Bug 1498320 - Remove the original CompileGlobalScript overload, and rewrite all users to use the new (GlobalScriptInfo&, SourceText<char16_t>&, ScriptSourceObject**) overload. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Fri, 26 Oct 2018 21:28:14 -0700
changeset 446438 24670a08843eba386bc29ad58c8289c39ac969e7
parent 446437 1dd5267839b3ccd35c62bcff81f7b8c60304f13e
child 446439 9d9b2d6342f770aa06a78e4e5932436293551086
push id109874
push userjwalden@mit.edu
push dateWed, 14 Nov 2018 23:38:56 +0000
treeherdermozilla-inbound@5b0d24759be6 [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 the original CompileGlobalScript overload, and rewrite all users to use the new (GlobalScriptInfo&, SourceText<char16_t>&, ScriptSourceObject**) overload. r=tcampbell
js/src/frontend/BytecodeCompilation.h
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/BytecodeCompiler.h
js/src/vm/CompilationAndEvaluation.cpp
js/src/vm/Debugger.cpp
js/src/vm/HelperThreads.cpp
--- a/js/src/frontend/BytecodeCompilation.h
+++ b/js/src/frontend/BytecodeCompilation.h
@@ -115,16 +115,20 @@ class MOZ_STACK_CLASS GlobalScriptInfo f
         MOZ_ASSERT(scopeKind == ScopeKind::Global || scopeKind == ScopeKind::NonSyntactic);
     }
 
     GlobalSharedContext* sharedContext() {
         return &globalsc_;
     }
 };
 
+extern JSScript*
+CompileGlobalScript(GlobalScriptInfo& info, JS::SourceText<char16_t>& srcBuf,
+                    ScriptSourceObject** sourceObjectOut = nullptr);
+
 class MOZ_STACK_CLASS EvalScriptInfo final
   : public BytecodeCompiler
 {
     JS::Handle<JSObject*> environment_;
     EvalSharedContext evalsc_;
 
   public:
     EvalScriptInfo(JSContext* cx, const JS::ReadOnlyCompileOptions& options,
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -217,16 +217,23 @@ CreateGlobalScript(GlobalScriptInfo& inf
     if (!script) {
         return nullptr;
     }
 
     assertException.reset();
     return script;
 }
 
+JSScript*
+frontend::CompileGlobalScript(GlobalScriptInfo& info, JS::SourceText<char16_t>& srcBuf,
+                              ScriptSourceObject** sourceObjectOut /* = nullptr */)
+{
+    return CreateGlobalScript(info, srcBuf, sourceObjectOut);
+}
+
 template<typename Unit>
 class MOZ_STACK_CLASS EvalScriptCompiler final
   : public ScriptCompiler<Unit>
 {
     using Base = ScriptCompiler<Unit>;
 
     using Base::compileScript;
     using Base::prepareScriptParse;
@@ -730,28 +737,16 @@ frontend::CreateScriptSourceObject(JSCon
         if (!ScriptSourceObject::initFromOptions(cx, sso, options)) {
             return nullptr;
         }
     }
 
     return sso;
 }
 
-JSScript*
-frontend::CompileGlobalScript(JSContext* cx, ScopeKind scopeKind,
-                              const ReadOnlyCompileOptions& options,
-                              SourceText<char16_t>& srcBuf,
-                              ScriptSourceObject** sourceObjectOut)
-{
-    MOZ_ASSERT(scopeKind == ScopeKind::Global || scopeKind == ScopeKind::NonSyntactic);
-
-    GlobalScriptInfo info(cx, options, scopeKind);
-    return CreateGlobalScript(info, srcBuf, sourceObjectOut);
-}
-
 #if defined(JS_BUILD_BINAST)
 
 JSScript*
 frontend::CompileGlobalBinASTScript(JSContext* cx, LifoAlloc& alloc, const ReadOnlyCompileOptions& options,
                                     const uint8_t* src, size_t len, ScriptSourceObject** sourceObjectOut)
 {
     AutoAssertReportedException assertException(cx);
 
--- a/js/src/frontend/BytecodeCompiler.h
+++ b/js/src/frontend/BytecodeCompiler.h
@@ -25,22 +25,16 @@ class ModuleObject;
 class ScriptSourceObject;
 
 namespace frontend {
 
 class ErrorReporter;
 class FunctionBox;
 class ParseNode;
 
-JSScript*
-CompileGlobalScript(JSContext* cx, ScopeKind scopeKind,
-                    const JS::ReadOnlyCompileOptions& options,
-                    JS::SourceText<char16_t>& srcBuf,
-                    ScriptSourceObject** sourceObjectOut = nullptr);
-
 #if defined(JS_BUILD_BINAST)
 
 JSScript*
 CompileGlobalBinASTScript(JSContext *cx, LifoAlloc& alloc,
                           const JS::ReadOnlyCompileOptions& options,
                           const uint8_t* src, size_t len,
                           ScriptSourceObject** sourceObjectOut = nullptr);
 
--- a/js/src/vm/CompilationAndEvaluation.cpp
+++ b/js/src/vm/CompilationAndEvaluation.cpp
@@ -11,16 +11,17 @@
 #include "mozilla/Maybe.h" // mozilla::None, mozilla::Some
 #include "mozilla/TextUtils.h" // mozilla::IsAscii
 
 #include <utility> // std::move
 
 #include "jsfriendapi.h" // js::GetErrorMessage
 #include "jstypes.h" // JS_PUBLIC_API
 
+#include "frontend/BytecodeCompilation.h" // frontend::CompileGlobalScript
 #include "frontend/FullParseHandler.h" // frontend::FullParseHandler
 #include "frontend/ParseContext.h" // frontend::UsedNameTracker
 #include "frontend/Parser.h" // frontend::Parser, frontend::ParseGoal
 #include "js/CharacterEncoding.h" // JS::UTF8Chars, JS::UTF8CharsToNewTwoByteCharsZ
 #include "js/RootingAPI.h" // JS::Rooted
 #include "js/SourceText.h" // JS::SourceText
 #include "js/TypeDecls.h" // JS::HandleObject, JS::MutableHandleScript
 #include "js/Utility.h" // JS::UniqueTwoByteChars
@@ -56,17 +57,18 @@ CompileSourceBuffer(JSContext* cx, const
                     SourceText<char16_t>& srcBuf, JS::MutableHandleScript script)
 {
     ScopeKind scopeKind = options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
 
     MOZ_ASSERT(!cx->zone()->isAtomsZone());
     AssertHeapIsIdle();
     CHECK_THREAD(cx);
 
-    script.set(frontend::CompileGlobalScript(cx, scopeKind, options, srcBuf));
+    frontend::GlobalScriptInfo info(cx, options, scopeKind);
+    script.set(frontend::CompileGlobalScript(info, srcBuf));
     return !!script;
 }
 
 static bool
 CompileLatin1(JSContext* cx, const ReadOnlyCompileOptions& options,
               const char* bytes, size_t length, JS::MutableHandleScript script)
 {
     auto chars = UniqueTwoByteChars(InflateString(cx, bytes, length));
@@ -518,25 +520,27 @@ Evaluate(JSContext* cx, ScopeKind scopeK
     CompileOptions options(cx, optionsArg);
     MOZ_ASSERT(!cx->zone()->isAtomsZone());
     AssertHeapIsIdle();
     CHECK_THREAD(cx);
     cx->check(env);
     MOZ_ASSERT_IF(!IsGlobalLexicalEnvironment(env), scopeKind == ScopeKind::NonSyntactic);
 
     options.setIsRunOnce(true);
-    RootedScript script(cx, frontend::CompileGlobalScript(cx, scopeKind, options, srcBuf));
-    if (!script) {
-        return false;
+
+    RootedScript script(cx);
+    {
+        frontend::GlobalScriptInfo info(cx, options, scopeKind);
+        script = frontend::CompileGlobalScript(info, srcBuf);
+        if (!script) {
+            return false;
+        }
     }
 
-    bool result = Execute(cx, script, *env,
-                          options.noScriptRval ? nullptr : rval.address());
-
-    return result;
+    return Execute(cx, script, *env, options.noScriptRval ? nullptr : rval.address());
 }
 
 static bool
 Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions& optionsArg,
          SourceText<char16_t>& srcBuf, MutableHandleValue rval)
 {
     RootedObject env(cx);
     RootedScope scope(cx);
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -11,16 +11,17 @@
 #include "mozilla/Sprintf.h"
 #include "mozilla/TypeTraits.h"
 
 #include <utility>
 
 #include "jsfriendapi.h"
 #include "jsnum.h"
 
+#include "frontend/BytecodeCompilation.h"
 #include "frontend/BytecodeCompiler.h"
 #include "frontend/Parser.h"
 #include "gc/FreeOp.h"
 #include "gc/HashUtil.h"
 #include "gc/Marking.h"
 #include "gc/Policy.h"
 #include "gc/PublicIterators.h"
 #include "jit/BaselineDebugModeOSR.h"
@@ -8922,30 +8923,32 @@ EvaluateInEnv(JSContext* cx, Handle<Env*
 
     if (frame) {
         MOZ_ASSERT(scopeKind == ScopeKind::NonSyntactic);
         RootedScope scope(cx, GlobalScope::createEmpty(cx, ScopeKind::NonSyntactic));
         if (!scope) {
             return false;
         }
         script = frontend::CompileEvalScript(cx, env, scope, options, srcBuf);
-        if (script) {
-            script->setActiveEval();
-        }
+        if (!script) {
+            return false;
+        }
+
+        script->setActiveEval();
     } else {
         // Do not consider executeInGlobal{WithBindings} as an eval, but instead
         // as executing a series of statements at the global level. This is to
         // circumvent the fresh lexical scope that all eval have, so that the
         // users of executeInGlobal, like the web console, may add new bindings to
         // the global scope.
-        script = frontend::CompileGlobalScript(cx, scopeKind, options, srcBuf);
-    }
-
-    if (!script) {
-        return false;
+        frontend::GlobalScriptInfo info(cx, options, scopeKind);
+        script = frontend::CompileGlobalScript(info, srcBuf);
+        if (!script) {
+            return false;
+        }
     }
 
     return ExecuteKernel(cx, script, *env, NullValue(), frame, rval.address());
 }
 
 static bool
 DebuggerGenericEval(JSContext* cx, const mozilla::Range<const char16_t> chars,
                     HandleObject bindings, const EvalOptions& options,
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -6,17 +6,17 @@
 
 #include "vm/HelperThreads.h"
 
 #include "mozilla/Maybe.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Unused.h"
 
 #include "builtin/Promise.h"
-#include "frontend/BytecodeCompiler.h"
+#include "frontend/BytecodeCompilation.h"
 #include "gc/GCInternals.h"
 #include "jit/IonBuilder.h"
 #include "js/SourceText.h"
 #include "js/UniquePtr.h"
 #include "js/Utility.h"
 #include "threading/CpuCount.h"
 #include "util/NativeStack.h"
 #include "vm/Debugger.h"
@@ -509,25 +509,36 @@ ScriptParseTask::ScriptParseTask(JSConte
     data(std::move(srcBuf))
 {}
 
 void
 ScriptParseTask::parse(JSContext* cx)
 {
     MOZ_ASSERT(cx->helperThread());
 
+    JSScript* script;
     Rooted<ScriptSourceObject*> sourceObject(cx);
 
-    ScopeKind scopeKind = options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
-
-    JSScript* script = frontend::CompileGlobalScript(cx, scopeKind, options, data,
-                                                     /* sourceObjectOut = */ &sourceObject.get());
+    {
+        ScopeKind scopeKind = options.nonSyntacticScope
+                              ? ScopeKind::NonSyntactic
+                              : ScopeKind::Global;
+        frontend::GlobalScriptInfo info(cx, options, scopeKind);
+        script = frontend::CompileGlobalScript(info, data,
+                                               /* sourceObjectOut = */ &sourceObject.get());
+    }
+
     if (script) {
         scripts.infallibleAppend(script);
     }
+
+    // Whatever happens to the top-level script compilation (even if it fails),
+    // we must finish initializing the SSO.  This is because there may be valid
+    // inner scripts observable by the debugger which reference the partially-
+    // initialized SSO.
     if (sourceObject) {
         sourceObjects.infallibleAppend(sourceObject);
     }
 }
 
 ModuleParseTask::ModuleParseTask(JSContext* cx, JS::SourceText<char16_t>& srcBuf,
                                  JS::OffThreadCompileCallback callback, void* callbackData)
   : ParseTask(ParseTaskKind::Module, cx, callback, callbackData),