mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 910823 - Factor out the code for casting from a JSClass* to an nsXBLJSClass* into a helper function. r=waldo
This commit is contained in:
parent
ddb5923fdc
commit
5dcee75fad
@ -76,7 +76,7 @@ XBLFinalize(JSFreeOp *fop, JSObject *obj)
|
||||
static_cast<nsXBLDocumentInfo*>(::JS_GetPrivate(obj));
|
||||
nsContentUtils::DeferredFinalize(docInfo);
|
||||
|
||||
nsXBLJSClass* c = static_cast<nsXBLJSClass*>(::JS_GetClass(obj));
|
||||
nsXBLJSClass* c = nsXBLJSClass::fromJSClass(::JS_GetClass(obj));
|
||||
c->Drop();
|
||||
}
|
||||
|
||||
@ -138,6 +138,19 @@ nsXBLJSClass::Destroy()
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsXBLJSClass*
|
||||
nsXBLService::getClass(const nsCString& k)
|
||||
{
|
||||
nsCStringKey key(k);
|
||||
return getClass(&key);
|
||||
}
|
||||
|
||||
nsXBLJSClass*
|
||||
nsXBLService::getClass(nsCStringKey *k)
|
||||
{
|
||||
return static_cast<nsXBLJSClass*>(nsXBLService::gClassTable->Get(k));
|
||||
}
|
||||
|
||||
// Implementation /////////////////////////////////////////////////////////////////
|
||||
|
||||
// Constructors/Destructors
|
||||
@ -926,9 +939,8 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> global,
|
||||
PR_snprintf(buf, sizeof(buf), " %llx", parent_proto_id.get());
|
||||
}
|
||||
xblKey.Append(buf);
|
||||
nsCStringKey key(xblKey);
|
||||
|
||||
c = static_cast<nsXBLJSClass*>(nsXBLService::gClassTable->Get(&key));
|
||||
c = nsXBLService::getClass(xblKey);
|
||||
if (c) {
|
||||
className.Assign(c->name);
|
||||
} else {
|
||||
@ -954,7 +966,7 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> global,
|
||||
|
||||
nsCStringKey key(xblKey);
|
||||
if (!c) {
|
||||
c = static_cast<nsXBLJSClass*>(nsXBLService::gClassTable->Get(&key));
|
||||
c = nsXBLService::getClass(&key);
|
||||
}
|
||||
if (c) {
|
||||
// If c is on the LRU list, remove it now!
|
||||
|
@ -61,7 +61,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
|
||||
MOZ_ASSERT(targetClassObject);
|
||||
|
||||
// Stash a strong reference to the JSClass in the binding.
|
||||
aBinding->SetJSClass(static_cast<nsXBLJSClass*>(JS_GetClass(targetClassObject)));
|
||||
aBinding->SetJSClass(nsXBLJSClass::fromJSClass(JS_GetClass(targetClassObject)));
|
||||
|
||||
// If the prototype already existed, we don't need to install anything. return early.
|
||||
if (!targetObjectIsNew)
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "js/Class.h" // nsXBLJSClass derives from JSClass
|
||||
#include "nsTArray.h"
|
||||
|
||||
class nsCStringKey;
|
||||
class nsXBLBinding;
|
||||
class nsXBLDocumentInfo;
|
||||
class nsXBLJSClass;
|
||||
@ -132,6 +133,10 @@ public:
|
||||
static bool gAllowDataURIs; // Whether we should allow data
|
||||
// urls in -moz-binding. Needed for
|
||||
// testing.
|
||||
|
||||
// Look up the class by key in gClassTable.
|
||||
static nsXBLJSClass *getClass(const nsCString &key);
|
||||
static nsXBLJSClass *getClass(nsCStringKey *key);
|
||||
};
|
||||
|
||||
class nsXBLJSClass : public mozilla::LinkedListElement<nsXBLJSClass>
|
||||
@ -156,6 +161,15 @@ public:
|
||||
nsrefcnt Drop() { return --mRefCnt ? mRefCnt : Destroy(); }
|
||||
nsrefcnt AddRef() { return Hold(); }
|
||||
nsrefcnt Release() { return Drop(); }
|
||||
|
||||
// Downcast from a pointer to JSClass to a pointer to nsXBLJSClass.
|
||||
static nsXBLJSClass*
|
||||
fromJSClass(JSClass* c)
|
||||
{
|
||||
nsXBLJSClass* x = static_cast<nsXBLJSClass*>(c);
|
||||
MOZ_ASSERT(nsXBLService::getClass(x->mKey) == x);
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user