diff --git a/js/src/debugger/Debugger-inl.h b/js/src/debugger/Debugger-inl.h index 5b0fafb8ad77..ad12ea2f9a01 100644 --- a/js/src/debugger/Debugger-inl.h +++ b/js/src/debugger/Debugger-inl.h @@ -17,7 +17,8 @@ /* static */ inline js::Debugger* js::Debugger::fromJSObject( const JSObject* obj) { MOZ_ASSERT(obj->is()); - return (Debugger*)obj->as().getPrivate(); + auto* dbg = &obj->as(); + return dbg->maybePtrFromReservedSlot(JSSLOT_DEBUG_DEBUGGER); } inline bool js::Debugger::isHookCallAllowed(JSContext* cx) const { diff --git a/js/src/debugger/Debugger.cpp b/js/src/debugger/Debugger.cpp index 47fe0b60dd1a..879eafd0f9d4 100644 --- a/js/src/debugger/Debugger.cpp +++ b/js/src/debugger/Debugger.cpp @@ -4015,9 +4015,7 @@ const JSClassOps DebuggerInstanceObject::classOps_ = { }; const JSClass DebuggerInstanceObject::class_ = { - "Debugger", - JSCLASS_HAS_PRIVATE | - JSCLASS_HAS_RESERVED_SLOTS(Debugger::JSSLOT_DEBUG_COUNT), + "Debugger", JSCLASS_HAS_RESERVED_SLOTS(Debugger::JSSLOT_DEBUG_COUNT), &classOps_}; static Debugger* Debugger_fromThisValue(JSContext* cx, const CallArgs& args, @@ -4635,7 +4633,7 @@ bool Debugger::construct(JSContext* cx, unsigned argc, Value* vp) { // The object owns the released pointer. debugger = dbg.release(); - InitObjectPrivate(obj, debugger, MemoryUse::Debugger); + InitReservedSlot(obj, JSSLOT_DEBUG_DEBUGGER, debugger, MemoryUse::Debugger); } // Add the initial debuggees, if any. diff --git a/js/src/debugger/Debugger.h b/js/src/debugger/Debugger.h index bc89e4bfb18f..c90eb564dbf6 100644 --- a/js/src/debugger/Debugger.h +++ b/js/src/debugger/Debugger.h @@ -541,6 +541,7 @@ class Debugger : private mozilla::LinkedListElement { HookCount }; enum { + JSSLOT_DEBUG_DEBUGGER, JSSLOT_DEBUG_PROTO_START, JSSLOT_DEBUG_FRAME_PROTO = JSSLOT_DEBUG_PROTO_START, JSSLOT_DEBUG_ENV_PROTO, diff --git a/js/src/vm/NativeObject.h b/js/src/vm/NativeObject.h index 5c12cd860ec6..db541e4ea7a7 100644 --- a/js/src/vm/NativeObject.h +++ b/js/src/vm/NativeObject.h @@ -1179,6 +1179,12 @@ class NativeObject : public JSObject { fixedSlots()[slot].init(this, HeapSlot::Slot, slot, value); } + template + T* maybePtrFromReservedSlot(uint32_t slot) const { + Value v = getReservedSlot(slot); + return v.isUndefined() ? nullptr : static_cast(v.toPrivate()); + } + /* * Calculate the number of dynamic slots to allocate to cover the properties * in an object with the given number of fixed slots and slot span.