From 829d111d40e100db1d25d8c280f0e1bbe7934cda Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 7 Jun 2016 14:03:26 +0200 Subject: [PATCH] Backed out changeset 448365b11e37 (bug 1271653) for bustage on a CLOSED TREE --- .../tests/debug/Object-isArrowFunction.js | 2 +- .../tests/debug/Object-script-lazy.js | 2 - js/src/jsapi.h | 1 - js/src/vm/Debugger.cpp | 131 ++++++------------ js/src/vm/Debugger.h | 7 +- 5 files changed, 47 insertions(+), 96 deletions(-) diff --git a/js/src/jit-test/tests/debug/Object-isArrowFunction.js b/js/src/jit-test/tests/debug/Object-isArrowFunction.js index 34c4a1de5972..e2cb288bd10b 100644 --- a/js/src/jit-test/tests/debug/Object-isArrowFunction.js +++ b/js/src/jit-test/tests/debug/Object-isArrowFunction.js @@ -15,7 +15,7 @@ checkIsArrow(true, '(a) => { bleh; }'); checkIsArrow(false, 'Object.getPrototypeOf(() => { })'); checkIsArrow(false, '(function () { })'); checkIsArrow(false, 'function f() { } f'); -checkIsArrow((void 0), '({})'); +checkIsArrow(false, '({})'); checkIsArrow(false, 'Math.atan2'); checkIsArrow(false, 'Function.prototype'); checkIsArrow(false, 'Function("")'); diff --git a/js/src/jit-test/tests/debug/Object-script-lazy.js b/js/src/jit-test/tests/debug/Object-script-lazy.js index b58dc38ad146..680d5267e16d 100644 --- a/js/src/jit-test/tests/debug/Object-script-lazy.js +++ b/js/src/jit-test/tests/debug/Object-script-lazy.js @@ -43,7 +43,6 @@ var hDO = g2w.getOwnPropertyDescriptor('h').value; assertEq(hDO.global, g2w); assertEq(hDO.unwrap().global === g2w, false); assertEq(hDO.unwrap().isBoundFunction, undefined); -assertEq(hDO.unwrap().isArrowFunction, undefined); assertEq(hDO.unwrap().boundTargetFunction, undefined); assertEq(hDO.unwrap().boundThis, undefined); assertEq(hDO.unwrap().boundArguments, undefined); @@ -53,7 +52,6 @@ dbg.addDebuggee(g1); assertEq(fDO.unwrap().script instanceof Debugger.Script, true); assertEq(gDO.unwrap().parameterNames instanceof Array, true); assertEq(hDO.unwrap().isBoundFunction, true); -assertEq(hDO.unwrap().isArrowFunction, false); assertEq(hDO.unwrap().boundTargetFunction, fDO.unwrap()); assertEq(hDO.unwrap().boundThis, gDO.unwrap()); assertEq(hDO.unwrap().boundArguments.length, 2); diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 4d833666bae4..66c8d7881955 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -222,7 +222,6 @@ typedef AutoVectorRooter AutoObjectVector; using ValueVector = JS::GCVector; using IdVector = JS::GCVector; using ScriptVector = JS::GCVector; -using StringVector = JS::GCVector; template class MOZ_RAII AutoHashMapRooter : protected AutoGCRooter diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index 8433a9cba5e3..331b80b9fe27 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -7898,9 +7898,8 @@ DebuggerObject_getClass(JSContext* cx, unsigned argc, Value* vp) static bool DebuggerObject_getCallable(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT(cx, argc, vp, "get callable", args, object) - - args.rval().setBoolean(DebuggerObject::isCallable(cx, object)); + THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get callable", args, refobj); + args.rval().setBoolean(refobj->isCallable()); return true; } @@ -7949,32 +7948,50 @@ DebuggerObject_getDisplayName(JSContext* cx, unsigned argc, Value* vp) static bool DebuggerObject_getParameterNames(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT(cx, argc, vp, "get parameterNames", args, object) - - if (!DebuggerObject::isDebuggeeFunction(cx, object)) { + THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get parameterNames", args, dbg, obj); + if (!obj->is()) { args.rval().setUndefined(); return true; } - Rooted names(cx, StringVector(cx)); - if (!DebuggerObject::parameterNames(cx, object, &names)) - return false; + RootedFunction fun(cx, &obj->as()); - RootedArrayObject obj(cx, NewDenseFullyAllocatedArray(cx, names.length())); - if (!obj) - return false; - - obj->ensureDenseInitializedLength(cx, 0, names.length()); - for (size_t i = 0; i < names.length(); ++i) { - Value v; - if (names[i]) - v = StringValue(names[i]); - else - v = UndefinedValue(); - obj->setDenseElement(i, v); + /* Only hand out parameter info for debuggee functions. */ + if (!dbg->observesGlobal(&fun->global())) { + args.rval().setUndefined(); + return true; } - args.rval().setObject(*obj); + RootedArrayObject result(cx, NewDenseFullyAllocatedArray(cx, fun->nargs())); + if (!result) + return false; + result->ensureDenseInitializedLength(cx, 0, fun->nargs()); + + if (fun->isInterpreted()) { + RootedScript script(cx, GetOrCreateFunctionScript(cx, fun)); + if (!script) + return false; + + MOZ_ASSERT(fun->nargs() == script->bindings.numArgs()); + + if (fun->nargs() > 0) { + BindingIter bi(script); + for (size_t i = 0; i < fun->nargs(); i++, bi++) { + MOZ_ASSERT(bi.argIndex() == i); + Value v; + if (bi->name()->length() == 0) + v = UndefinedValue(); + else + v = StringValue(bi->name()); + result->setDenseElement(i, v); + } + } + } else { + for (size_t i = 0; i < fun->nargs(); i++) + result->setDenseElement(i, UndefinedValue()); + } + + args.rval().setObject(*result); return true; } @@ -8044,14 +8061,10 @@ DebuggerObject_getEnvironment(JSContext* cx, unsigned argc, Value* vp) static bool DebuggerObject_getIsArrowFunction(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT(cx, argc, vp, "get isArrowFunction", args, object) + THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get isArrowFunction", args, refobj); - if (!DebuggerObject::isDebuggeeFunction(cx, object)) { - args.rval().setUndefined(); - return true; - } - - args.rval().setBoolean(DebuggerObject::isArrowFunction(cx, object)); + args.rval().setBoolean(refobj->is() + && refobj->as().isArrow()); return true; } @@ -8849,14 +8862,6 @@ DebuggerObject::create(JSContext* cx, HandleObject proto, HandleObject referent, return &object; } -/* static */ bool -DebuggerObject::isCallable(JSContext* cx, Handle object) -{ - RootedObject referent(cx, object->referent()); - - return referent->isCallable(); -} - /* static */ bool DebuggerObject::isFunction(JSContext* cx, Handle object) { @@ -8875,26 +8880,6 @@ DebuggerObject::isDebuggeeFunction(JSContext* cx, Handle object dbg->observesGlobal(&referent->as().global()); } -/* static */ bool -DebuggerObject::isBoundFunction(JSContext* cx, Handle object) -{ - MOZ_ASSERT(isDebuggeeFunction(cx, object)); - - RootedFunction referent(cx, &object->referent()->as()); - - return referent->isBoundFunction(); -} - -/* static */ bool -DebuggerObject::isArrowFunction(JSContext* cx, Handle object) -{ - MOZ_ASSERT(isDebuggeeFunction(cx, object)); - - RootedFunction referent(cx, &object->referent()->as()); - - return referent->isArrow(); -} - /* static */ bool DebuggerObject::isGlobal(JSContext* cx, Handle object) { @@ -8947,39 +8932,13 @@ DebuggerObject::displayName(JSContext* cx, Handle object, } /* static */ bool -DebuggerObject::parameterNames(JSContext* cx, Handle object, - MutableHandle result) +DebuggerObject::isBoundFunction(JSContext* cx, Handle object) { MOZ_ASSERT(isDebuggeeFunction(cx, object)); - RootedFunction referent(cx, &object->referent()->as()); + RootedObject referent(cx, object->referent()); - if (!result.growBy(referent->nargs())) - return false; - if (referent->isInterpreted()) { - RootedScript script(cx, GetOrCreateFunctionScript(cx, referent)); - if (!script) - return false; - - MOZ_ASSERT(referent->nargs() == script->bindings.numArgs()); - - if (referent->nargs() > 0) { - BindingIter bi(script); - for (size_t i = 0; i < referent->nargs(); i++, bi++) { - MOZ_ASSERT(bi.argIndex() == i); - Value v; - if (bi->name()->length() == 0) - result[i].set(nullptr); - else - result[i].set(bi->name()); - } - } - } else { - for (size_t i = 0; i < referent->nargs(); i++) - result[i].set(nullptr); - } - - return true; + return referent->isBoundFunction(); } /* static */ bool diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index fa273bd2bf84..8d8a6874e25c 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -1051,20 +1051,15 @@ class DebuggerObject : public NativeObject static DebuggerObject* create(JSContext* cx, HandleObject proto, HandleObject obj, HandleNativeObject debugger); - static bool isCallable(JSContext* cx, Handle object); static bool isFunction(JSContext* cx, Handle object); static bool isDebuggeeFunction(JSContext* cx, Handle object); - static bool isBoundFunction(JSContext* cx, Handle object); - static bool isArrowFunction(JSContext* cx, Handle object); static bool isGlobal(JSContext* cx, Handle object); static bool className(JSContext* cx, Handle object, MutableHandleString result); static bool name(JSContext* cx, Handle object, MutableHandleString result); static bool displayName(JSContext* cx, Handle object, MutableHandleString result); - - static bool parameterNames(JSContext* cx, Handle object, - MutableHandle result); + static bool isBoundFunction(JSContext* cx, Handle object); static bool boundTargetFunction(JSContext* cx, Handle object, MutableHandleObject result); static bool boundThis(JSContext* cx, Handle object,