bug 121178, r=jst,sr=brendan, "jsdIStackFrame::eval signature needs to be changed"

return exception from jsdService::Eval if one occurs.
This commit is contained in:
rginda%netscape.com 2002-01-29 06:15:58 +00:00
parent ecdf07d4a4
commit 33fccb8187
6 changed files with 108 additions and 28 deletions

View File

@ -569,12 +569,9 @@ interface jsdIStackFrame : jsdIEphemeral
* @param line Starting line number for this script. One based.
* @retval Result of evaluating the script.
*/
jsdIValue eval (in AString bytes, in string fileName,
in unsigned long line);
/*
boolean eval (in AString bytes, in string fileName,
in unsigned long line, out result);
*/
in unsigned long line, out jsdIValue result);
};
/**

View File

@ -637,14 +637,15 @@ jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
JSDStackFrameInfo* jsdframe,
const jschar *bytes, uintN length,
const char *filename, uintN lineno,
jsval *rval);
JSBool eatExceptions, jsval *rval);
extern JSBool
jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const char *bytes, uintN length,
const char *filename, uintN lineno, jsval *rval);
const char *filename, uintN lineno,
JSBool eatExceptions, jsval *rval);
extern JSString*
jsd_ValToStringInStackFrame(JSDContext* jsdc,

View File

@ -323,7 +323,8 @@ jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const jschar *bytes, uintN length,
const char *filename, uintN lineno, jsval *rval)
const char *filename, uintN lineno,
JSBool eatExceptions, jsval *rval)
{
JSBool retval;
JSBool valid;
@ -342,11 +343,14 @@ jsd_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
cx = jsdthreadstate->context;
JS_ASSERT(cx);
if (eatExceptions)
exceptionState = JS_SaveExceptionState(cx);
JS_ClearPendingException(cx);
jsd_StartingEvalUsingFilename(jsdc, filename);
retval = JS_EvaluateUCInStackFrame(cx, jsdframe->fp, bytes, length,
filename, lineno, rval);
jsd_FinishedEvalUsingFilename(jsdc, filename);
if (eatExceptions)
JS_RestoreExceptionState(cx, exceptionState);
return retval;
@ -357,7 +361,8 @@ jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const char *bytes, uintN length,
const char *filename, uintN lineno, jsval *rval)
const char *filename, uintN lineno,
JSBool eatExceptions, jsval *rval)
{
JSBool retval;
JSBool valid;
@ -376,11 +381,14 @@ jsd_EvaluateScriptInStackFrame(JSDContext* jsdc,
cx = jsdthreadstate->context;
JS_ASSERT(cx);
if (eatExceptions)
exceptionState = JS_SaveExceptionState(cx);
JS_ClearPendingException(cx);
jsd_StartingEvalUsingFilename(jsdc, filename);
retval = JS_EvaluateInStackFrame(cx, jsdframe->fp, bytes, length,
filename, lineno, rval);
jsd_FinishedEvalUsingFilename(jsdc, filename);
if (eatExceptions)
JS_RestoreExceptionState(cx, exceptionState);
return retval;

View File

@ -1387,26 +1387,42 @@ jsdStackFrame::GetThisValue(jsdIValue **_rval)
NS_IMETHODIMP
jsdStackFrame::Eval (const nsAReadableString &bytes, const char *fileName,
PRUint32 line, jsdIValue **_rval)
PRUint32 line, jsdIValue **result, PRBool *_rval)
{
ASSERT_VALID_FRAME;
jsval jv;
const nsSharedBufferHandle<PRUnichar> *h = bytes.GetSharedBufferHandle();
const jschar *char_bytes = NS_REINTERPRET_CAST(const jschar *,
h->DataStart());
JSExceptionState *estate = 0;
jsval jv;
if (!JSD_EvaluateUCScriptInStackFrame (mCx, mThreadState, mStackFrameInfo,
char_bytes, bytes.Length(), fileName,
line, &jv))
return NS_ERROR_FAILURE;
JSContext *cx = JSD_GetJSContext (mCx, mThreadState);
estate = JS_SaveExceptionState (cx);
JS_ClearPendingException (cx);
*_rval = JSD_AttemptUCScriptInStackFrame (mCx, mThreadState,
mStackFrameInfo,
char_bytes, bytes.Length(),
fileName, line, &jv);
if (!*_rval) {
if (JS_IsExceptionPending(cx))
JS_GetPendingException (cx, &jv);
else
jv = 0;
}
JS_RestoreExceptionState (cx, estate);
if (jv) {
JSDValue *jsdv = JSD_NewValue (mCx, jv);
if (!jsdv)
return NS_ERROR_FAILURE;
*_rval = jsdValue::FromPtr (mCx, jsdv);
if (!*_rval)
*result = jsdValue::FromPtr (mCx, jsdv);
if (!*result)
return NS_ERROR_FAILURE;
} else {
*result = 0;
}
return NS_OK;
}

View File

@ -638,7 +638,26 @@ JSD_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
return jsd_EvaluateUCScriptInStackFrame(jsdc, jsdthreadstate,jsdframe,
bytes, length, filename, lineno,
rval);
JS_TRUE, rval);
}
JSD_PUBLIC_API(JSBool)
JSD_AttemptUCScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const jschar *bytes, uintN length,
const char *filename, uintN lineno,
jsval *rval)
{
JSD_ASSERT_VALID_CONTEXT(jsdc);
JS_ASSERT(bytes);
JS_ASSERT(length);
JS_ASSERT(filename);
JS_ASSERT(rval);
return jsd_EvaluateUCScriptInStackFrame(jsdc, jsdthreadstate,jsdframe,
bytes, length, filename, lineno,
JS_FALSE, rval);
}
JSD_PUBLIC_API(JSBool)
@ -656,7 +675,25 @@ JSD_EvaluateScriptInStackFrame(JSDContext* jsdc,
return jsd_EvaluateScriptInStackFrame(jsdc, jsdthreadstate,jsdframe,
bytes, length,
filename, lineno, rval);
filename, lineno, JS_TRUE, rval);
}
JSD_PUBLIC_API(JSBool)
JSD_AttemptScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const char *bytes, uintN length,
const char *filename, uintN lineno, jsval *rval)
{
JSD_ASSERT_VALID_CONTEXT(jsdc);
JS_ASSERT(bytes);
JS_ASSERT(length);
JS_ASSERT(filename);
JS_ASSERT(rval);
return jsd_EvaluateScriptInStackFrame(jsdc, jsdthreadstate,jsdframe,
bytes, length,
filename, lineno, JS_FALSE, rval);
}
JSD_PUBLIC_API(JSString*)

View File

@ -806,6 +806,17 @@ JSD_EvaluateUCScriptInStackFrame(JSDContext* jsdc,
const char *filename, uintN lineno,
jsval *rval);
/*
* Same as above, but does not eat exceptions.
*/
extern JSD_PUBLIC_API(JSBool)
JSD_AttemptUCScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const jschar *bytes, uintN length,
const char *filename, uintN lineno,
jsval *rval);
/* single byte character version of JSD_EvaluateUCScriptInStackFrame */
extern JSD_PUBLIC_API(JSBool)
JSD_EvaluateScriptInStackFrame(JSDContext* jsdc,
@ -814,6 +825,16 @@ JSD_EvaluateScriptInStackFrame(JSDContext* jsdc,
const char *bytes, uintN length,
const char *filename, uintN lineno, jsval *rval);
/*
* Same as above, but does not eat exceptions.
*/
extern JSD_PUBLIC_API(JSBool)
JSD_AttemptScriptInStackFrame(JSDContext* jsdc,
JSDThreadState* jsdthreadstate,
JSDStackFrameInfo* jsdframe,
const char *bytes, uintN length,
const char *filename, uintN lineno, jsval *rval);
/*
* Convert the given jsval to a string
* NOTE: The ErrorReporter hook might be called if this fails.