Bug 812617 - Provide a JSBindingFinalized hook for the native classes using Web IDL bindings to know when their JS wrapper has been finalized; r=bzbarsky

--HG--
extra : rebase_source : bb5059a170f3c2f4aa977190fceea421b41b5e58
This commit is contained in:
Peter Van der Beken 2013-03-17 21:47:12 -04:00
parent a3fa501952
commit 5db19d4269
2 changed files with 21 additions and 1 deletions

View File

@ -1667,6 +1667,25 @@ bool
NativeToString(JSContext* cx, JSObject* wrapper, JSObject* obj, const char* pre, NativeToString(JSContext* cx, JSObject* wrapper, JSObject* obj, const char* pre,
const char* post, JS::Value* v); const char* post, JS::Value* v);
HAS_MEMBER(JSBindingFinalized)
template<class T, bool hasCallback=HasJSBindingFinalizedMember<T>::Value>
struct JSBindingFinalized
{
static void Finalized(T* self)
{
}
};
template<class T>
struct JSBindingFinalized<T, true>
{
static void Finalized(T* self)
{
self->JSBindingFinalized();
}
};
nsresult nsresult
ReparentWrapper(JSContext* aCx, JSObject* aObj); ReparentWrapper(JSContext* aCx, JSObject* aObj);

View File

@ -919,7 +919,8 @@ def finalizeHook(descriptor, hookName, context):
if descriptor.customFinalize: if descriptor.customFinalize:
finalize = "self->%s(%s);" % (hookName, context) finalize = "self->%s(%s);" % (hookName, context)
else: else:
finalize = "ClearWrapper(self, self);\n" if descriptor.wrapperCache else "" finalize = "JSBindingFinalized<%s>::Finalized(self);\n" % descriptor.nativeType
finalize += "ClearWrapper(self, self);\n" if descriptor.wrapperCache else ""
if descriptor.workers: if descriptor.workers:
finalize += "self->Release();" finalize += "self->Release();"
elif descriptor.nativeOwnership == 'nsisupports': elif descriptor.nativeOwnership == 'nsisupports':