Bug 1544882 - Move JSScript::loadSource into ScriptSource, because it only acts on ScriptSource and so only makes sense there. r=arai
authorJeff Walden <jwalden@mit.edu>
Mon, 15 Apr 2019 15:09:01 -0700
changeset 530253 8509f60299dfdb085a8a64ea45522bacb82b16c5
parent 530252 74774a7f1a4dd13925354df4e3963068fc4cd28d
child 530254 14248be0eba939ce2317e887e205386ad3214774
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1544882
milestone68.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 1544882 - Move JSScript::loadSource into ScriptSource, because it only acts on ScriptSource and so only makes sense there. r=arai Differential Revision: https://phabricator.services.mozilla.com/D27768
js/src/jsapi.cpp
js/src/vm/Debugger.cpp
js/src/vm/JSFunction.cpp
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
js/src/wasm/AsmJS.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3655,17 +3655,17 @@ JS_PUBLIC_API JSString* JS_DecompileScri
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
   script->ensureNonLazyCanonicalFunction();
   RootedFunction fun(cx, script->functionNonDelazifying());
   if (fun) {
     return JS_DecompileFunction(cx, fun);
   }
   bool haveSource;
-  if (!JSScript::loadSource(cx, script->scriptSource(), &haveSource)) {
+  if (!ScriptSource::loadSource(cx, script->scriptSource(), &haveSource)) {
     return nullptr;
   }
   return haveSource ? JSScript::sourceData(cx, script)
                     : NewStringCopyZ<CanGC>(cx, "[no source]");
 }
 
 JS_PUBLIC_API JSString* JS_DecompileFunction(JSContext* cx,
                                              HandleFunction fun) {
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -8407,17 +8407,17 @@ class DebuggerSourceGetTextMatcher {
  public:
   explicit DebuggerSourceGetTextMatcher(JSContext* cx) : cx_(cx) {}
 
   using ReturnType = JSString*;
 
   ReturnType match(HandleScriptSourceObject sourceObject) {
     ScriptSource* ss = sourceObject->source();
     bool hasSourceText;
-    if (!JSScript::loadSource(cx_, ss, &hasSourceText)) {
+    if (!ScriptSource::loadSource(cx_, ss, &hasSourceText)) {
       return nullptr;
     }
     if (!hasSourceText) {
       return NewStringCopyZ<CanGC>(cx_, "[no source]");
     }
 
     if (ss->isFunctionBody()) {
       return ss->functionBodyString(cx_);
--- a/js/src/vm/JSFunction.cpp
+++ b/js/src/vm/JSFunction.cpp
@@ -865,17 +865,17 @@ JSString* js::FunctionToString(JSContext
                     (fun->isClassConstructor() || !fun->isSelfHostedBuiltin());
 
   // If we're in toSource mode, put parentheses around lambda functions so
   // that eval returns lambda, not function statement.
   bool addParentheses =
       haveSource && isToSource && (fun->isLambda() && !fun->isArrow());
 
   if (haveSource) {
-    if (!JSScript::loadSource(cx, script->scriptSource(), &haveSource)) {
+    if (!ScriptSource::loadSource(cx, script->scriptSource(), &haveSource)) {
       return nullptr;
     }
   }
 
   // Fast path for the common case, to avoid StringBuffer overhead.
   if (!addParentheses && haveSource) {
     FunctionToStringCache& cache = cx->zone()->functionToStringCache();
     if (JSString* str = cache.lookup(script)) {
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -1648,17 +1648,17 @@ void ScriptSourceObject::setPrivate(JSRu
   JS::AutoSuppressGCAnalysis nogc;
   Value prevValue = getReservedSlot(PRIVATE_SLOT);
   rt->releaseScriptPrivate(prevValue);
   setReservedSlot(PRIVATE_SLOT, value);
   rt->addRefScriptPrivate(value);
 }
 
 /* static */
-bool JSScript::loadSource(JSContext* cx, ScriptSource* ss, bool* loaded) {
+bool ScriptSource::loadSource(JSContext* cx, ScriptSource* ss, bool* loaded) {
   *loaded = ss->hasSourceText();
   if (*loaded) {
     return true;
   }
 
   if (!cx->runtime()->sourceHook.ref() || !ss->sourceRetrievable()) {
     return true;
   }
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -686,16 +686,22 @@ class ScriptSource {
       const mozilla::Maybe<uint32_t>& parameterListEnd = mozilla::Nothing());
 
   /**
    * The minimum script length (in code units) necessary for a script to be
    * eligible to be compressed.
    */
   static constexpr size_t MinimumCompressibleLength = 256;
 
+  // Attempt to load usable source for |ss| -- source text on which substring
+  // operations and the like can be performed.  On success return true and set
+  // |*loaded| to indicate whether usable source could be loaded; otherwise
+  // return false.
+  static bool loadSource(JSContext* cx, ScriptSource* ss, bool* loaded);
+
   template <typename Unit>
   MOZ_MUST_USE bool setSourceCopy(JSContext* cx, JS::SourceText<Unit>& srcBuf);
 
   void setSourceRetrievable() { sourceRetrievable_ = true; }
   bool sourceRetrievable() const { return sourceRetrievable_; }
   bool hasSourceText() const {
     return hasUncompressedSource() || hasCompressedSource();
   }
@@ -2489,22 +2495,16 @@ class JSScript : public js::gc::TenuredC
   // directly, via lazy arguments or a rest parameter.
   bool mayReadFrameArgsDirectly();
 
   static JSFlatString* sourceData(JSContext* cx, JS::HandleScript script);
 
   MOZ_MUST_USE bool appendSourceDataForToString(JSContext* cx,
                                                 js::StringBuffer& buf);
 
-  // Attempt to load usable source for |ss| -- source text on which substring
-  // operations and the like can be performed.  On success return true and set
-  // |*loaded| to indicate whether usable source could be loaded; otherwise
-  // return false.
-  static bool loadSource(JSContext* cx, js::ScriptSource* ss, bool* loaded);
-
   void setSourceObject(js::ScriptSourceObject* object);
   js::ScriptSourceObject* sourceObject() const { return sourceObject_; }
   js::ScriptSource* scriptSource() const;
   js::ScriptSource* maybeForwardedScriptSource() const;
 
   void setDefaultClassConstructorSpan(js::ScriptSourceObject* sourceObject,
                                       uint32_t start, uint32_t end,
                                       unsigned line, unsigned column);
--- a/js/src/wasm/AsmJS.cpp
+++ b/js/src/wasm/AsmJS.cpp
@@ -6882,17 +6882,17 @@ static bool HandleInstantiationFailure(J
     return false;
   }
 
   ScriptSource* source = metadata.scriptSource.get();
 
   // Source discarding is allowed to affect JS semantics because it is never
   // enabled for normal JS content.
   bool haveSource;
-  if (!JSScript::loadSource(cx, source, &haveSource)) {
+  if (!ScriptSource::loadSource(cx, source, &haveSource)) {
     return false;
   }
   if (!haveSource) {
     JS_ReportErrorASCII(cx,
                         "asm.js link failure with source discarding enabled");
     return false;
   }
 
@@ -7214,17 +7214,17 @@ JSString* js::AsmJSModuleToString(JSCont
 
   JSStringBuilder out(cx);
 
   if (isToSource && fun->isLambda() && !out.append("(")) {
     return nullptr;
   }
 
   bool haveSource;
-  if (!JSScript::loadSource(cx, source, &haveSource)) {
+  if (!ScriptSource::loadSource(cx, source, &haveSource)) {
     return nullptr;
   }
 
   if (!haveSource) {
     if (!out.append("function ")) {
       return nullptr;
     }
     if (fun->explicitName() && !out.append(fun->explicitName())) {
@@ -7265,17 +7265,17 @@ JSString* js::AsmJSFunctionToString(JSCo
   ScriptSource* source = metadata.scriptSource.get();
   JSStringBuilder out(cx);
 
   if (!out.append("function ")) {
     return nullptr;
   }
 
   bool haveSource;
-  if (!JSScript::loadSource(cx, source, &haveSource)) {
+  if (!ScriptSource::loadSource(cx, source, &haveSource)) {
     return nullptr;
   }
 
   if (!haveSource) {
     // asm.js functions can't be anonymous
     MOZ_ASSERT(fun->explicitName());
     if (!out.append(fun->explicitName())) {
       return nullptr;