Bug 1526394: Treat self-hosted functions the same as non-interpreted functions in Debugger code. r=jorendorff

This commit is contained in:
André Bargull 2019-03-26 12:27:54 -07:00
Родитель c4004ef40c
Коммит 3b306926a8
4 изменённых файлов: 41 добавлений и 7 удалений

Просмотреть файл

@ -125,7 +125,7 @@ const TEST_DATA = [ // eslint-disable-line
"Bubbling", "Bubbling",
"DOM2", "DOM2",
], ],
handler: "function sort(arr, comparefn) {\n" + handler: "function sort(, ) {\n" +
" [native code]\n" + " [native code]\n" +
"}", "}",
}, },

Просмотреть файл

@ -0,0 +1,15 @@
// The environment of self-hosted builtins is not exposed to the debugger and
// instead is reported as |undefined| just like native builtins.
let g = newGlobal({newCompartment: true});
let dbg = new Debugger();
let gw = dbg.addDebuggee(g);
// Array is a known native builtin function.
let nativeBuiltin = gw.makeDebuggeeValue(g.Array);
assertEq(nativeBuiltin.environment, undefined);
// Array.prototype[@@iterator] is a known self-hosted builtin function.
let selfhostedBuiltin = gw.makeDebuggeeValue(g.Array.prototype[Symbol.iterator]);
assertEq(selfhostedBuiltin.environment, undefined);

Просмотреть файл

@ -0,0 +1,15 @@
// The script of self-hosted builtins is not exposed to the debugger and
// instead is reported as |undefined| just like native builtins.
let g = newGlobal({newCompartment: true});
let dbg = new Debugger();
let gw = dbg.addDebuggee(g);
// Array is a known native builtin function.
let nativeBuiltin = gw.makeDebuggeeValue(g.Array);
assertEq(nativeBuiltin.script, undefined);
// Array.prototype[@@iterator] is a known self-hosted builtin function.
let selfhostedBuiltin = gw.makeDebuggeeValue(g.Array.prototype[Symbol.iterator]);
assertEq(selfhostedBuiltin.script, undefined);

Просмотреть файл

@ -202,6 +202,10 @@ static const Class DebuggerSource_class = {
/*** Utils ******************************************************************/ /*** Utils ******************************************************************/
static inline bool IsInterpretedNonSelfHostedFunction(JSFunction* fun) {
return fun->isInterpreted() && !fun->isSelfHostedBuiltin();
}
static inline bool EnsureFunctionHasScript(JSContext* cx, HandleFunction fun) { static inline bool EnsureFunctionHasScript(JSContext* cx, HandleFunction fun) {
if (fun->isInterpretedLazy()) { if (fun->isInterpretedLazy()) {
AutoRealm ar(cx, fun); AutoRealm ar(cx, fun);
@ -212,7 +216,7 @@ static inline bool EnsureFunctionHasScript(JSContext* cx, HandleFunction fun) {
static inline JSScript* GetOrCreateFunctionScript(JSContext* cx, static inline JSScript* GetOrCreateFunctionScript(JSContext* cx,
HandleFunction fun) { HandleFunction fun) {
MOZ_ASSERT(fun->isInterpreted()); MOZ_ASSERT(IsInterpretedNonSelfHostedFunction(fun));
if (!EnsureFunctionHasScript(cx, fun)) { if (!EnsureFunctionHasScript(cx, fun)) {
return nullptr; return nullptr;
} }
@ -6332,8 +6336,8 @@ static bool DebuggerScript_getChildScripts(JSContext* cx, unsigned argc,
for (const GCPtrObject& obj : script->objects()) { for (const GCPtrObject& obj : script->objects()) {
if (obj->is<JSFunction>()) { if (obj->is<JSFunction>()) {
fun = &obj->as<JSFunction>(); fun = &obj->as<JSFunction>();
// The inner function could be a wasm native. // The inner function could be an asm.js native.
if (fun->isNative()) { if (!IsInterpretedNonSelfHostedFunction(fun)) {
continue; continue;
} }
funScript = GetOrCreateFunctionScript(cx, fun); funScript = GetOrCreateFunctionScript(cx, fun);
@ -10318,7 +10322,7 @@ bool DebuggerObject::scriptGetter(JSContext* cx, unsigned argc, Value* vp) {
} }
RootedFunction fun(cx, &obj->as<JSFunction>()); RootedFunction fun(cx, &obj->as<JSFunction>());
if (!fun->isInterpreted()) { if (!IsInterpretedNonSelfHostedFunction(fun)) {
args.rval().setUndefined(); args.rval().setUndefined();
return true; return true;
} }
@ -10357,7 +10361,7 @@ bool DebuggerObject::environmentGetter(JSContext* cx, unsigned argc,
} }
RootedFunction fun(cx, &obj->as<JSFunction>()); RootedFunction fun(cx, &obj->as<JSFunction>());
if (!fun->isInterpreted()) { if (!IsInterpretedNonSelfHostedFunction(fun)) {
args.rval().setUndefined(); args.rval().setUndefined();
return true; return true;
} }
@ -11469,7 +11473,7 @@ bool DebuggerObject::getParameterNames(JSContext* cx,
if (!result.growBy(referent->nargs())) { if (!result.growBy(referent->nargs())) {
return false; return false;
} }
if (referent->isInterpreted()) { if (IsInterpretedNonSelfHostedFunction(referent)) {
RootedScript script(cx, GetOrCreateFunctionScript(cx, referent)); RootedScript script(cx, GetOrCreateFunctionScript(cx, referent));
if (!script) { if (!script) {
return false; return false;