Bug 989183 - Check for nsXBLJSClass. r=bz

This commit is contained in:
Bobby Holley 2014-04-01 21:34:34 -03:00
parent ff8c36d435
commit 02270e76f1
2 changed files with 10 additions and 1 deletions

View File

@ -114,6 +114,12 @@ nsXBLJSClass::nsXBLJSClass(const nsAFlatCString& aClassName,
finalize = XBLFinalize;
}
bool
nsXBLJSClass::IsXBLJSClass(const JSClass* aClass)
{
return aClass->finalize == XBLFinalize;
}
nsrefcnt
nsXBLJSClass::Destroy()
{
@ -988,7 +994,7 @@ nsXBLBinding::DoInitJSClass(JSContext *cx,
if (!::JS_LookupPropertyWithFlags(cx, global, className.get(), 0, &val))
return NS_ERROR_OUT_OF_MEMORY;
if (val.isObject()) {
if (val.isObject() && nsXBLJSClass::IsXBLJSClass(JS_GetClass(&val.toObject()))) {
*aNew = false;
proto = &val.toObject();
} else {

View File

@ -161,6 +161,8 @@ public:
nsrefcnt AddRef() { return Hold(); }
nsrefcnt Release() { return Drop(); }
static bool IsXBLJSClass(const JSClass* aClass);
// Downcast from a pointer to const JSClass to a pointer to non-const
// nsXBLJSClass.
//
@ -173,6 +175,7 @@ public:
static nsXBLJSClass*
fromJSClass(const JSClass* c)
{
MOZ_ASSERT(IsXBLJSClass(c));
nsXBLJSClass* x = const_cast<nsXBLJSClass*>(static_cast<const nsXBLJSClass*>(c));
MOZ_ASSERT(nsXBLService::getClass(x->mKey) == x);
return x;