Bug 1529991 Part 2 - Avoid unnecessary delazification in the Debugger, r=jorendorff.

Differential Revision: https://phabricator.services.mozilla.com/D38801

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brian Hackett 2019-07-26 02:19:30 +00:00
parent cea4a22b91
commit 55a87b9190
2 changed files with 42 additions and 28 deletions

View File

@ -1246,14 +1246,6 @@ bool Debugger::wrapDebuggeeObject(JSContext* cx, HandleObject obj,
MutableHandleDebuggerObject result) {
MOZ_ASSERT(obj);
if (obj->is<JSFunction>()) {
MOZ_ASSERT(!IsInternalFunctionObject(*obj));
RootedFunction fun(cx, &obj->as<JSFunction>());
if (!EnsureFunctionHasScript(cx, fun)) {
return false;
}
}
DependentAddPtr<ObjectWeakMap> p(cx, objects, obj);
if (p) {
result.set(&p->value()->as<DebuggerObject>());

View File

@ -537,10 +537,30 @@ bool DebuggerScript::getFormat(JSContext* cx, unsigned argc, Value* vp) {
return true;
}
static bool PushFunctionScript(JSContext* cx, Debugger* dbg, HandleFunction fun,
HandleObject array) {
// Ignore asm.js natives.
if (!IsInterpretedNonSelfHostedFunction(fun)) {
return true;
}
RootedObject wrapped(cx);
if (fun->isInterpretedLazy()) {
Rooted<LazyScript*> lazy(cx, fun->lazyScript());
wrapped = dbg->wrapLazyScript(cx, lazy);
} else {
RootedScript script(cx, fun->nonLazyScript());
wrapped = dbg->wrapScript(cx, script);
}
return wrapped && NewbornArrayPush(cx, array, ObjectValue(*wrapped));
}
/* static */
bool DebuggerScript::getChildScripts(JSContext* cx, unsigned argc, Value* vp) {
THIS_DEBUGSCRIPT_SCRIPT_DELAZIFY(cx, argc, vp, "getChildScripts", args, obj,
script);
THIS_DEBUGSCRIPT_SCRIPT_MAYBE_LAZY(cx, argc, vp, "getChildScripts", args,
obj);
Debugger* dbg = Debugger::fromChildJSObject(obj);
RootedObject result(cx, NewDenseEmptyArray(cx));
@ -548,32 +568,34 @@ bool DebuggerScript::getChildScripts(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
// Wrap and append scripts for the inner functions in script->gcthings().
RootedFunction fun(cx);
RootedScript funScript(cx);
RootedObject s(cx);
for (JS::GCCellPtr gcThing : script->gcthings()) {
if (!gcThing.is<JSObject>()) {
continue;
}
JSObject* obj = &gcThing.as<JSObject>();
if (obj->is<JSFunction>()) {
fun = &obj->as<JSFunction>();
// The inner function could be an asm.js native.
if (!IsInterpretedNonSelfHostedFunction(fun)) {
if (obj->getReferent().is<JSScript*>()) {
RootedScript script(cx, obj->getReferent().as<JSScript*>());
for (JS::GCCellPtr gcThing : script->gcthings()) {
if (!gcThing.is<JSObject>()) {
continue;
}
funScript = GetOrCreateFunctionScript(cx, fun);
if (!funScript) {
return false;
JSObject* obj = &gcThing.as<JSObject>();
if (obj->is<JSFunction>()) {
fun = &obj->as<JSFunction>();
if (!PushFunctionScript(cx, dbg, fun, result)) {
return false;
}
}
s = dbg->wrapScript(cx, funScript);
if (!s || !NewbornArrayPush(cx, result, ObjectValue(*s))) {
}
} else {
Rooted<LazyScript*> lazy(cx, obj->getReferent().as<LazyScript*>());
for (const GCPtrFunction& innerFun : lazy->innerFunctions()) {
fun = innerFun;
if (!PushFunctionScript(cx, dbg, fun, result)) {
return false;
}
}
}
args.rval().setObject(*result);
return true;
}