Bug 1498320 - Remove BytecodeCompiler::enclosingScope and just make users provide it themselves when they need it. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Thu, 01 Nov 2018 17:34:54 -0700
changeset 445954 17243a560006c6db1f9e4cc0fea57a8ae29b1dbc
parent 445953 0db3c534950cc51af7e106971113ff718170d352
child 445955 c7705516c1e3c820660296a965b267e7fc4d575f
child 445982 f6df375b86987b2772067a61873ebfe3a98c353a
push id109805
push userjwalden@mit.edu
push dateTue, 13 Nov 2018 01:51:46 +0000
treeherdermozilla-inbound@17243a560006 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1498320
milestone65.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 1498320 - Remove BytecodeCompiler::enclosingScope and just make users provide it themselves when they need it. r=tcampbell
js/src/frontend/BytecodeCompiler.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -44,35 +44,32 @@ class MOZ_STACK_CLASS BytecodeCompiler
 {
   protected:
     AutoKeepAtoms keepAtoms;
 
     JSContext* cx;
     const ReadOnlyCompileOptions& options;
     SourceBufferHolder& sourceBuffer;
 
-    RootedScope enclosingScope;
-
     RootedScriptSourceObject sourceObject;
     ScriptSource* scriptSource;
 
     Maybe<UsedNameTracker> usedNames;
     Maybe<Parser<SyntaxParseHandler, char16_t>> syntaxParser;
     Maybe<Parser<FullParseHandler, char16_t>> parser;
 
     Directives directives;
 
     RootedScript script;
 
   public:
     // Construct an object passing mandatory arguments.
     BytecodeCompiler(JSContext* cx,
                      const ReadOnlyCompileOptions& options,
-                     SourceBufferHolder& sourceBuffer,
-                     HandleScope enclosingScope);
+                     SourceBufferHolder& sourceBuffer);
 
     ScriptSourceObject* sourceObjectPtr() const {
         return sourceObject.get();
     }
 
     // Call this before calling compile{Global,Eval}Script.
     MOZ_MUST_USE bool prepareScriptParse() {
         return createSourceAndParser(ParseGoal::Script) && createCompleteScript();
@@ -81,27 +78,28 @@ class MOZ_STACK_CLASS BytecodeCompiler
     JSScript* compileGlobalScript(ScopeKind scopeKind);
     JSScript* compileEvalScript(HandleObject environment, HandleScope enclosingScope);
 
     // Call this before calling compileModule.
     MOZ_MUST_USE bool prepareModuleParse() {
         return createSourceAndParser(ParseGoal::Module) && createCompleteScript();
     }
 
-    ModuleObject* compileModule();
+    ModuleObject* compileModule(HandleScope enclosingScope);
 
     // Call this before calling parseStandaloneFunction.
     MOZ_MUST_USE bool prepareStandaloneFunctionParse(const Maybe<uint32_t>& parameterListEnd) {
         return createSourceAndParser(ParseGoal::Script, parameterListEnd);
     }
 
     // Call this before calling compileStandaloneFunction.
     CodeNode* parseStandaloneFunction(MutableHandleFunction fun, GeneratorKind generatorKind,
                                       FunctionAsyncKind asyncKind,
-                                      const Maybe<uint32_t>& parameterListEnd);
+                                      const Maybe<uint32_t>& parameterListEnd,
+                                      HandleScope enclosingScope);
 
     bool compileStandaloneFunction(CodeNode* parsedFunction, MutableHandleFunction fun);
 
   private:
     void assertSourceAndParserCreated() const {
         MOZ_ASSERT(sourceObject != nullptr);
         MOZ_ASSERT(scriptSource != nullptr);
         MOZ_ASSERT(usedNames.isSome());
@@ -186,23 +184,21 @@ AutoFrontendTraceLog::AutoFrontendTraceL
     typeLog_.emplace(logger_, id);
 }
 #else
 { }
 #endif
 
 BytecodeCompiler::BytecodeCompiler(JSContext* cx,
                                    const ReadOnlyCompileOptions& options,
-                                   SourceBufferHolder& sourceBuffer,
-                                   HandleScope enclosingScope)
+                                   SourceBufferHolder& sourceBuffer)
   : keepAtoms(cx),
     cx(cx),
     options(options),
     sourceBuffer(sourceBuffer),
-    enclosingScope(cx, enclosingScope),
     sourceObject(cx),
     scriptSource(nullptr),
     directives(options.strictOption),
     script(cx)
 {
     MOZ_ASSERT(sourceBuffer.get());
 }
 
@@ -446,17 +442,17 @@ BytecodeCompiler::compileEvalScript(Hand
     if (!prepareScriptParse()) {
         return nullptr;
     }
 
     return compileScript(environment, &evalsc);
 }
 
 ModuleObject*
-BytecodeCompiler::compileModule()
+BytecodeCompiler::compileModule(HandleScope enclosingScope)
 {
     assertSourceParserAndScriptCreated();
 
     Rooted<ModuleObject*> module(cx, ModuleObject::create(cx));
     if (!module) {
         return nullptr;
     }
 
@@ -500,17 +496,18 @@ BytecodeCompiler::compileModule()
 
 // Parse a standalone JS function, which might appear as the value of an
 // event handler attribute in an HTML <INPUT> tag, or in a Function()
 // constructor.
 CodeNode*
 BytecodeCompiler::parseStandaloneFunction(MutableHandleFunction fun,
                                           GeneratorKind generatorKind,
                                           FunctionAsyncKind asyncKind,
-                                          const Maybe<uint32_t>& parameterListEnd)
+                                          const Maybe<uint32_t>& parameterListEnd,
+                                          HandleScope enclosingScope)
 {
     MOZ_ASSERT(fun);
     MOZ_ASSERT(fun->isTenured());
 
     assertSourceAndParserCreated();
 
     TokenStreamPosition startPosition(keepAtoms, parser->tokenStream);
 
@@ -671,17 +668,17 @@ class MOZ_RAII AutoAssertReportedExcepti
 JSScript*
 frontend::CompileGlobalScript(JSContext* cx, ScopeKind scopeKind,
                               const ReadOnlyCompileOptions& options,
                               SourceBufferHolder& srcBuf,
                               ScriptSourceObject** sourceObjectOut)
 {
     MOZ_ASSERT(scopeKind == ScopeKind::Global || scopeKind == ScopeKind::NonSyntactic);
     AutoAssertReportedException assertException(cx);
-    BytecodeCompiler compiler(cx, options, srcBuf, /* enclosingScope = */ nullptr);
+    BytecodeCompiler compiler(cx, options, srcBuf);
     AutoInitializeSourceObject autoSSO(compiler, sourceObjectOut);
     JSScript* script = compiler.compileGlobalScript(scopeKind);
     if (!script) {
         return nullptr;
     }
     assertException.reset();
     return script;
 }
@@ -752,17 +749,17 @@ frontend::CompileGlobalBinASTScript(JSCo
 JSScript*
 frontend::CompileEvalScript(JSContext* cx, HandleObject environment,
                             HandleScope enclosingScope,
                             const ReadOnlyCompileOptions& options,
                             SourceBufferHolder& srcBuf,
                             ScriptSourceObject** sourceObjectOut)
 {
     AutoAssertReportedException assertException(cx);
-    BytecodeCompiler compiler(cx, options, srcBuf, enclosingScope);
+    BytecodeCompiler compiler(cx, options, srcBuf);
     AutoInitializeSourceObject autoSSO(compiler, sourceObjectOut);
     JSScript* script = compiler.compileEvalScript(environment, enclosingScope);
     if (!script) {
         return nullptr;
     }
     assertException.reset();
     return script;
 
@@ -778,25 +775,25 @@ frontend::CompileModule(JSContext* cx, c
 
     AutoAssertReportedException assertException(cx);
 
     CompileOptions options(cx, optionsInput);
     options.maybeMakeStrictMode(true); // ES6 10.2.1 Module code is always strict mode code.
     options.setIsRunOnce(true);
     options.allowHTMLComments = false;
 
-    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
-    BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
+    BytecodeCompiler compiler(cx, options, srcBuf);
     AutoInitializeSourceObject autoSSO(compiler, sourceObjectOut);
 
     if (!compiler.prepareModuleParse()) {
         return nullptr;
     }
 
-    ModuleObject* module = compiler.compileModule();
+    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
+    ModuleObject* module = compiler.compileModule(emptyGlobalScope);
     if (!module) {
         return nullptr;
     }
 
     assertException.reset();
     return module;
 }
 
@@ -1031,106 +1028,106 @@ bool
 frontend::CompileStandaloneFunction(JSContext* cx, MutableHandleFunction fun,
                                     const JS::ReadOnlyCompileOptions& options,
                                     JS::SourceBufferHolder& srcBuf,
                                     const Maybe<uint32_t>& parameterListEnd,
                                     HandleScope enclosingScope /* = nullptr */)
 {
     AutoAssertReportedException assertException(cx);
 
+    BytecodeCompiler compiler(cx, options, srcBuf);
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
+        return false;
+    }
+
     RootedScope scope(cx, enclosingScope);
     if (!scope) {
         scope = &cx->global()->emptyGlobalScope();
     }
 
-    BytecodeCompiler compiler(cx, options, srcBuf, scope);
-    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
-        return false;
-    }
-
     CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::NotGenerator,
                                                                 FunctionAsyncKind::SyncFunction,
-                                                                parameterListEnd);
+                                                                parameterListEnd, scope);
     if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }
 
 bool
 frontend::CompileStandaloneGenerator(JSContext* cx, MutableHandleFunction fun,
                                      const JS::ReadOnlyCompileOptions& options,
                                      JS::SourceBufferHolder& srcBuf,
                                      const Maybe<uint32_t>& parameterListEnd)
 {
     AutoAssertReportedException assertException(cx);
 
-    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
-
-    BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
+    BytecodeCompiler compiler(cx, options, srcBuf);
     if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
         return false;
     }
 
+    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
     CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::Generator,
                                                                 FunctionAsyncKind::SyncFunction,
-                                                                parameterListEnd);
+                                                                parameterListEnd,
+                                                                emptyGlobalScope);
     if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }
 
 bool
 frontend::CompileStandaloneAsyncFunction(JSContext* cx, MutableHandleFunction fun,
                                          const ReadOnlyCompileOptions& options,
                                          JS::SourceBufferHolder& srcBuf,
                                          const Maybe<uint32_t>& parameterListEnd)
 {
     AutoAssertReportedException assertException(cx);
 
-    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
-
-    BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
+    BytecodeCompiler compiler(cx, options, srcBuf);
     if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
         return false;
     }
 
+    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
     CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::NotGenerator,
                                                                 FunctionAsyncKind::AsyncFunction,
-                                                                parameterListEnd);
+                                                                parameterListEnd,
+                                                                emptyGlobalScope);
     if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }
 
 bool
 frontend::CompileStandaloneAsyncGenerator(JSContext* cx, MutableHandleFunction fun,
                                           const ReadOnlyCompileOptions& options,
                                           JS::SourceBufferHolder& srcBuf,
                                           const Maybe<uint32_t>& parameterListEnd)
 {
     AutoAssertReportedException assertException(cx);
 
-    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
-
-    BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
+    BytecodeCompiler compiler(cx, options, srcBuf);
     if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
         return false;
     }
 
+    RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
     CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::Generator,
                                                                 FunctionAsyncKind::AsyncFunction,
-                                                                parameterListEnd);
+                                                                parameterListEnd,
+                                                                emptyGlobalScope);
     if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }