More fixes for leak bug 294893. Make sure to clear the scope of the native wrapper when a wrapped native's scope is cleared. r+sr=bzbarsky@mit.edu, a=drivers

This commit is contained in:
jst%mozilla.jstenback.com 2005-05-25 03:40:24 +00:00
Родитель 1839183615
Коммит 4095b0c95f
1 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -1139,6 +1139,25 @@ XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
return js_ObjectOps.enumerate(cx, obj, enum_op, statep, idp);
}
JS_STATIC_DLL_CALLBACK(void)
XPC_WN_JSOp_Clear(JSContext *cx, JSObject *obj)
{
// If our scope is cleared, make sure we clear the scope of our
// native wrapper as well.
XPCWrappedNative *wrapper =
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj);
if(wrapper && wrapper->IsValid())
{
JSObject *nativeWrapper = wrapper->GetNativeWrapper();
if(nativeWrapper)
JS_ClearScope(cx, nativeWrapper);
}
js_ObjectOps.clear(cx, obj);
}
JSObjectOps * JS_DLL_CALLBACK
XPC_WN_GetObjectOpsNoCall(JSContext *cx, JSClass *clazz)
{
@ -1160,9 +1179,11 @@ JSBool xpc_InitWrappedNativeJSOps()
memcpy(&XPC_WN_WithCall_JSOps, &js_ObjectOps, sizeof(JSObjectOps));
XPC_WN_WithCall_JSOps.enumerate = XPC_WN_JSOp_Enumerate;
XPC_WN_WithCall_JSOps.clear = XPC_WN_JSOp_Clear;
XPC_WN_NoCall_JSOps.call = nsnull;
XPC_WN_NoCall_JSOps.construct = nsnull;
XPC_WN_NoCall_JSOps.clear = XPC_WN_JSOp_Clear;
}
return JS_TRUE;
}