Bug 1635839 - Part 4: Add an option for private class fields, disabled by default r=jorendorff
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 02 Jun 2020 20:58:04 +0000
changeset 533616 851ee4729a31745d4845a584750f8858fcc0a455
parent 533615 2b34ab462221a4721c8ae08cc24e2b019c61a74a
child 533617 480ec262bae2ad526cd41b46d149182f9f2f4be6
push id37474
push userabutkovits@mozilla.com
push dateWed, 03 Jun 2020 09:29:05 +0000
treeherdermozilla-central@bf162b065e1f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1635839
milestone79.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 1635839 - Part 4: Add an option for private class fields, disabled by default r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D74105
js/public/CompileOptions.h
js/public/RealmOptions.h
js/src/jsapi.cpp
js/src/shell/js.cpp
js/src/shell/jsshell.h
--- a/js/public/CompileOptions.h
+++ b/js/public/CompileOptions.h
@@ -125,16 +125,17 @@ class JS_PUBLIC_API TransitiveCompileOpt
   AsmJSOption asmJSOption = AsmJSOption::Disabled;
   bool throwOnAsmJSValidationFailureOption = false;
   bool forceAsync = false;
   bool discardSource = false;
   bool sourceIsLazy = false;
   bool allowHTMLComments = true;
   bool hideScriptFromDebugger = false;
   bool nonSyntacticScope = false;
+  bool privateClassFields = false;
 
   /**
    * |introductionType| is a statically allocated C string: one of "eval",
    * "Function", or "GeneratorFunction".
    */
   const char* introductionType = nullptr;
 
   unsigned introductionLineno = 0;
--- a/js/public/RealmOptions.h
+++ b/js/public/RealmOptions.h
@@ -229,16 +229,22 @@ class JS_PUBLIC_API RealmCreationOptions
   }
 
   bool getIteratorHelpersEnabled() const { return iteratorHelpers_; }
   RealmCreationOptions& setIteratorHelpersEnabled(bool flag) {
     iteratorHelpers_ = flag;
     return *this;
   }
 
+  bool getPrivateClassFieldsEnabled() const { return privateClassFields_; }
+  RealmCreationOptions& setPrivateClassFieldsEnabled(bool flag) {
+    privateClassFields_ = 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;
@@ -269,16 +275,17 @@ class JS_PUBLIC_API RealmCreationOptions
   bool readableByteStreams_ = false;
   bool byobStreamReaders_ = false;
   bool writableStreams_ = false;
   bool readableStreamPipeTo_ = false;
   bool weakRefs_ = false;
   bool toSource_ = false;
   bool propertyErrorMessageFix_ = false;
   bool iteratorHelpers_ = false;
+  bool privateClassFields_ = 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/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3468,16 +3468,17 @@ void JS::TransitiveCompileOptions::copyP
   discardSource = rhs.discardSource;
   sourceIsLazy = rhs.sourceIsLazy;
   introductionType = rhs.introductionType;
   introductionLineno = rhs.introductionLineno;
   introductionOffset = rhs.introductionOffset;
   hasIntroductionInfo = rhs.hasIntroductionInfo;
   hideScriptFromDebugger = rhs.hideScriptFromDebugger;
   nonSyntacticScope = rhs.nonSyntacticScope;
+  privateClassFields = rhs.privateClassFields;
 };
 
 void JS::ReadOnlyCompileOptions::copyPODNonTransitiveOptions(
     const ReadOnlyCompileOptions& rhs) {
   lineno = rhs.lineno;
   column = rhs.column;
   scriptSourceOffset = rhs.scriptSourceOffset;
   isRunOnce = rhs.isRunOnce;
@@ -3559,16 +3560,18 @@ JS::CompileOptions::CompileOptions(JSCon
     asmJSOption = AsmJSOption::Disabled;
   } else if (cx->realm()->debuggerObservesAsmJS()) {
     asmJSOption = AsmJSOption::DisabledByDebugger;
   } else {
     asmJSOption = AsmJSOption::Enabled;
   }
   throwOnAsmJSValidationFailureOption =
       cx->options().throwOnAsmJSValidationFailure();
+  privateClassFields =
+      cx->realm()->creationOptions().getPrivateClassFieldsEnabled();
 
   sourcePragmas_ = cx->options().sourcePragmas();
 
   // Certain modes of operation force strict-mode in general.
   forceStrictMode_ = cx->options().strictMode();
 
   // Certain modes of operation disallow syntax parsing in general.
   forceFullParse_ = cx->realm()->behaviors().disableLazyParsing() ||
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -508,16 +508,17 @@ bool shell::enableStreams = false;
 bool shell::enableReadableByteStreams = false;
 bool shell::enableBYOBStreamReaders = false;
 bool shell::enableWritableStreams = false;
 bool shell::enableReadableStreamPipeTo = false;
 bool shell::enableWeakRefs = false;
 bool shell::enableToSource = false;
 bool shell::enablePropertyErrorMessageFix = false;
 bool shell::enableIteratorHelpers = false;
+bool shell::enablePrivateClassFields = 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;
@@ -3888,17 +3889,18 @@ static void SetStandardRealmOptions(JS::
       .setStreamsEnabled(enableStreams)
       .setReadableByteStreamsEnabled(enableReadableByteStreams)
       .setBYOBStreamReadersEnabled(enableBYOBStreamReaders)
       .setWritableStreamsEnabled(enableWritableStreams)
       .setReadableStreamPipeToEnabled(enableReadableStreamPipeTo)
       .setWeakRefsEnabled(enableWeakRefs)
       .setToSourceEnabled(enableToSource)
       .setPropertyErrorMessageFixEnabled(enablePropertyErrorMessageFix)
-      .setIteratorHelpersEnabled(enableIteratorHelpers);
+      .setIteratorHelpersEnabled(enableIteratorHelpers)
+      .setPrivateClassFieldsEnabled(enablePrivateClassFields);
 }
 
 static MOZ_MUST_USE bool CheckRealmOptions(JSContext* cx,
                                            JS::RealmOptions& options,
                                            JSPrincipals* principals) {
   JS::RealmCreationOptions& creationOptions = options.creationOptions();
   if (creationOptions.compartmentSpecifier() !=
       JS::CompartmentSpecifier::ExistingCompartment) {
@@ -10256,16 +10258,17 @@ static bool SetContextOptions(JSContext*
   enableBYOBStreamReaders = op.getBoolOption("enable-byob-stream-readers");
   enableWritableStreams = op.getBoolOption("enable-writable-streams");
   enableReadableStreamPipeTo = op.getBoolOption("enable-readablestream-pipeto");
   enableWeakRefs = op.getBoolOption("enable-weak-refs");
   enableToSource = !op.getBoolOption("disable-tosource");
   enablePropertyErrorMessageFix =
       !op.getBoolOption("disable-property-error-message-fix");
   enableIteratorHelpers = op.getBoolOption("enable-iterator-helpers");
+  enablePrivateClassFields = op.getBoolOption("enable-private-fields");
 
   JS::ContextOptionsRef(cx)
       .setAsmJS(enableAsmJS)
       .setWasm(enableWasm)
       .setWasmForTrustedPrinciples(enableWasm)
       .setWasmBaseline(enableWasmBaseline)
       .setWasmIon(enableWasmIon)
       .setWasmReftypes(enableWasmReftypes)
@@ -11129,16 +11132,18 @@ int main(int argc, char** argv, char** e
                         "WHATWG ReadableStream.prototype.pipeTo") ||
       !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.addBoolOption('\0', "enable-iterator-helpers",
                         "Enable iterator helpers") ||
+      !op.addBoolOption('\0', "enable-private-fields",
+                        "Enable private class fields") ||
       !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
@@ -134,16 +134,17 @@ extern bool enableStreams;
 extern bool enableReadableByteStreams;
 extern bool enableBYOBStreamReaders;
 extern bool enableWritableStreams;
 extern bool enableReadableStreamPipeTo;
 extern bool enableWeakRefs;
 extern bool enableToSource;
 extern bool enablePropertyErrorMessageFix;
 extern bool enableIteratorHelpers;
+extern bool enablePrivateClassFields;
 #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;