From ca92b6788a68ec0fe991254274321312291db3f1 Mon Sep 17 00:00:00 2001 From: Yoshi Cheng-Hao Huang Date: Fri, 8 Sep 2023 17:10:50 +0000 Subject: [PATCH] Bug 1850755 - Part 1: Turn on well-formed-unicode-strings by default in Browser and JS Shell. r=spidermonkey-reviewers,jandem Well-Formed Unicode strings is in TC39 Stage 4 and has been merged into ECMA262 spec, https://github.com/tc39/ecma262/pull/3039 Differential Revision: https://phabricator.services.mozilla.com/D187182 --- js/public/RealmOptions.h | 18 +++++++++--------- js/src/builtin/String.cpp | 5 ----- js/src/shell/js.cpp | 16 ++++++++-------- js/src/tests/non262/String/wellFormed.js | 9 --------- js/xpconnect/src/XPCJSContext.cpp | 8 ++++---- modules/libpref/init/StaticPrefList.yaml | 12 ++++++------ 6 files changed, 27 insertions(+), 41 deletions(-) delete mode 100644 js/src/tests/non262/String/wellFormed.js diff --git a/js/public/RealmOptions.h b/js/public/RealmOptions.h index 1f9f765da8a33..41885165ddd49 100644 --- a/js/public/RealmOptions.h +++ b/js/public/RealmOptions.h @@ -204,13 +204,6 @@ class JS_PUBLIC_API RealmCreationOptions { return *this; } -#ifdef NIGHTLY_BUILD - bool getArrayGroupingEnabled() const { return arrayGrouping_; } - RealmCreationOptions& setArrayGroupingEnabled(bool flag) { - arrayGrouping_ = flag; - return *this; - } - bool getWellFormedUnicodeStringsEnabled() const { return wellFormedUnicodeStrings_; } @@ -219,6 +212,13 @@ class JS_PUBLIC_API RealmCreationOptions { return *this; } +#ifdef NIGHTLY_BUILD + bool getArrayGroupingEnabled() const { return arrayGrouping_; } + RealmCreationOptions& setArrayGroupingEnabled(bool flag) { + arrayGrouping_ = flag; + return *this; + } + bool getNewSetMethodsEnabled() const { return newSetMethods_; } RealmCreationOptions& setNewSetMethodsEnabled(bool flag) { newSetMethods_ = flag; @@ -292,10 +292,10 @@ class JS_PUBLIC_API RealmCreationOptions { bool propertyErrorMessageFix_ = false; bool iteratorHelpers_ = false; bool shadowRealms_ = false; + // Pref for String.prototype.{is,to}WellFormed() methods. + bool wellFormedUnicodeStrings_ = true; #ifdef NIGHTLY_BUILD bool arrayGrouping_ = false; - // Pref for String.prototype.{is,to}WellFormed() methods. - bool wellFormedUnicodeStrings_ = false; // Pref for new Set.prototype methods. bool newSetMethods_ = false; // Pref for ArrayBuffer.prototype.transfer{,ToFixedLength}() methods. diff --git a/js/src/builtin/String.cpp b/js/src/builtin/String.cpp index 923e8b835eb1d..a252905ec215c 100644 --- a/js/src/builtin/String.cpp +++ b/js/src/builtin/String.cpp @@ -1562,7 +1562,6 @@ static bool str_normalize(JSContext* cx, unsigned argc, Value* vp) { #endif // JS_HAS_INTL_API -#ifdef NIGHTLY_BUILD /** * IsStringWellFormedUnicode ( string ) * https://tc39.es/ecma262/#sec-isstringwellformedunicode @@ -1693,8 +1692,6 @@ static const JSFunctionSpec wellFormed_functions[] = { JS_FN("isWellFormed", str_isWellFormed, 0, 0), JS_FN("toWellFormed", str_toWellFormed, 0, 0), JS_FS_END}; -#endif // NIGHTLY_BUILD - static bool str_charAt(JSContext* cx, unsigned argc, Value* vp) { AutoJSMethodProfilerEntry pseudoFrame(cx, "String.prototype", "charAt"); CallArgs args = CallArgsFromVp(argc, vp); @@ -4040,13 +4037,11 @@ static bool StringClassFinish(JSContext* cx, HandleObject ctor, return false; } -#ifdef NIGHTLY_BUILD // Define isWellFormed/toWellFormed functions. if (cx->realm()->creationOptions().getWellFormedUnicodeStringsEnabled() && !JS_DefineFunctions(cx, nativeProto, wellFormed_functions)) { return false; } -#endif return true; } diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index dd1c6c60f6206..c8f3b3937cf0c 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -741,10 +741,10 @@ bool shell::enableToSource = false; bool shell::enablePropertyErrorMessageFix = false; bool shell::enableIteratorHelpers = false; bool shell::enableShadowRealms = false; +// Pref for String.prototype.{is,to}WellFormed() methods. +bool shell::enableWellFormedUnicodeStrings = true; #ifdef NIGHTLY_BUILD bool shell::enableArrayGrouping = false; -// Pref for String.prototype.{is,to}WellFormed() methods. -bool shell::enableWellFormedUnicodeStrings = false; // Pref for new Set.prototype methods. bool shell::enableNewSetMethods = false; // Pref for ArrayBuffer.prototype.transfer{,ToFixedLength}() methods. @@ -4135,9 +4135,9 @@ static void SetStandardRealmOptions(JS::RealmOptions& options) { .setPropertyErrorMessageFixEnabled(enablePropertyErrorMessageFix) .setIteratorHelpersEnabled(enableIteratorHelpers) .setShadowRealmsEnabled(enableShadowRealms) + .setWellFormedUnicodeStringsEnabled(enableWellFormedUnicodeStrings) #ifdef NIGHTLY_BUILD .setArrayGroupingEnabled(enableArrayGrouping) - .setWellFormedUnicodeStringsEnabled(enableWellFormedUnicodeStrings) .setNewSetMethodsEnabled(enableNewSetMethods) .setArrayBufferTransferEnabled(enableArrayBufferTransfer) #endif @@ -11640,9 +11640,9 @@ bool InitOptionParser(OptionParser& op) { !op.addBoolOption('\0', "enable-shadow-realms", "Enable ShadowRealms") || !op.addBoolOption('\0', "enable-array-grouping", "Enable Array.grouping") || - !op.addBoolOption('\0', "enable-well-formed-unicode-strings", - "Enable String.prototype.{is,to}WellFormed() methods" - "(Well-Formed Unicode Strings)") || + !op.addBoolOption('\0', "disable-well-formed-unicode-strings", + "Disable String.prototype.{is,to}WellFormed() methods" + "(Well-Formed Unicode Strings) (default: Enabled)") || !op.addBoolOption('\0', "enable-new-set-methods", "Enable New Set methods") || !op.addBoolOption('\0', "enable-arraybuffer-transfer", @@ -12152,10 +12152,10 @@ bool SetContextOptions(JSContext* cx, const OptionParser& op) { !op.getBoolOption("disable-property-error-message-fix"); enableIteratorHelpers = op.getBoolOption("enable-iterator-helpers"); enableShadowRealms = op.getBoolOption("enable-shadow-realms"); + enableWellFormedUnicodeStrings = + !op.getBoolOption("disable-well-formed-unicode-strings"); #ifdef NIGHTLY_BUILD enableArrayGrouping = op.getBoolOption("enable-array-grouping"); - enableWellFormedUnicodeStrings = - op.getBoolOption("enable-well-formed-unicode-strings"); enableNewSetMethods = op.getBoolOption("enable-new-set-methods"); enableArrayBufferTransfer = op.getBoolOption("enable-arraybuffer-transfer"); #endif diff --git a/js/src/tests/non262/String/wellFormed.js b/js/src/tests/non262/String/wellFormed.js deleted file mode 100644 index babf0825be7ed..0000000000000 --- a/js/src/tests/non262/String/wellFormed.js +++ /dev/null @@ -1,9 +0,0 @@ -// Calling String.prototype.isWellFormed() or toWellFormed() should throw a -// TypeError when the pref "enable-well-formed-unicode-strings" is off. -// -// This test should be removed once the pref is turned on by default. -assertThrowsInstanceOf(() => "abc".isWellFormed(), TypeError) -assertThrowsInstanceOf(() => "abc".toWellFormed(), TypeError) - -if (typeof reportCompare === "function") - reportCompare(0, 0); diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 35c8f39f84eb8..b6ecd08aeec4c 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -777,9 +777,9 @@ static mozilla::Atomic sWeakRefsEnabled(false); static mozilla::Atomic sWeakRefsExposeCleanupSome(false); static mozilla::Atomic sIteratorHelpersEnabled(false); static mozilla::Atomic sShadowRealmsEnabled(false); +static mozilla::Atomic sWellFormedUnicodeStringsEnabled(true); #ifdef NIGHTLY_BUILD static mozilla::Atomic sArrayGroupingEnabled(false); -static mozilla::Atomic sWellFormedUnicodeStringsEnabled(false); static mozilla::Atomic sNewSetMethodsEnabled(false); static mozilla::Atomic sArrayBufferTransferEnabled(false); #endif @@ -806,9 +806,9 @@ void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) { .setWeakRefsEnabled(GetWeakRefsEnabled()) .setIteratorHelpersEnabled(sIteratorHelpersEnabled) .setShadowRealmsEnabled(sShadowRealmsEnabled) + .setWellFormedUnicodeStringsEnabled(sWellFormedUnicodeStringsEnabled) #ifdef NIGHTLY_BUILD .setArrayGroupingEnabled(sArrayGroupingEnabled) - .setWellFormedUnicodeStringsEnabled(sWellFormedUnicodeStringsEnabled) .setNewSetMethodsEnabled(sNewSetMethodsEnabled) .setArrayBufferTransferEnabled(sArrayBufferTransferEnabled) #endif @@ -1007,13 +1007,13 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) { JS_OPTIONS_DOT_STR "experimental.weakrefs.expose_cleanupSome"); sShadowRealmsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.shadow_realms"); + sWellFormedUnicodeStringsEnabled = + Preferences::GetBool(JS_OPTIONS_DOT_STR "well_formed_unicode_strings"); #ifdef NIGHTLY_BUILD sIteratorHelpersEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.iterator_helpers"); sArrayGroupingEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.array_grouping"); - sWellFormedUnicodeStringsEnabled = Preferences::GetBool( - JS_OPTIONS_DOT_STR "experimental.well_formed_unicode_strings"); sNewSetMethodsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.new_set_methods"); sArrayBufferTransferEnabled = Preferences::GetBool( diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 95f4f674e35e3..e50c4096947f0 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -7456,6 +7456,12 @@ value: false mirror: always +# Support for String.prototype.{is,to}WellFormed in JavaScript. +- name: javascript.options.well_formed_unicode_strings + type: bool + value: true + mirror: always + #ifdef NIGHTLY_BUILD # Experimental support for Iterator Helpers in JavaScript. - name: javascript.options.experimental.iterator_helpers @@ -7469,12 +7475,6 @@ value: false mirror: always - # Experimental support for String.prototype.{is,to}WellFormed in JavaScript. -- name: javascript.options.experimental.well_formed_unicode_strings - type: bool - value: false - mirror: always - # Experimental support for New Set methods - name: javascript.options.experimental.new_set_methods type: bool