Bug 1583816 - Add BaseScript::functionNonDelazifying() and simplify code r=jandem
☠☠ backed out by bb56e5bd2203 ☠ ☠
authorTed Campbell <tcampbell@mozilla.com>
Mon, 30 Sep 2019 08:45:54 +0000
changeset 495664 73734a2e8547b2cc72920c255b933183e70ee8ba
parent 495663 2736f38dd2ce83b8711c0db304fcf6cf5b62f56f
child 495665 e545376c33914c25a9252a74e09bd2b5b3e8ed76
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1583816
milestone71.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 1583816 - Add BaseScript::functionNonDelazifying() and simplify code r=jandem Instead of checking for canonical function using scope chain, we can directly use the functionOrGlobal field. By moving this to the BaseScript class we can also simplify the debugger acccess. Depends on D47070 Differential Revision: https://phabricator.services.mozilla.com/D47071
js/src/debugger/Script.cpp
js/src/vm/JSScript-inl.h
js/src/vm/JSScript.h
--- a/js/src/debugger/Script.cpp
+++ b/js/src/debugger/Script.cpp
@@ -290,30 +290,16 @@ bool DebuggerScript::CallData::ToNative(
   if (!obj) {
     return false;
   }
 
   CallData data(cx, args, obj);
   return (data.*MyMethod)();
 }
 
-template <typename Result>
-Result CallScriptMethod(HandleDebuggerScript obj,
-                        Result (JSScript::*ifJSScript)() const,
-                        Result (LazyScript::*ifLazyScript)() const) {
-  if (obj->getReferent().is<JSScript*>()) {
-    JSScript* script = obj->getReferent().as<JSScript*>();
-    return (script->*ifJSScript)();
-  }
-
-  MOZ_ASSERT(obj->getReferent().is<LazyScript*>());
-  LazyScript* lazyScript = obj->getReferent().as<LazyScript*>();
-  return (lazyScript->*ifLazyScript)();
-}
-
 bool DebuggerScript::CallData::getIsGeneratorFunction() {
   if (!ensureScriptMaybeLazy()) {
     return false;
   }
   args.rval().setBoolean(obj->getReferentScript()->isGenerator());
   return true;
 }
 
@@ -325,37 +311,34 @@ bool DebuggerScript::CallData::getIsAsyn
   return true;
 }
 
 bool DebuggerScript::CallData::getIsFunction() {
   if (!ensureScriptMaybeLazy()) {
     return false;
   }
 
-  // Note: LazyScripts always have functions.
-  args.rval().setBoolean(!referent.is<JSScript*>() ||
-                         referent.as<JSScript*>()->functionNonDelazifying());
+  args.rval().setBoolean(obj->getReferentScript()->functionNonDelazifying());
   return true;
 }
 
 bool DebuggerScript::CallData::getIsModule() {
   if (!ensureScriptMaybeLazy()) {
     return false;
   }
   args.rval().setBoolean(referent.is<JSScript*>() &&
                          referent.as<JSScript*>()->isModule());
   return true;
 }
 
 bool DebuggerScript::CallData::getDisplayName() {
   if (!ensureScriptMaybeLazy()) {
     return false;
   }
-  JSFunction* func = CallScriptMethod(obj, &JSScript::functionNonDelazifying,
-                                      &LazyScript::functionNonDelazifying);
+  JSFunction* func = obj->getReferentScript()->functionNonDelazifying();
   Debugger* dbg = Debugger::fromChildJSObject(obj);
 
   JSString* name = func ? func->displayAtom() : nullptr;
   if (!name) {
     args.rval().setUndefined();
     return true;
   }
 
--- a/js/src/vm/JSScript-inl.h
+++ b/js/src/vm/JSScript-inl.h
@@ -65,31 +65,31 @@ void SetFrameArgumentsObject(JSContext* 
     return nullptr;
   }
   return fun;
 }
 
 }  // namespace js
 
 inline JSFunction* JSScript::functionDelazifying() const {
-  JSFunction* fun = function();
+  JSFunction* fun = functionNonDelazifying();
   if (fun && fun->isInterpretedLazy()) {
     fun->setUnlazifiedScript(const_cast<JSScript*>(this));
     // If this script has a LazyScript, make sure the LazyScript has a
     // reference to the script when delazifying its canonical function.
     if (lazyScript && !lazyScript->maybeScript()) {
       lazyScript->initScript(const_cast<JSScript*>(this));
     }
   }
   return fun;
 }
 
 inline void JSScript::ensureNonLazyCanonicalFunction() {
   // Infallibly delazify the canonical script.
-  JSFunction* fun = function();
+  JSFunction* fun = functionNonDelazifying();
   if (fun && fun->isInterpretedLazy()) {
     functionDelazifying();
   }
 }
 
 inline JSFunction* JSScript::getFunction(size_t index) {
   JSObject* obj = getObject(index);
   MOZ_RELEASE_ASSERT(obj->is<JSFunction>(), "Script object is not JSFunction");
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1510,17 +1510,17 @@ class BaseScript : public gc::TenuredCel
 
     NeedsHomeObject = 1 << 13,
 
     IsDerivedClassConstructor = 1 << 14,
     IsDefaultClassConstructor = 1 << 15,
 
     // Script is a lambda to treat as running once or a global or eval script
     // that will only run once.  Which one it is can be disambiguated by
-    // checking whether function() is null.
+    // checking whether functionNonDelazifying() is null.
     TreatAsRunOnce = 1 << 16,
 
     // 'this', 'arguments' and f.apply() are used. This is likely to be a
     // wrapper.
     IsLikelyConstructorWrapper = 1 << 17,
 
     // Set if this function is a generator function or async generator.
     IsGenerator = 1 << 18,
@@ -1633,16 +1633,23 @@ class BaseScript : public gc::TenuredCel
   uint8_t* jitCodeRaw() const { return jitCodeRaw_; }
 
   JS::Realm* realm() const { return functionOrGlobal_->nonCCWRealm(); }
   JS::Compartment* compartment() const {
     return functionOrGlobal_->compartment();
   }
   JS::Compartment* maybeCompartment() const { return compartment(); }
 
+  JSFunction* functionNonDelazifying() const {
+    if (functionOrGlobal_->is<JSFunction>()) {
+      return &functionOrGlobal_->as<JSFunction>();
+    }
+    return nullptr;
+  }
+
   ScriptSourceObject* sourceObject() const { return sourceObject_; }
   ScriptSource* scriptSource() const { return sourceObject()->source(); }
   ScriptSource* maybeForwardedScriptSource() const;
 
   bool mutedErrors() const { return scriptSource()->mutedErrors(); }
 
   const char* filename() const { return scriptSource()->filename(); }
   const char* maybeForwardedFilename() const {
@@ -2673,22 +2680,16 @@ class JSScript : public js::BaseScript {
    * Original compiled function for the script, if it has a function.
    * nullptr for global and eval scripts.
    * The delazifying variant ensures that the function isn't lazy. The
    * non-delazifying variant must only be used after earlier code has
    * called ensureNonLazyCanonicalFunction and while the function can't
    * have been relazified.
    */
   inline JSFunction* functionDelazifying() const;
-  JSFunction* functionNonDelazifying() const {
-    if (bodyScope()->is<js::FunctionScope>()) {
-      return bodyScope()->as<js::FunctionScope>().canonicalFunction();
-    }
-    return nullptr;
-  }
   /*
    * De-lazifies the canonical function. Must be called before entering code
    * that expects the function to be non-lazy.
    */
   inline void ensureNonLazyCanonicalFunction();
 
   bool isModule() const {
     MOZ_ASSERT(hasFlag(ImmutableFlags::IsModule) ==
@@ -3008,23 +3009,16 @@ class JSScript : public js::BaseScript {
     MOZ_ASSERT(js::JOF_OPTYPE(JSOp(*pc)) == JOF_SCOPE,
                "Did you mean to use lookupScope(pc)?");
     return getScope(GET_UINT32_INDEX(pc));
   }
 
   inline JSFunction* getFunction(size_t index);
   inline JSFunction* getFunction(jsbytecode* pc);
 
-  JSFunction* function() const {
-    if (functionNonDelazifying()) {
-      return functionNonDelazifying();
-    }
-    return nullptr;
-  }
-
   inline js::RegExpObject* getRegExp(size_t index);
   inline js::RegExpObject* getRegExp(jsbytecode* pc);
 
   js::BigInt* getBigInt(size_t index) {
     return &gcthings()[index].as<js::BigInt>();
   }
 
   js::BigInt* getBigInt(jsbytecode* pc) {
@@ -3290,20 +3284,16 @@ class LazyScript : public BaseScript {
       JSContext* cx, uint32_t numClosedOverBindings, uint32_t numInnerFunctions,
       HandleFunction fun, HandleScript script, HandleScope enclosingScope,
       HandleScriptSourceObject sourceObject, uint32_t immutableFlags,
       uint32_t sourceStart, uint32_t sourceEnd, uint32_t toStringStart,
       uint32_t toStringEnd, uint32_t lineno, uint32_t column);
 
   static inline JSFunction* functionDelazifying(JSContext* cx,
                                                 Handle<LazyScript*>);
-  JSFunction* functionNonDelazifying() const {
-    return &functionOrGlobal_->as<JSFunction>();
-  }
-
   void initScript(JSScript* script);
 
   JSScript* maybeScript() { return script_; }
   const JSScript* maybeScriptUnbarriered() const {
     return script_.unbarrieredGet();
   }
   bool hasScript() const { return bool(script_); }