Backout Bug 704259, a=bustage

This commit is contained in:
Olli Pettay 2012-03-08 16:44:32 +02:00
parent b13d39e0b9
commit df535ad6d4
3 changed files with 52 additions and 20 deletions

View File

@ -6467,10 +6467,23 @@ JS_ClearPendingException(JSContext *cx)
JS_PUBLIC_API(JSBool)
JS_ReportPendingException(JSContext *cx)
{
JSBool ok;
bool save;
AssertNoGC(cx);
CHECK_REQUEST(cx);
return js_ReportUncaughtException(cx);
/*
* Set cx->generatingError to suppress the standard error-to-exception
* conversion done by all {js,JS}_Report* functions except for OOM. The
* cx->generatingError flag was added to suppress recursive divergence
* under js_ErrorToException, but it serves for our purposes here too.
*/
save = cx->generatingError;
cx->generatingError = JS_TRUE;
ok = js_ReportUncaughtException(cx);
cx->generatingError = save;
return ok;
}
struct JSExceptionState {

View File

@ -830,11 +830,11 @@ struct JSContext : js::ContextFriendFields
bool hasVersionOverride;
/* Exception state -- the exception member is a GC root by definition. */
JSBool throwing; /* is there a pending exception? */
js::Value exception; /* most-recently-thrown exception */
JSBool throwing; /* is there a pending exception? */
js::Value exception; /* most-recently-thrown exception */
/* Per-context run options. */
unsigned runOptions; /* see jsapi.h for JSOPTION_* */
unsigned runOptions; /* see jsapi.h for JSOPTION_* */
public:
int32_t reportGranularity; /* see jsprobes.h */
@ -844,8 +844,11 @@ struct JSContext : js::ContextFriendFields
js::AutoResolving *resolvingList;
/* True if generating an error, to prevent runaway recursion. */
bool generatingError;
/*
* True if generating an error, to prevent runaway recursion.
* NB: generatingError packs with throwing below.
*/
bool generatingError;
/* GC heap compartment. */
JSCompartment *compartment;

View File

@ -1084,7 +1084,7 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
*/
JS_ASSERT(reportp);
if (JSREPORT_IS_WARNING(reportp->flags))
return false;
return JS_FALSE;
/* Find the exception index associated with this error. */
errorNumber = (JSErrNum) reportp->errorNumber;
@ -1107,12 +1107,19 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
* with the given error number.
*/
if (exn == JSEXN_NONE)
return false;
return JS_FALSE;
/* Prevent infinite recursion. */
/*
* Prevent runaway recursion, via cx->generatingError. If an out-of-memory
* error occurs, no exception object will be created, but we don't assume
* that OOM is the only kind of error that subroutines of this function
* called below might raise.
*/
if (cx->generatingError)
return false;
AutoScopedAssign<bool> asa(&cx->generatingError, false);
return JS_FALSE;
MUST_FLOW_THROUGH("out");
cx->generatingError = JS_TRUE;
/* Protect the newly-created strings below from nesting GCs. */
PodArrayZero(tv);
@ -1125,34 +1132,43 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
*/
ok = js_GetClassPrototype(cx, NULL, GetExceptionProtoKey(exn), &errProto);
if (!ok)
return false;
goto out;
tv[0] = OBJECT_TO_JSVAL(errProto);
errObject = NewObjectWithGivenProto(cx, &ErrorClass, errProto, NULL);
if (!errObject)
return false;
if (!errObject) {
ok = JS_FALSE;
goto out;
}
tv[1] = OBJECT_TO_JSVAL(errObject);
messageStr = JS_NewStringCopyZ(cx, message);
if (!messageStr)
return false;
if (!messageStr) {
ok = JS_FALSE;
goto out;
}
tv[2] = STRING_TO_JSVAL(messageStr);
filenameStr = JS_NewStringCopyZ(cx, reportp->filename);
if (!filenameStr)
return false;
if (!filenameStr) {
ok = JS_FALSE;
goto out;
}
tv[3] = STRING_TO_JSVAL(filenameStr);
ok = InitExnPrivate(cx, errObject, messageStr, filenameStr,
reportp->lineno, reportp, exn);
if (!ok)
return false;
goto out;
JS_SetPendingException(cx, OBJECT_TO_JSVAL(errObject));
/* Flag the error report passed in to indicate an exception was raised. */
reportp->flags |= JSREPORT_EXCEPTION;
return true;
out:
cx->generatingError = JS_FALSE;
return ok;
}
JSBool