diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 4f1c075847a..abe803517fd 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -1515,25 +1515,22 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, // Try the type-specific listener interface PRBool hasInterface = PR_FALSE; if (typeData) - ret = DispatchToInterface(*aDOMEvent, ls->mListener, - dispData->method, *typeData->iid, - &hasInterface); + DispatchToInterface(*aDOMEvent, ls->mListener, + dispData->method, *typeData->iid, + &hasInterface); // If it doesn't implement that, call the generic HandleEvent() if (!hasInterface && (ls->mSubType == NS_EVENT_BITS_NONE || ls->mSubType & dispData->bits)) - ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, - dispData ? dispData->bits : NS_EVENT_BITS_NONE, - aFlags); + HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, + dispData ? dispData->bits : NS_EVENT_BITS_NONE, + aFlags); } } } } - // XXX (NS_OK != ret) is going away, - // (aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) is correct - if ((NS_OK != ret) || - (aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT)) { + if (aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) { *aEventStatus = nsEventStatus_eConsumeNoDefault; } diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 129c90b6705..ac4db4960d4 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -5025,7 +5025,6 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout) nsTimeoutImpl dummy_timeout; JSContext *cx; PRInt64 now, deadline; - nsresult rv; PRUint32 firingDepth = mTimeoutFiringDepth + 1; // Make sure that the window and the script context don't go away as @@ -5124,10 +5123,10 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout) nsAutoString retval; PRBool is_undefined; - rv = mContext->EvaluateString(nsDependentString(script), mJSObject, - timeout->mPrincipal, timeout->mFileName, - timeout->mLineNo, timeout->mVersion, - retval, &is_undefined); + mContext->EvaluateString(nsDependentString(script), mJSObject, + timeout->mPrincipal, timeout->mFileName, + timeout->mLineNo, timeout->mVersion, retval, + &is_undefined); } else { PRInt64 lateness64; PRInt32 lateness; @@ -5140,9 +5139,8 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout) timeout->mArgv[timeout->mArgc] = INT_TO_JSVAL((jsint) lateness); jsval dummy; - rv = mContext->CallEventHandler(mJSObject, timeout->mFunObj, - timeout->mArgc + 1, timeout->mArgv, - &dummy); + mContext->CallEventHandler(mJSObject, timeout->mFunObj, + timeout->mArgc + 1, timeout->mArgv, &dummy); } --mTimeoutFiringDepth; @@ -5209,9 +5207,9 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout) // Reschedule the OS timer. Don't bother returning any error // codes if this fails since nobody who cares about them is // listening anyways. - rv = timeout->mTimer->InitWithFuncCallback(TimerCallback, timeout, - delay32, - nsITimer::TYPE_ONE_SHOT); + nsresult rv = + timeout->mTimer->InitWithFuncCallback(TimerCallback, timeout, delay32, + nsITimer::TYPE_ONE_SHOT); if (NS_FAILED(rv)) { NS_ERROR("Error initializing timer for DOM timeout!"); diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index 3600a7858a6..2b3918124b7 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -1277,13 +1277,16 @@ nsJSContext::CallEventHandler(JSObject *aTarget, JSObject *aHandler, // Don't pass back results from failed calls. *rval = JSVAL_VOID; + + // Tell the caller that the handler threw an error. + rv = NS_ERROR_FAILURE; } } if (NS_FAILED(stack->Pop(nsnull))) return NS_ERROR_FAILURE; - return NS_OK; + return rv; } nsresult diff --git a/dom/src/events/nsJSEventListener.cpp b/dom/src/events/nsJSEventListener.cpp index 05940460e2a..8f592eb36a3 100644 --- a/dom/src/events/nsJSEventListener.cpp +++ b/dom/src/events/nsJSEventListener.cpp @@ -100,7 +100,8 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } //if (mReturnResult == nsReturnResult_eNotSet) { - if (eventString.Equals(NS_LITERAL_STRING("error")) || eventString.Equals(NS_LITERAL_STRING("mouseover"))) { + if (eventString.Equals(NS_LITERAL_STRING("error")) || + eventString.Equals(NS_LITERAL_STRING("mouseover"))) { mReturnResult = nsReturnResult_eReverseReturnResult; } else { @@ -197,18 +198,19 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) beforeUnload->text = nsDependentJSString(JSVAL_TO_STRING(rval)); } } - } else { + } else if (JSVAL_IS_BOOLEAN(rval)) { // if the handler returned false and its sense is not reversed, // or the handler returned true and its sense is reversed from // the usual (false means cancel), then prevent default. - PRBool jsBoolResult = !JSVAL_IS_BOOLEAN(rval) || JSVAL_TO_BOOLEAN(rval); - - if (jsBoolResult == + if (JSVAL_TO_BOOLEAN(rval) == (mReturnResult == nsReturnResult_eReverseReturnResult)) { aEvent->PreventDefault(); } } + } else if (eventString.Equals(NS_LITERAL_STRING("onsubmit"))) { + // Don't submit any data if the event handler failed + aEvent->PreventDefault(); } return rv;