Skip to content

Commit

Permalink
Bug 1652624 - Part 2: Avoid direct getPrivate usage on debugger child…
Browse files Browse the repository at this point in the history
…ren. r=arai

Calling `getPrivate` directly spreads implementation details of the Debugger
wrapper types across multiple files in a way that is ugly and complicates the
implementation. We can easily avoid that by making the existing referent
functions public.

Differential Revision: https://phabricator.services.mozilla.com/D83443
  • Loading branch information
loganfsmyth committed Jul 16, 2020
1 parent d1cbf77 commit f09b8d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions js/src/debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ bool Debugger::unwrapDebuggeeObject(JSContext* cx, MutableHandleObject obj) {
return false;
}

obj.set(static_cast<JSObject*>(ndobj->getPrivate()));
obj.set(ndobj->referent());
return true;
}

Expand Down Expand Up @@ -6009,12 +6009,12 @@ bool Debugger::CallData::adoptDebuggeeValue() {
RootedValue v(cx, args[0]);
if (v.isObject()) {
RootedObject obj(cx, &v.toObject());
NativeObject* ndobj = ToNativeDebuggerObject(cx, &obj);
DebuggerObject* ndobj = ToNativeDebuggerObject(cx, &obj);
if (!ndobj) {
return false;
}

obj.set(static_cast<JSObject*>(ndobj->getPrivate()));
obj.set(ndobj->referent());
v = ObjectValue(*obj);

if (!dbg->wrapDebuggeeValue(cx, &v)) {
Expand Down Expand Up @@ -6712,10 +6712,9 @@ bool Debugger::isDebuggerCrossCompartmentEdge(JSObject* obj,
} else if (obj->is<DebuggerSource>()) {
referent = obj->as<DebuggerSource>().getReferentRawObject();
} else if (obj->is<DebuggerObject>()) {
referent = static_cast<gc::Cell*>(obj->as<DebuggerObject>().getPrivate());
referent = obj->as<DebuggerObject>().referent();
} else if (obj->is<DebuggerEnvironment>()) {
referent =
static_cast<gc::Cell*>(obj->as<DebuggerEnvironment>().getPrivate());
referent = obj->as<DebuggerEnvironment>().referent();
}

return referent == target;
Expand Down
12 changes: 6 additions & 6 deletions js/src/debugger/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ class DebuggerEnvironment : public NativeObject {
bool isInstance() const;
Debugger* owner() const;

private:
static const JSClassOps classOps_;

static const JSPropertySpec properties_[];
static const JSFunctionSpec methods_[];

Env* referent() const {
Env* env = static_cast<Env*>(getPrivate());
MOZ_ASSERT(env);
return env;
}

private:
static const JSClassOps classOps_;

static const JSPropertySpec properties_[];
static const JSFunctionSpec methods_[];

bool requireDebuggee(JSContext* cx) const;

static MOZ_MUST_USE bool construct(JSContext* cx, unsigned argc, Value* vp);
Expand Down
12 changes: 6 additions & 6 deletions js/src/debugger/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ class DebuggerObject : public NativeObject {
bool isInstance() const;
Debugger* owner() const;

JSObject* referent() const {
JSObject* obj = (JSObject*)getPrivate();
MOZ_ASSERT(obj);
return obj;
}

private:
enum { OWNER_SLOT };

Expand All @@ -188,12 +194,6 @@ class DebuggerObject : public NativeObject {
static const JSPropertySpec promiseProperties_[];
static const JSFunctionSpec methods_[];

JSObject* referent() const {
JSObject* obj = (JSObject*)getPrivate();
MOZ_ASSERT(obj);
return obj;
}

PromiseObject* promise() const;

static MOZ_MUST_USE bool requireGlobal(JSContext* cx,
Expand Down

0 comments on commit f09b8d1

Please sign in to comment.