Skip to content

Commit

Permalink
Bug 1719795 part 1 - Add a helper function for getting a SimpleGlobal…
Browse files Browse the repository at this point in the history
…Object's native global. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D119498
  • Loading branch information
jandem committed Jul 13, 2021
1 parent bba712b commit bd35512
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dom/bindings/SimpleGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SimpleGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
NS_INTERFACE_MAP_END

static SimpleGlobalObject* GetSimpleGlobal(JSObject* global);

static void SimpleGlobal_finalize(JSFreeOp* fop, JSObject* obj) {
auto* globalObject = static_cast<SimpleGlobalObject*>(JS::GetPrivate(obj));
SimpleGlobalObject* globalObject = GetSimpleGlobal(obj);
if (globalObject) {
globalObject->ClearWrapper(obj);
NS_RELEASE(globalObject);
}
}

static size_t SimpleGlobal_moved(JSObject* obj, JSObject* old) {
auto* globalObject = static_cast<SimpleGlobalObject*>(JS::GetPrivate(obj));
SimpleGlobalObject* globalObject = GetSimpleGlobal(obj);
if (globalObject) {
globalObject->UpdateWrapper(obj, old);
}
Expand Down Expand Up @@ -83,6 +85,12 @@ const JSClass SimpleGlobalClass = {"",
&SimpleGlobalClassExtension,
JS_NULL_OBJECT_OPS};

static SimpleGlobalObject* GetSimpleGlobal(JSObject* global) {
MOZ_ASSERT(JS::GetClass(global) == &SimpleGlobalClass);

return static_cast<SimpleGlobalObject*>(JS::GetPrivate(global));
}

// static
JSObject* SimpleGlobalObject::Create(GlobalType globalType,
JS::Handle<JS::Value> proto) {
Expand Down Expand Up @@ -162,7 +170,7 @@ SimpleGlobalObject::GlobalType SimpleGlobalObject::SimpleGlobalType(
return SimpleGlobalObject::GlobalType::NotSimpleGlobal;
}

auto* globalObject = static_cast<SimpleGlobalObject*>(JS::GetPrivate(obj));
SimpleGlobalObject* globalObject = GetSimpleGlobal(obj);
return globalObject->Type();
}

Expand Down

0 comments on commit bd35512

Please sign in to comment.