From 3ffbd13c273f034225b2d5de5964c629b607d13e Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Wed, 1 Jun 2005 19:26:24 +0000 Subject: [PATCH] Log creation of XPCNativeWrapper and XPCWrappedNative objects if DEBUG_XPCNativeWrapper is defined. Bug 295435, r+sr=jst, a=shaver. --- js/src/xpconnect/src/XPCNativeWrapper.cpp | 31 +++++++++++++++++++++++ js/src/xpconnect/src/xpcwrappednative.cpp | 20 ++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/js/src/xpconnect/src/XPCNativeWrapper.cpp b/js/src/xpconnect/src/XPCNativeWrapper.cpp index 005cf8198354..f18d43f4ce48 100644 --- a/js/src/xpconnect/src/XPCNativeWrapper.cpp +++ b/js/src/xpconnect/src/XPCNativeWrapper.cpp @@ -944,6 +944,21 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_FALSE; } +#ifdef DEBUG_XPCNativeWrapper + { + XPCCallContext ccx(JS_CALLER, cx); + + // Keep wrapperObj alive while we mess with strings + AUTO_MARK_JSVAL(ccx, OBJECT_TO_JSVAL(wrapperObj)); + + char *s = wrappedNative->ToString(ccx); + printf("Created new XPCNativeWrapper %p for wrapped native %s\n", + (void*)wrapperObj, s); + if (s) + JS_smprintf_free(s); + } +#endif + *rval = OBJECT_TO_JSVAL(wrapperObj); { @@ -1152,6 +1167,22 @@ XPCNativeWrapper::GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper) } wrapper->SetNativeWrapper(obj); + +#ifdef DEBUG_XPCNativeWrapper + { + XPCCallContext ccx(NATIVE_CALLER, cx); + + // Keep obj alive while we mess with strings + AUTO_MARK_JSVAL(ccx, OBJECT_TO_JSVAL(obj)); + + char *s = wrapper->ToString(ccx); + printf("Created new XPCNativeWrapper %p for wrapped native %s\n", + (void*)obj, s); + if (s) + JS_smprintf_free(s); + } +#endif + return obj; } diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp index b7960b591f66..5327361ed1fa 100644 --- a/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/js/src/xpconnect/src/xpcwrappednative.cpp @@ -402,6 +402,17 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx, return rv; } +#if DEBUG_XPCNativeWrapper + { + char* s = wrapper->ToString(ccx); + NS_ASSERTION(wrapper->GetFlatJSObject(), "eh?"); + printf("Created wrapped native %s, flat JSObject is %p\n", + s, (void*)wrapper->GetFlatJSObject()); + if (s) + JS_smprintf_free(s); + } +#endif + // Redundant wrapper must be killed outside of the map lock. XPCWrappedNative* wrapperToKill = nsnull; @@ -2462,9 +2473,11 @@ XPCWrappedNative::ToString(XPCCallContext& ccx, { #ifdef DEBUG # define FMT_ADDR " @ 0x%p" +# define FMT_STR(str) str # define PARAM_ADDR(w) , w #else # define FMT_ADDR "" +# define FMT_STR(str) # define PARAM_ADDR(w) #endif @@ -2510,12 +2523,13 @@ XPCWrappedNative::ToString(XPCCallContext& ccx, { return nsnull; } - const char* fmt = "[xpconnect wrapped %s" FMT_ADDR "]"; + const char* fmt = "[xpconnect wrapped %s" FMT_ADDR FMT_STR(" (native") + FMT_ADDR FMT_STR(")") "]"; if(si) { - fmt = "[object %s" FMT_ADDR "]"; + fmt = "[object %s" FMT_ADDR FMT_STR(" (native") FMT_ADDR FMT_STR(")") "]"; } - sz = JS_smprintf(fmt, name PARAM_ADDR(this)); + sz = JS_smprintf(fmt, name PARAM_ADDR(this) PARAM_ADDR(mIdentity)); JS_smprintf_free(name);