mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 01:35:35 +00:00
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 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
e86151739c
commit
4c44ca754f
@ -295,20 +295,6 @@ bool DebuggerScript::CallData::ToNative(JSContext* cx, unsigned argc, Value* vp)
|
||||
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;
|
||||
@ -330,9 +316,7 @@ bool DebuggerScript::CallData::getIsFunction() {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -349,8 +333,7 @@ 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;
|
||||
|
@ -70,7 +70,7 @@ void SetFrameArgumentsObject(JSContext* cx, AbstractFramePtr frame,
|
||||
} // 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
|
||||
@ -84,7 +84,7 @@ inline JSFunction* JSScript::functionDelazifying() const {
|
||||
|
||||
inline void JSScript::ensureNonLazyCanonicalFunction() {
|
||||
// Infallibly delazify the canonical script.
|
||||
JSFunction* fun = function();
|
||||
JSFunction* fun = functionNonDelazifying();
|
||||
if (fun && fun->isInterpretedLazy()) {
|
||||
functionDelazifying();
|
||||
}
|
||||
|
@ -1515,7 +1515,7 @@ class BaseScript : public gc::TenuredCell {
|
||||
|
||||
// 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
|
||||
@ -1638,6 +1638,13 @@ class BaseScript : public gc::TenuredCell {
|
||||
}
|
||||
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;
|
||||
@ -2678,12 +2685,6 @@ class JSScript : public js::BaseScript {
|
||||
* 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.
|
||||
@ -3013,13 +3014,6 @@ class JSScript : public js::BaseScript {
|
||||
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);
|
||||
|
||||
@ -3295,10 +3289,6 @@ class LazyScript : public BaseScript {
|
||||
|
||||
static inline JSFunction* functionDelazifying(JSContext* cx,
|
||||
Handle<LazyScript*>);
|
||||
JSFunction* functionNonDelazifying() const {
|
||||
return &functionOrGlobal_->as<JSFunction>();
|
||||
}
|
||||
|
||||
void initScript(JSScript* script);
|
||||
|
||||
JSScript* maybeScript() { return script_; }
|
||||
|
Loading…
Reference in New Issue
Block a user