Bug 1498320 - Remove the original CompileEvalScript overload, and rewrite all users to use a new (EvalScriptInfo&, SourceText<char16_t>&) overload that calls a UTF-8/16-ready template function. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Fri, 26 Oct 2018 21:28:14 -0700
changeset 446516 9d9b2d6342f770aa06a78e4e5932436293551086
parent 446515 24670a08843eba386bc29ad58c8289c39ac969e7
child 446517 a005d87f9e929015e7d56f6ae500d29f35fdc4ad
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 - Remove the original CompileEvalScript overload, and rewrite all users to use a new (EvalScriptInfo&, SourceText<char16_t>&) overload that calls a UTF-8/16-ready template function. r=tcampbell
js/src/builtin/Eval.cpp
js/src/frontend/BytecodeCompilation.h
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/BytecodeCompiler.h
js/src/vm/Debugger.cpp
--- a/js/src/builtin/Eval.cpp
+++ b/js/src/builtin/Eval.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "builtin/Eval.h"
 
 #include "mozilla/HashFunctions.h"
 #include "mozilla/Range.h"
 
-#include "frontend/BytecodeCompiler.h"
+#include "frontend/BytecodeCompilation.h"
 #include "gc/HashUtil.h"
 #include "js/SourceText.h"
 #include "js/StableStringChars.h"
 #include "vm/Debugger.h"
 #include "vm/GlobalObject.h"
 #include "vm/JSContext.h"
 #include "vm/JSONParser.h"
 
@@ -323,17 +323,18 @@ EvalKernel(JSContext* cx, HandleValue v,
         const char16_t* chars = linearChars.twoByteRange().begin().get();
         SourceOwnership ownership = linearChars.maybeGiveOwnershipToCaller()
                                     ? SourceOwnership::TakeOwnership
                                     : SourceOwnership::Borrowed;
         if (!srcBuf.init(cx, chars, linearStr->length(), ownership)) {
             return false;
         }
 
-        JSScript* compiled = frontend::CompileEvalScript(cx, env, enclosing, options, srcBuf);
+        frontend::EvalScriptInfo info(cx, options, env, enclosing);
+        JSScript* compiled = frontend::CompileEvalScript(info, srcBuf);
         if (!compiled) {
             return false;
         }
 
         esg.setNewScript(compiled);
     }
 
     // Look up the newTarget from the frame iterator.
@@ -412,17 +413,18 @@ js::DirectEvalStringFromIon(JSContext* c
         const char16_t* chars = linearChars.twoByteRange().begin().get();
         SourceOwnership ownership = linearChars.maybeGiveOwnershipToCaller()
                                     ? SourceOwnership::TakeOwnership
                                     : SourceOwnership::Borrowed;
         if (!srcBuf.init(cx, chars, linearStr->length(), ownership)) {
             return false;
         }
 
-        JSScript* compiled = frontend::CompileEvalScript(cx, env, enclosing, options, srcBuf);
+        frontend::EvalScriptInfo info(cx, options, env, enclosing);
+        JSScript* compiled = frontend::CompileEvalScript(info, srcBuf);
         if (!compiled) {
             return false;
         }
 
         esg.setNewScript(compiled);
     }
 
     return ExecuteKernel(cx, esg.script(), *env, newTargetValue,
--- a/js/src/frontend/BytecodeCompilation.h
+++ b/js/src/frontend/BytecodeCompilation.h
@@ -142,16 +142,19 @@ class MOZ_STACK_CLASS EvalScriptInfo fin
         return environment_;
     }
 
     EvalSharedContext* sharedContext() {
         return &evalsc_;
     }
 };
 
+extern JSScript*
+CompileEvalScript(EvalScriptInfo& info, JS::SourceText<char16_t>& srcBuf);
+
 class MOZ_STACK_CLASS ModuleInfo final
   : public BytecodeCompiler
 {
   public:
     ModuleInfo(JSContext* cx, const JS::ReadOnlyCompileOptions& options)
       : BytecodeCompiler(cx, options)
     {}
 };
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -225,36 +225,40 @@ CreateGlobalScript(GlobalScriptInfo& inf
 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>
+static JSScript*
+CreateEvalScript(frontend::EvalScriptInfo& info, SourceText<Unit>& srcBuf)
 {
-    using Base = ScriptCompiler<Unit>;
+    AutoAssertReportedException assertException(info.context());
 
-    using Base::compileScript;
-    using Base::prepareScriptParse;
+    frontend::ScriptCompiler<Unit> compiler(srcBuf);
+    if (!compiler.prepareScriptParse(info)) {
+        return nullptr;
+    }
 
-  public:
-    explicit EvalScriptCompiler(SourceText<Unit>& srcBuf)
-      : Base(srcBuf)
-    {}
+    JSScript* script = compiler.compileScript(info, info.environment(), info.sharedContext());
+    if (!script) {
+        return nullptr;
+    }
 
-    JSScript* compile(EvalScriptInfo& info) {
-        if (!prepareScriptParse(info)) {
-            return nullptr;
-        }
-        return compileScript(info, info.environment(), info.sharedContext());
-    }
-};
+    assertException.reset();
+    return script;
+}
+
+JSScript*
+frontend::CompileEvalScript(EvalScriptInfo& info, JS::SourceText<char16_t>& srcBuf)
+{
+    return CreateEvalScript(info, srcBuf);
+}
 
 template<typename Unit>
 class MOZ_STACK_CLASS frontend::ModuleCompiler final
   : public SourceAwareCompiler<Unit>
 {
     using Base = SourceAwareCompiler<Unit>;
 
     using Base::assertSourceParserAndScriptCreated;
@@ -800,39 +804,16 @@ frontend::CompileGlobalBinASTScript(JSCo
     }
 
     assertException.reset();
     return script;
 }
 
 #endif // JS_BUILD_BINAST
 
-JSScript*
-frontend::CompileEvalScript(JSContext* cx, HandleObject environment,
-                            HandleScope enclosingScope,
-                            const ReadOnlyCompileOptions& options,
-                            SourceText<char16_t>& srcBuf,
-                            ScriptSourceObject** sourceObjectOut)
-{
-    AutoAssertReportedException assertException(cx);
-
-    EvalScriptInfo info(cx, options, environment, enclosingScope);
-    AutoInitializeSourceObject autoSSO(info, sourceObjectOut);
-
-    EvalScriptCompiler<char16_t> compiler(srcBuf);
-    JSScript* script = compiler.compile(info);
-    if (!script) {
-        return nullptr;
-    }
-
-    assertException.reset();
-    return script;
-
-}
-
 ModuleObject*
 frontend::CompileModule(JSContext* cx, const ReadOnlyCompileOptions& optionsInput,
                         SourceText<char16_t>& srcBuf,
                         ScriptSourceObject** sourceObjectOut)
 {
     MOZ_ASSERT(srcBuf.get());
     MOZ_ASSERT_IF(sourceObjectOut, *sourceObjectOut == nullptr);
 
--- a/js/src/frontend/BytecodeCompiler.h
+++ b/js/src/frontend/BytecodeCompiler.h
@@ -38,23 +38,16 @@ CompileGlobalBinASTScript(JSContext *cx,
                           const uint8_t* src, size_t len,
                           ScriptSourceObject** sourceObjectOut = nullptr);
 
 MOZ_MUST_USE bool
 CompileLazyBinASTFunction(JSContext* cx, Handle<LazyScript*> lazy, const uint8_t* buf, size_t length);
 
 #endif // JS_BUILD_BINAST
 
-JSScript*
-CompileEvalScript(JSContext* cx, HandleObject environment,
-                  HandleScope enclosingScope,
-                  const JS::ReadOnlyCompileOptions& options,
-                  JS::SourceText<char16_t>& srcBuf,
-                  ScriptSourceObject** sourceObjectOut = nullptr);
-
 ModuleObject*
 CompileModule(JSContext* cx, const JS::ReadOnlyCompileOptions& options,
               JS::SourceText<char16_t>& srcBuf);
 
 ModuleObject*
 CompileModule(JSContext* cx, const JS::ReadOnlyCompileOptions& options,
               JS::SourceText<char16_t>& srcBuf,
               ScriptSourceObject** sourceObjectOut);
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -12,17 +12,16 @@
 #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"
 #include "jit/BaselineJIT.h"
@@ -8922,17 +8921,19 @@ 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);
+
+        frontend::EvalScriptInfo info(cx, options, env, scope);
+        script = frontend::CompileEvalScript(info, srcBuf);
         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