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
This commit is contained in:
rginda%netscape.com 2002-02-07 00:59:55 +00:00
parent 9c46c55eb3
commit 7fccaa5b34
2 changed files with 106 additions and 3 deletions

View File

@ -152,6 +152,12 @@ interface jsdIDebuggerService : nsISupports
*/ */
void off (); 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 * Temporarily disable the debugger. Hooks will not be called while the
* debugger is paused. Multiple calls to pause will increase the "pause * debugger is paused. Multiple calls to pause will increase the "pause
@ -249,6 +255,14 @@ interface jsdIDebuggerService : nsISupports
* Clear all breakpoints in all scripts. * Clear all breakpoints in all scripts.
*/ */
void clearAllBreakpoints (); 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 /* XXX these two routines are candidates for refactoring. The only problem
* is that it is not clear where and how they should land. * 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 * The jsdIService caches this value internally, to if it changes you must
* swap the filter with itself using jsdIService::swapFilters. * swap the filter with itself using jsdIService::swapFilters.
*/ */
attribute nsISupports glob; attribute nsISupports globalObject;
/** /**
* String representing the url pattern to be filtered. Supports limited * String representing the url pattern to be filtered. Supports limited
@ -860,6 +874,15 @@ interface jsdIValue : jsdIEphemeral
* the jsdIValue with the underlying structure. * the jsdIValue with the underlying structure.
*/ */
void refresh(); 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();
}; };
/** /**

View File

@ -256,7 +256,7 @@ jsds_SyncFilter (FilterRecord *rec, jsdIFilter *filter)
JSObject *glob_proper = nsnull; JSObject *glob_proper = nsnull;
nsCOMPtr<nsISupports> glob; nsCOMPtr<nsISupports> glob;
nsresult rv = filter->GetGlob(getter_AddRefs(glob)); nsresult rv = filter->GetGlobalObject(getter_AddRefs(glob));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return PR_FALSE; return PR_FALSE;
if (glob) { if (glob) {
@ -634,7 +634,15 @@ jsds_ExecutionHookProc (JSDContext* jsdc, JSDThreadState* jsdthreadstate,
gJsds->GetDebuggerHook(getter_AddRefs(hook)); gJsds->GetDebuggerHook(getter_AddRefs(hook));
break; break;
case JSD_HOOK_BREAKPOINT: 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; break;
case JSD_HOOK_THROW: case JSD_HOOK_THROW:
{ {
@ -1932,6 +1940,34 @@ jsdValue::Refresh()
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
jsdValue::GetWrappedValue()
{
ASSERT_VALID_EPHEMERAL;
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
if (!xpc)
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIXPCNativeCallContext> 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 * debugger service implementation
******************************************************************************/ ******************************************************************************/
@ -2184,6 +2220,14 @@ jsdService::Off (void)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
jsdService::GetPauseDepth(PRUint32 *_rval)
{
NS_ENSURE_ARG_POINTER(_rval);
*_rval = mPauseLevel;
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
jsdService::Pause(PRUint32 *_rval) jsdService::Pause(PRUint32 *_rval)
{ {
@ -2469,6 +2513,42 @@ jsdService::ClearAllBreakpoints (void)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
jsdService::WrapValue(jsdIValue **_rval)
{
ASSERT_VALID_CONTEXT;
nsCOMPtr<nsIXPConnect> xpc = do_GetService (nsIXPConnect::GetCID());
if (!xpc)
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIXPCNativeCallContext> 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 NS_IMETHODIMP
jsdService::EnterNestedEventLoop (jsdINestCallback *callback, PRUint32 *_rval) jsdService::EnterNestedEventLoop (jsdINestCallback *callback, PRUint32 *_rval)
{ {