From a12a67e4002789eff76997adfb31cc34e8836bdb Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Wed, 25 May 2005 03:40:24 +0000 Subject: [PATCH] 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 --- .../xpconnect/src/xpcwrappednativejsops.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/src/xpconnect/src/xpcwrappednativejsops.cpp b/js/src/xpconnect/src/xpcwrappednativejsops.cpp index a8df7b4135b..9099c11c887 100644 --- a/js/src/xpconnect/src/xpcwrappednativejsops.cpp +++ b/js/src/xpconnect/src/xpcwrappednativejsops.cpp @@ -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; }