diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index da9c0e907eb0..331b80b9fe27 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -8662,6 +8662,9 @@ DebuggerObject_forceLexicalInitializationByName(JSContext *cx, unsigned argc, Va if (!args.requireAtLeast(cx, "Debugger.Object.prototype.forceLexicalInitializationByName", 1)) return false; + if (!DebuggerObject::requireGlobal(cx, object)) + return false; + RootedId id(cx); if (!ValueToIdentifier(cx, args[0], &id)) return false; @@ -8681,6 +8684,9 @@ DebuggerObject_executeInGlobal(JSContext* cx, unsigned argc, Value* vp) if (!args.requireAtLeast(cx, "Debugger.Object.prototype.executeInGlobal", 1)) return false; + if (!DebuggerObject::requireGlobal(cx, object)) + return false; + AutoStableStringChars stableChars(cx); if (!ValueToStableChars(cx, "Debugger.Object.prototype.executeInGlobal", args[0], stableChars)) @@ -8703,6 +8709,9 @@ DebuggerObject_executeInGlobalWithBindings(JSContext* cx, unsigned argc, Value* if (!args.requireAtLeast(cx, "Debugger.Object.prototype.executeInGlobalWithBindings", 2)) return false; + if (!DebuggerObject::requireGlobal(cx, object)) + return false; + AutoStableStringChars stableChars(cx); if (!ValueToStableChars(cx, "Debugger.Object.prototype.executeInGlobalWithBindings", args[0], stableChars)) @@ -8871,6 +8880,14 @@ DebuggerObject::isDebuggeeFunction(JSContext* cx, Handle object dbg->observesGlobal(&referent->as().global()); } +/* static */ bool +DebuggerObject::isGlobal(JSContext* cx, Handle object) +{ + RootedObject referent(cx, object->referent()); + + return referent->is(); +} + /* static */ bool DebuggerObject::className(JSContext* cx, Handle object, MutableHandleString result) @@ -9282,9 +9299,6 @@ DebuggerObject::call(JSContext* cx, Handle object, HandleValue DebuggerObject::forceLexicalInitializationByName(JSContext* cx, Handle object, HandleId id, bool& result) { - if (!DebuggerObject::requireGlobalObject(cx, object)) - return false; - if (!JSID_IS_STRING(id)) { JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE, "Debugger.Object.prototype.forceLexicalInitializationByName", @@ -9292,11 +9306,11 @@ DebuggerObject::forceLexicalInitializationByName(JSContext* cx, Handlereferent()); - - RootedObject globalLexical(cx, &referent->as().lexicalScope()); + Rooted referent(cx, &object->referent()->as()); + RootedObject globalLexical(cx, &referent->lexicalScope()); RootedObject pobj(cx); RootedShape shape(cx); if (!LookupProperty(cx, globalLexical, id, &pobj, &shape)) @@ -9319,14 +9333,12 @@ DebuggerObject::executeInGlobal(JSContext* cx, Handle object, mozilla::Range chars, HandleObject bindings, const EvalOptions& options, MutableHandleValue result) { - if (!DebuggerObject::requireGlobalObject(cx, object)) - return false; + MOZ_ASSERT(isGlobal(cx, object)); - RootedObject referent(cx, object->referent()); + Rooted referent(cx, &object->referent()->as()); Debugger* dbg = object->owner(); - RootedObject globalLexical(cx, &referent->as().lexicalScope()); - + RootedObject globalLexical(cx, &referent->lexicalScope()); return DebuggerGenericEval(cx, chars, bindings, options, result, dbg, globalLexical, nullptr); } @@ -9407,11 +9419,11 @@ DebuggerObject::unwrap(JSContext* cx, Handle object, } /* static */ bool -DebuggerObject::requireGlobalObject(JSContext* cx, Handle object) +DebuggerObject::requireGlobal(JSContext* cx, Handle object) { - RootedObject referent(cx, object->referent()); + if (!DebuggerObject::isGlobal(cx, object)) { + RootedObject referent(cx, object->referent()); - if (!referent->is()) { const char* isWrapper = ""; const char* isWindowProxy = ""; diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index 6b7fc37ec215..8d8a6874e25c 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -1053,6 +1053,7 @@ class DebuggerObject : public NativeObject static bool isFunction(JSContext* cx, Handle object); static bool isDebuggeeFunction(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); @@ -1101,6 +1102,8 @@ class DebuggerObject : public NativeObject static bool unwrap(JSContext* cx, Handle object, MutableHandle result); + static bool requireGlobal(JSContext* cx, Handle object); + private: enum { OWNER_SLOT @@ -1114,8 +1117,6 @@ class DebuggerObject : public NativeObject #endif // SPIDERMONKEY_PROMISE static const JSFunctionSpec methods_[]; - static bool requireGlobalObject(JSContext* cx, Handle object); - JSObject* referent() const { JSObject* obj = (JSObject*) getPrivate(); MOZ_ASSERT(obj);