Bug 1259822 - Part 1: Add pref to enable fix for accessing property of null or undefined. r=jorendorff
authorTooru Fujisawa <arai_a@mac.com>
Sat, 11 Jan 2020 05:08:33 +0000
changeset 509854 03939cd2d0ab6cba212721a285b59034050e29a2
parent 509852 32d6e8a34f39f8f00e2eae7fd1b01186f80e182c
child 509855 e8d220dbe0299d90441b3dce6587a5b174f24644
push id37005
push usernerli@mozilla.com
push dateSat, 11 Jan 2020 21:51:30 +0000
treeherdermozilla-central@408f6c0f9814 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1259822
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1259822 - Part 1: Add pref to enable fix for accessing property of null or undefined. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D58103
js/public/RealmOptions.h
js/src/shell/js.cpp
js/src/shell/jsshell.h
js/xpconnect/src/XPCJSContext.cpp
modules/libpref/init/StaticPrefList.yaml
--- a/js/public/RealmOptions.h
+++ b/js/public/RealmOptions.h
@@ -186,16 +186,24 @@ class JS_PUBLIC_API RealmCreationOptions
   }
 
   bool getToSourceEnabled() const { return toSource_; }
   RealmCreationOptions& setToSourceEnabled(bool flag) {
     toSource_ = flag;
     return *this;
   }
 
+  bool getPropertyErrorMessageFixEnabled() const {
+    return propertyErrorMessageFix_;
+  }
+  RealmCreationOptions& setPropertyErrorMessageFixEnabled(bool flag) {
+    propertyErrorMessageFix_ = flag;
+    return *this;
+  }
+
   // This flag doesn't affect JS engine behavior.  It is used by Gecko to
   // mark whether content windows and workers are "Secure Context"s. See
   // https://w3c.github.io/webappsec-secure-contexts/
   // https://bugzilla.mozilla.org/show_bug.cgi?id=1162772#c34
   bool secureContext() const { return secureContext_; }
   RealmCreationOptions& setSecureContext(bool flag) {
     secureContext_ = flag;
     return *this;
@@ -225,16 +233,17 @@ class JS_PUBLIC_API RealmCreationOptions
   bool readableByteStreams_ = false;
   bool byobStreamReaders_ = false;
   bool writableStreams_ = false;
   bool readableStreamPipeTo_ = false;
   bool fields_ = false;
   bool awaitFix_ = false;
   bool weakRefs_ = false;
   bool toSource_ = false;
+  bool propertyErrorMessageFix_ = false;
   bool secureContext_ = false;
 };
 
 /**
  * RealmBehaviors specifies behaviors of a realm that can be changed after the
  * realm's been created.
  */
 class JS_PUBLIC_API RealmBehaviors {
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -495,16 +495,17 @@ bool shell::enableStreams = false;
 bool shell::enableReadableByteStreams = false;
 bool shell::enableBYOBStreamReaders = false;
 bool shell::enableWritableStreams = false;
 bool shell::enableReadableStreamPipeTo = false;
 bool shell::enableFields = false;
 bool shell::enableAwaitFix = false;
 bool shell::enableWeakRefs = false;
 bool shell::enableToSource = false;
+bool shell::enablePropertyErrorMessageFix = false;
 #ifdef JS_GC_ZEAL
 uint32_t shell::gZealBits = 0;
 uint32_t shell::gZealFrequency = 0;
 #endif
 bool shell::printTiming = false;
 RCFile* shell::gErrFile = nullptr;
 RCFile* shell::gOutFile = nullptr;
 bool shell::reportWarnings = true;
@@ -3710,17 +3711,18 @@ static void SetStandardRealmOptions(JS::
       .setStreamsEnabled(enableStreams)
       .setReadableByteStreamsEnabled(enableReadableByteStreams)
       .setBYOBStreamReadersEnabled(enableBYOBStreamReaders)
       .setWritableStreamsEnabled(enableWritableStreams)
       .setReadableStreamPipeToEnabled(enableReadableStreamPipeTo)
       .setFieldsEnabled(enableFields)
       .setAwaitFixEnabled(enableAwaitFix)
       .setWeakRefsEnabled(enableWeakRefs)
-      .setToSourceEnabled(enableToSource);
+      .setToSourceEnabled(enableToSource)
+      .setPropertyErrorMessageFixEnabled(enablePropertyErrorMessageFix);
   options.behaviors().setDeferredParserAlloc(enableDeferredMode);
 }
 
 static MOZ_MUST_USE bool CheckRealmOptions(JSContext* cx,
                                            JS::RealmOptions& options,
                                            JSPrincipals* principals) {
   JS::RealmCreationOptions& creationOptions = options.creationOptions();
   if (creationOptions.compartmentSpecifier() !=
@@ -10383,16 +10385,18 @@ static bool SetContextOptions(JSContext*
   enableReadableStreamPipeTo = op.getBoolOption("enable-readablestream-pipeto");
 #ifdef ENABLE_WASM_BIGINT
   enableWasmBigInt = op.getBoolOption("wasm-bigint");
 #endif
   enableFields = !op.getBoolOption("disable-experimental-fields");
   enableAwaitFix = op.getBoolOption("enable-experimental-await-fix");
   enableWeakRefs = op.getBoolOption("enable-weak-refs");
   enableToSource = !op.getBoolOption("disable-tosource");
+  enablePropertyErrorMessageFix =
+      !op.getBoolOption("disable-property-error-message-fix");
 
   JS::ContextOptionsRef(cx)
       .setAsmJS(enableAsmJS)
       .setWasm(enableWasm)
       .setWasmForTrustedPrinciples(enableWasm)
       .setWasmBaseline(enableWasmBaseline)
       .setWasmIon(enableWasmIon)
 #ifdef ENABLE_WASM_CRANELIFT
@@ -11182,16 +11186,19 @@ int main(int argc, char** argv, char** e
                         "Enable support for "
                         "WHATWG ReadableStream.prototype.pipeTo") ||
       !op.addBoolOption('\0', "disable-experimental-fields",
                         "Disable public fields in classes") ||
       !op.addBoolOption('\0', "enable-experimental-await-fix",
                         "Enable new, faster await semantics") ||
       !op.addBoolOption('\0', "enable-weak-refs", "Enable weak references") ||
       !op.addBoolOption('\0', "disable-tosource", "Disable toSource/uneval") ||
+      !op.addBoolOption('\0', "disable-property-error-message-fix",
+                        "Disable fix for the error message when accessing "
+                        "property of null or undefined") ||
       !op.addStringOption('\0', "shared-memory", "on/off",
                           "SharedArrayBuffer and Atomics "
 #if SHARED_MEMORY_DEFAULT
                           "(default: on, off to disable)"
 #else
                           "(default: off, on to enable)"
 #endif
                           ) ||
--- a/js/src/shell/jsshell.h
+++ b/js/src/shell/jsshell.h
@@ -120,16 +120,17 @@ extern bool enableStreams;
 extern bool enableReadableByteStreams;
 extern bool enableBYOBStreamReaders;
 extern bool enableWritableStreams;
 extern bool enableReadableStreamPipeTo;
 extern bool enableFields;
 extern bool enableAwaitFix;
 extern bool enableWeakRefs;
 extern bool enableToSource;
+extern bool enablePropertyErrorMessageFix;
 #ifdef JS_GC_ZEAL
 extern uint32_t gZealBits;
 extern uint32_t gZealFrequency;
 #endif
 extern bool printTiming;
 extern RCFile* gErrFile;
 extern RCFile* gOutFile;
 extern bool reportWarnings;
--- a/js/xpconnect/src/XPCJSContext.cpp
+++ b/js/xpconnect/src/XPCJSContext.cpp
@@ -755,28 +755,30 @@ bool xpc::ExtraWarningsForSystemJS() { r
 bool xpc::ExtraWarningsForSystemJS() { return false; }
 #endif
 
 static mozilla::Atomic<bool> sSharedMemoryEnabled(false);
 static mozilla::Atomic<bool> sStreamsEnabled(false);
 static mozilla::Atomic<bool> sFieldsEnabled(false);
 static mozilla::Atomic<bool> sParserDeferAllocationEnabled(false);
 static mozilla::Atomic<bool> sAwaitFixEnabled(false);
+static mozilla::Atomic<bool> sPropertyErrorMessageFixEnabled(false);
 
 void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
   options.creationOptions()
       .setSharedMemoryAndAtomicsEnabled(sSharedMemoryEnabled)
       .setCoopAndCoepEnabled(
           StaticPrefs::browser_tabs_remote_useCrossOriginOpenerPolicy() &&
           StaticPrefs::browser_tabs_remote_useCrossOriginEmbedderPolicy())
       .setStreamsEnabled(sStreamsEnabled)
       .setWritableStreamsEnabled(
           StaticPrefs::javascript_options_writable_streams())
       .setFieldsEnabled(sFieldsEnabled)
-      .setAwaitFixEnabled(sAwaitFixEnabled);
+      .setAwaitFixEnabled(sAwaitFixEnabled)
+      .setPropertyErrorMessageFixEnabled(sPropertyErrorMessageFixEnabled);
   options.behaviors().setDeferredParserAlloc(sParserDeferAllocationEnabled);
 }
 
 static void LoadStartupJSPrefs(XPCJSContext* xpccx) {
   // Prefs that require a restart are handled here. This includes the
   // process-wide JIT options because toggling these at runtime can easily cause
   // races or get us into an inconsistent state.
   //
@@ -934,16 +936,18 @@ static void ReloadPrefsCallback(const ch
       Preferences::GetBool(JS_OPTIONS_DOT_STR "shared_memory");
   sStreamsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "streams");
   sParserDeferAllocationEnabled =
       Preferences::GetBool(JS_OPTIONS_DOT_STR "parser_defer_allocation");
   sFieldsEnabled =
       Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.fields");
   sAwaitFixEnabled =
       Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.await_fix");
+  sPropertyErrorMessageFixEnabled =
+      Preferences::GetBool(JS_OPTIONS_DOT_STR "property_error_message_fix");
 
 #ifdef DEBUG
   sExtraWarningsForSystemJS =
       Preferences::GetBool(JS_OPTIONS_DOT_STR "strict.debug");
 #endif
 
 #ifdef JS_GC_ZEAL
   int32_t zeal = Preferences::GetInt(JS_OPTIONS_DOT_STR "gczeal", -1);
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -4178,16 +4178,22 @@
   value: true
   mirror: always
 
 - name: javascript.options.experimental.await_fix
   type: RelaxedAtomicBool
   value: true
   mirror: always
 
+# Use better error message when accessing property of null or undefined.
+- name: javascript.options.property_error_message_fix
+  type: RelaxedAtomicBool
+  value: @IS_NOT_RELEASE_OR_BETA@
+  mirror: always
+
 # The amount of time we wait between a request to GC (due to leaving a page) and doing the actual GC, in ms.
 - name: javascript.options.gc_delay
   type: uint32_t
   value: 4000
   mirror: always
 
 # The amount of time we wait from the first request to GC to actually doing the first GC, in ms.
 - name: javascript.options.gc_delay.first