From 7fccaa5b34b0b406e6a6895fa7be346f6cfe4410 Mon Sep 17 00:00:00 2001 From: "rginda%netscape.com" Date: Thu, 7 Feb 2002 00:59:55 +0000 Subject: [PATCH] bug 121039, "Need a way to unwrap jsdIValues", r=jband, sr=jst adds jsdIValue::getWrappedValue() and jsdIService::wrapValue() methods to provid e js scripts a way to convert between jsdIValues and "real" js values. Also includes fix to not call breakpoint hook while paused, and changes jsdIFilt er::glob attribute to jsdIFilter::globalObject, to match jsdIContext::globalObject --- js/jsd/idl/jsdIDebuggerService.idl | 25 ++++++++- js/jsd/jsd_xpc.cpp | 84 +++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/js/jsd/idl/jsdIDebuggerService.idl b/js/jsd/idl/jsdIDebuggerService.idl index 44a8597c0fc6..cafa4a6a7efe 100644 --- a/js/jsd/idl/jsdIDebuggerService.idl +++ b/js/jsd/idl/jsdIDebuggerService.idl @@ -152,6 +152,12 @@ interface jsdIDebuggerService : nsISupports */ void off (); + /** + * Peek at the current pause depth of the debugger. + * + * @return depth Number of pause() calls still waiting to be unPause()d. + */ + readonly attribute unsigned long pauseDepth; /** * Temporarily disable the debugger. Hooks will not be called while the * debugger is paused. Multiple calls to pause will increase the "pause @@ -249,6 +255,14 @@ interface jsdIDebuggerService : nsISupports * Clear all breakpoints in all scripts. */ void clearAllBreakpoints (); + + /** + * When called from JavaScript, this method returns the jsdIValue wrapper + * for the given value. If a wrapper does not exist one will be created. + * When called from another language this method returns an xpconnect + * defined error code. + */ + jsdIValue wrapValue (/*in jsvalue value*/); /* XXX these two routines are candidates for refactoring. The only problem * is that it is not clear where and how they should land. @@ -312,7 +326,7 @@ interface jsdIFilter : nsISupports * The jsdIService caches this value internally, to if it changes you must * swap the filter with itself using jsdIService::swapFilters. */ - attribute nsISupports glob; + attribute nsISupports globalObject; /** * String representing the url pattern to be filtered. Supports limited @@ -860,6 +874,15 @@ interface jsdIValue : jsdIEphemeral * the jsdIValue with the underlying structure. */ void refresh(); + + /** + * When called from JavaScript, this method returns the JavaScript value + * wrapped by this jsdIValue. The calling script is free to use the result + * as it would any other JavaScript value. + * When called from another language this method returns an xpconnect + * defined error code. + */ + void getWrappedValue(); }; /** diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp index 250f4953715f..897ec6ce8c2b 100644 --- a/js/jsd/jsd_xpc.cpp +++ b/js/jsd/jsd_xpc.cpp @@ -256,7 +256,7 @@ jsds_SyncFilter (FilterRecord *rec, jsdIFilter *filter) JSObject *glob_proper = nsnull; nsCOMPtr glob; - nsresult rv = filter->GetGlob(getter_AddRefs(glob)); + nsresult rv = filter->GetGlobalObject(getter_AddRefs(glob)); if (NS_FAILED(rv)) return PR_FALSE; if (glob) { @@ -634,7 +634,15 @@ jsds_ExecutionHookProc (JSDContext* jsdc, JSDThreadState* jsdthreadstate, gJsds->GetDebuggerHook(getter_AddRefs(hook)); break; case JSD_HOOK_BREAKPOINT: - gJsds->GetBreakpointHook(getter_AddRefs(hook)); + { + /* we can't pause breakpoints the way we pause the other + * execution hooks (at least, not easily.) Instead we bail + * here if the service is paused. */ + PRUint32 level; + gJsds->GetPauseDepth(&level); + if (!level) + gJsds->GetBreakpointHook(getter_AddRefs(hook)); + } break; case JSD_HOOK_THROW: { @@ -1932,6 +1940,34 @@ jsdValue::Refresh() return NS_OK; } +NS_IMETHODIMP +jsdValue::GetWrappedValue() +{ + ASSERT_VALID_EPHEMERAL; + nsCOMPtr xpc = do_GetService(nsIXPConnect::GetCID()); + if (!xpc) + return NS_ERROR_FAILURE; + + nsresult rv; + nsCOMPtr cc; + rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc)); + if (NS_FAILED(rv)) + return rv; + + jsval *result; + rv = cc->GetRetValPtr(&result); + if (NS_FAILED(rv)) + return rv; + + if (result) + { + *result = JSD_GetValueWrappedJSVal (mCx, mValue); + cc->SetReturnValueWasSet(PR_TRUE); + } + + return NS_OK; +} + /****************************************************************************** * debugger service implementation ******************************************************************************/ @@ -2184,6 +2220,14 @@ jsdService::Off (void) return NS_OK; } +NS_IMETHODIMP +jsdService::GetPauseDepth(PRUint32 *_rval) +{ + NS_ENSURE_ARG_POINTER(_rval); + *_rval = mPauseLevel; + return NS_OK; +} + NS_IMETHODIMP jsdService::Pause(PRUint32 *_rval) { @@ -2469,6 +2513,42 @@ jsdService::ClearAllBreakpoints (void) return NS_OK; } +NS_IMETHODIMP +jsdService::WrapValue(jsdIValue **_rval) +{ + ASSERT_VALID_CONTEXT; + + nsCOMPtr xpc = do_GetService (nsIXPConnect::GetCID()); + if (!xpc) + return NS_ERROR_FAILURE; + + nsresult rv; + nsCOMPtr cc; + rv = xpc->GetCurrentNativeCallContext (getter_AddRefs(cc)); + if (NS_FAILED(rv)) + return rv; + + PRUint32 argc; + rv = cc->GetArgc (&argc); + if (NS_FAILED(rv)) + return rv; + if (argc < 1) + return NS_ERROR_INVALID_ARG; + + jsval *argv; + rv = cc->GetArgvPtr (&argv); + if (NS_FAILED(rv)) + return rv; + + JSDValue *jsdv = JSD_NewValue (mCx, argv[0]); + if (!jsdv) + return NS_ERROR_FAILURE; + + *_rval = jsdValue::FromPtr (mCx, jsdv); + return NS_OK; +} + + NS_IMETHODIMP jsdService::EnterNestedEventLoop (jsdINestCallback *callback, PRUint32 *_rval) {