Bug 1498320 - Create a BytecodeCompiler subclass to perform eval script compilation. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Thu, 01 Nov 2018 17:34:54 -0700
changeset 446502 76feab5328edddcedcacf16353b3fd8c05b2eedf
parent 446501 43b8810bb3eda6bc628dddda9209153c57de653b
child 446503 3ed7e8a375625442194ebb38dc2fd4c1d476b760
push id35042
push useraiakab@mozilla.com
push dateThu, 15 Nov 2018 09:54:38 +0000
treeherdermozilla-central@dca9c72df68b [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 - Create a BytecodeCompiler subclass to perform eval script compilation. r=tcampbell
js/src/frontend/BytecodeCompiler.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -70,18 +70,16 @@ class MOZ_STACK_CLASS BytecodeCompiler
         return sourceObject.get();
     }
 
     // Call this before calling compile{Global,Eval}Script.
     MOZ_MUST_USE bool prepareScriptParse() {
         return createSourceAndParser(ParseGoal::Script) && createCompleteScript();
     }
 
-    JSScript* compileEvalScript(HandleObject environment, HandleScope enclosingScope);
-
     // Call this before calling compileModule.
     MOZ_MUST_USE bool prepareModuleParse() {
         return createSourceAndParser(ParseGoal::Module) && createCompleteScript();
     }
 
     ModuleObject* compileModule(HandleScope enclosingScope);
 
     // Call this before calling parseStandaloneFunction.
@@ -152,16 +150,39 @@ class MOZ_STACK_CLASS GlobalScriptByteco
     JSScript* compile() {
         if (!prepareScriptParse()) {
             return nullptr;
         }
         return compileScript(nullptr, &globalsc_);
     }
 };
 
+class MOZ_STACK_CLASS EvalScriptBytecodeCompiler final
+  : public BytecodeCompiler
+{
+    HandleObject environment_;
+    EvalSharedContext evalsc_;
+
+  public:
+    EvalScriptBytecodeCompiler(JSContext* cx, const ReadOnlyCompileOptions& options,
+                               SourceBufferHolder& sourceBuffer, HandleObject environment,
+                               HandleScope enclosingScope)
+      : BytecodeCompiler(cx, options, sourceBuffer),
+        environment_(environment),
+        evalsc_(cx, environment_, enclosingScope, directives, options.extraWarningsOption)
+    {}
+
+    JSScript* compile() {
+        if (!prepareScriptParse()) {
+            return nullptr;
+        }
+        return compileScript(environment_, &evalsc_);
+    }
+};
+
 AutoFrontendTraceLog::AutoFrontendTraceLog(JSContext* cx, const TraceLoggerTextId id,
                                            const ErrorReporter& errorReporter)
 #ifdef JS_TRACE_LOGGING
   : logger_(TraceLoggerForCurrentThread(cx))
 {
     // If the tokenizer hasn't yet gotten any tokens, use the line and column
     // numbers from CompileOptions.
     uint32_t line, column;
@@ -418,29 +439,16 @@ BytecodeCompiler::compileScript(HandleOb
         return nullptr;
     }
 
     MOZ_ASSERT_IF(!cx->helperThread(), !cx->isExceptionPending());
 
     return script;
 }
 
-JSScript*
-BytecodeCompiler::compileEvalScript(HandleObject environment, HandleScope enclosingScope)
-{
-    EvalSharedContext evalsc(cx, environment, enclosingScope,
-                             directives, options.extraWarningsOption);
-
-    if (!prepareScriptParse()) {
-        return nullptr;
-    }
-
-    return compileScript(environment, &evalsc);
-}
-
 ModuleObject*
 BytecodeCompiler::compileModule(HandleScope enclosingScope)
 {
     assertSourceParserAndScriptCreated();
 
     Rooted<ModuleObject*> module(cx, ModuleObject::create(cx));
     if (!module) {
         return nullptr;
@@ -743,22 +751,25 @@ 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);
+
+    EvalScriptBytecodeCompiler compiler(cx, options, srcBuf, environment, enclosingScope);
     AutoInitializeSourceObject autoSSO(compiler, sourceObjectOut);
-    JSScript* script = compiler.compileEvalScript(environment, enclosingScope);
+
+    JSScript* script = compiler.compile();
     if (!script) {
         return nullptr;
     }
+
     assertException.reset();
     return script;
 
 }
 
 ModuleObject*
 frontend::CompileModule(JSContext* cx, const ReadOnlyCompileOptions& optionsInput,
                         SourceBufferHolder& srcBuf,