Bug 461917. Do a better job of reporting pending exceptions when compiling an event listener. r=mrbkap, sr=jst

This commit is contained in:
Boris Zbarsky 2008-12-03 09:41:09 -05:00
Родитель 78bcfd50e8
Коммит 13db56625d
3 изменённых файлов: 19 добавлений и 5 удалений

Просмотреть файл

@ -824,7 +824,6 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
handler);
if (rv == NS_ERROR_ILLEGAL_VALUE) {
NS_WARNING("Probably a syntax error in the event handler!");
context->ReportPendingException();
return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;
}
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -173,6 +173,11 @@ public:
* directly - it must be bound (and thereby cloned, and therefore have the
* correct principals) before use!
*
* If the compilation sets a pending exception on the native context, it is
* this method's responsibility to report said exception immediately, without
* relying on callers to do so.
*
*
* @param aName an nsIAtom pointer naming the function; it must be lowercase
* and ASCII, and should not be longer than 63 chars. This bound on
* length is enforced only by assertions, so caveat caller!

Просмотреть файл

@ -423,10 +423,12 @@ NS_ScriptErrorReporter(JSContext *cx,
const char *message,
JSErrorReport *report)
{
JSStackFrame * fp = nsnull;
while ((fp = JS_FrameIterator(cx, &fp))) {
if (!JS_IsNativeFrame(cx, fp)) {
return;
{ // Scope for |fp|
JSStackFrame * fp = nsnull;
while ((fp = JS_FrameIterator(cx, &fp))) {
if (!JS_IsNativeFrame(cx, fp)) {
return;
}
}
}
@ -1819,6 +1821,9 @@ nsJSContext::CompileEventHandler(nsIAtom *aName,
{
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_NOT_INITIALIZED);
NS_PRECONDITION(!::JS_IsExceptionPending(mContext),
"Why are we being called with a pending exception?");
if (!sSecurityManager) {
NS_ERROR("Huh, we need a script security manager to compile "
"an event handler!");
@ -1849,6 +1854,11 @@ nsJSContext::CompileEventHandler(nsIAtom *aName,
aURL, aLineNo);
if (!fun) {
// Set aside the frame chain on cx while reporting, since it has
// nothing to do with the error we just hit.
JSStackFrame* frame = JS_SaveFrameChain(mContext);
ReportPendingException();
JS_RestoreFrameChain(mContext, frame);
return NS_ERROR_ILLEGAL_VALUE;
}