diff --git a/js/src/js.msg b/js/src/js.msg index d8b89879c90f..cb73d2b69596 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -232,6 +232,7 @@ MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 0, JSEXN_SYNTAXERR, "missing } in compoun MSG_DEF(JSMSG_DECLARATION_AFTER_EXPORT,0, JSEXN_SYNTAXERR, "missing declaration after 'export' keyword") MSG_DEF(JSMSG_DECLARATION_AFTER_IMPORT,0, JSEXN_SYNTAXERR, "missing declaration after 'import' keyword") MSG_DEF(JSMSG_DEPRECATED_DELETE_OPERAND, 0, JSEXN_SYNTAXERR, "applying the 'delete' operator to an unqualified name is deprecated") +MSG_DEF(JSMSG_DEPRECATED_FLAGS_ARG, 0, JSEXN_NONE, "flags argument of String.prototype.{search,match,replace} is deprecated") MSG_DEF(JSMSG_DEPRECATED_LET_BLOCK, 0, JSEXN_NONE, "JavaScript 1.7's let blocks are deprecated") MSG_DEF(JSMSG_DEPRECATED_FOR_EACH, 0, JSEXN_NONE, "JavaScript 1.6's for-each-in loops are deprecated; consider using ES6 for-of instead") MSG_DEF(JSMSG_DEPRECATED_LET_EXPRESSION, 0, JSEXN_NONE, "JavaScript 1.7's let expressions are deprecated") diff --git a/js/src/jscompartment.cpp b/js/src/jscompartment.cpp index cb9e3bf7a87d..1b9f3e75f457 100644 --- a/js/src/jscompartment.cpp +++ b/js/src/jscompartment.cpp @@ -46,6 +46,7 @@ JSCompartment::JSCompartment(Zone *zone, const JS::CompartmentOptions &options = isSelfHosting(false), marked(true), warnedAboutNoSuchMethod(false), + warnedAboutFlagsArgument(false), addonId(options.addonIdOrNull()), #ifdef DEBUG firedOnNewGlobalObject(false), diff --git a/js/src/jscompartment.h b/js/src/jscompartment.h index 5d54486eb19b..27f9a3170136 100644 --- a/js/src/jscompartment.h +++ b/js/src/jscompartment.h @@ -149,6 +149,7 @@ struct JSCompartment bool isSelfHosting; bool marked; bool warnedAboutNoSuchMethod; + bool warnedAboutFlagsArgument; // A null add-on ID means that the compartment is not associated with an // add-on. diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 3b105088b62a..05af5d54298e 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -2137,6 +2137,13 @@ class MOZ_STACK_CLASS StringRegExpGuard cx->compartment()->addTelemetry(filename, JSCompartment::DeprecatedFlagsArgument); } + if (!cx->compartment()->warnedAboutFlagsArgument) { + if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, GetErrorMessage, nullptr, + JSMSG_DEPRECATED_FLAGS_ARG)) + return false; + cx->compartment()->warnedAboutFlagsArgument = true; + } + opt = ToString(cx, args[optarg]); if (!opt) return false; diff --git a/js/src/tests/js1_5/String/replace-flags.js b/js/src/tests/js1_5/String/replace-flags.js new file mode 100644 index 000000000000..656d4acfa6f6 --- /dev/null +++ b/js/src/tests/js1_5/String/replace-flags.js @@ -0,0 +1,15 @@ +// |reftest| skip-if(!xulRuntime.shell) + +var BUGNUMBER = 1142351; +var summary = 'Add console warnings for non-standard flag argument of String.prototype.{search,match,replace}.'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +options("werror"); +assertEq(evaluate("'aaaA'.match('a', 'i')", {catchTermination: true}), "terminated"); +assertEq(evaluate("'aaaA'.search('a', 'i')", {catchTermination: true}), "terminated"); +assertEq(evaluate("'aaaA'.replace('a', 'b', 'g')", {catchTermination: true}), "terminated"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/vm/Xdr.h b/js/src/vm/Xdr.h index bcdbdc0f9c32..fa9e92ed8e23 100644 --- a/js/src/vm/Xdr.h +++ b/js/src/vm/Xdr.h @@ -29,11 +29,11 @@ namespace js { * * https://developer.mozilla.org/en-US/docs/SpiderMonkey/Internals/Bytecode */ -static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 267; +static const uint32_t XDR_BYTECODE_VERSION_SUBTRAHEND = 268; static const uint32_t XDR_BYTECODE_VERSION = uint32_t(0xb973c0de - XDR_BYTECODE_VERSION_SUBTRAHEND); -static_assert(JSErr_Limit == 388, +static_assert(JSErr_Limit == 389, "GREETINGS, POTENTIAL SUBTRAHEND INCREMENTER! If you added or " "removed MSG_DEFs from js.msg, you should increment " "XDR_BYTECODE_VERSION_SUBTRAHEND and update this assertion's "