Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 825392 - Infer the global from the reflector in DoInitJSClass. r=bz
Browse files Browse the repository at this point in the history
  • Loading branch information
bholley committed Mar 19, 2014
1 parent 287fa29 commit 8adb032
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
9 changes: 8 additions & 1 deletion dom/xbl/nsXBLBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ nsXBLBinding::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData)

// static
nsresult
nsXBLBinding::DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> global,
nsXBLBinding::DoInitJSClass(JSContext *cx,
JS::Handle<JSObject*> obj,
const nsAFlatCString& aClassName,
nsXBLPrototypeBinding* aProtoBinding,
Expand All @@ -930,6 +930,13 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> global,
nsAutoCString className(aClassName);
nsAutoCString xblKey(aClassName);

// Note that, now that NAC reflectors are created in the XBL scope, the
// reflector is not necessarily same-compartment with the document. So we'll
// end up creating a separate instance of the oddly-named XBL class object
// and defining it as a property on the XBL scope's global. This works fine,
// but we need to make sure never to assume that the the reflector and
// prototype are same-compartment with the bound document.
JS::RootedObject global(cx, js::GetGlobalForObjectCrossCompartment(obj));
JSAutoCompartment ac(cx, global);

JS::Rooted<JSObject*> parent_proto(cx, nullptr);
Expand Down
3 changes: 1 addition & 2 deletions dom/xbl/nsXBLBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ class nsXBLBinding MOZ_FINAL

void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData);

static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> global,
JS::Handle<JSObject*> obj,
static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj,
const nsAFlatCString& aClassName,
nsXBLPrototypeBinding* aProtoBinding,
JS::MutableHandle<JSObject*> aClassObject,
Expand Down
6 changes: 3 additions & 3 deletions dom/xbl/nsXBLProtoImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding,
// concrete base class. We need to alter the object so that our concrete class is interposed
// between the object and its base class. We become the new base class of the object, and the
// object's old base class becomes the new class' base class.
rv = aBinding->InitClass(mClassName, cx, global, value, aTargetClassObject, aTargetIsNew);
rv = aBinding->InitClass(mClassName, cx, value, aTargetClassObject, aTargetIsNew);
if (NS_FAILED(rv)) {
return rv;
}
Expand All @@ -211,7 +211,7 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)

JS::Rooted<JSObject*> classObject(cx);
bool classObjectIsNew = false;
nsresult rv = aBinding->InitClass(mClassName, cx, compilationGlobal, compilationGlobal,
nsresult rv = aBinding->InitClass(mClassName, cx, compilationGlobal,
&classObject, &classObjectIsNew);
if (NS_FAILED(rv))
return rv;
Expand Down Expand Up @@ -341,7 +341,7 @@ nsXBLProtoImpl::Read(nsIObjectInputStream* aStream,

JS::Rooted<JSObject*> classObject(cx);
bool classObjectIsNew = false;
nsresult rv = aBinding->InitClass(mClassName, cx, global, global, &classObject,
nsresult rv = aBinding->InitClass(mClassName, cx, global, &classObject,
&classObjectIsNew);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(classObject);
Expand Down
3 changes: 1 addition & 2 deletions dom/xbl/nsXBLPrototypeBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,11 @@ nsXBLPrototypeBinding::GetImmediateChild(nsIAtom* aTag)
nsresult
nsXBLPrototypeBinding::InitClass(const nsCString& aClassName,
JSContext * aContext,
JS::Handle<JSObject*> aGlobal,
JS::Handle<JSObject*> aScriptObject,
JS::MutableHandle<JSObject*> aClassObject,
bool* aNew)
{
return nsXBLBinding::DoInitJSClass(aContext, aGlobal, aScriptObject,
return nsXBLBinding::DoInitJSClass(aContext, aScriptObject,
aClassName, this, aClassObject, aNew);
}

Expand Down
1 change: 0 additions & 1 deletion dom/xbl/nsXBLPrototypeBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class nsXBLPrototypeBinding MOZ_FINAL
}

nsresult InitClass(const nsCString& aClassName, JSContext * aContext,
JS::Handle<JSObject*> aGlobal,
JS::Handle<JSObject*> aScriptObject,
JS::MutableHandle<JSObject*> aClassObject,
bool* aNew);
Expand Down

0 comments on commit 8adb032

Please sign in to comment.