Bug 949722 - Assigning to '.onerror' of XHR appends an event listener, rather than overwriting it (only in workers), r=khuey

This commit is contained in:
Olli Pettay 2013-12-21 02:22:13 +02:00
parent abb96de92a
commit e979b883fc
6 changed files with 19 additions and 12 deletions

View File

@ -525,8 +525,7 @@ nsEventListenerManager::ListenerCanHandle(nsListenerStruct* aLs,
}
return aLs->mTypeString.Equals(aEvent->typeString);
}
MOZ_ASSERT_IF(aEvent->eventStructType != NS_SCRIPT_ERROR_EVENT,
mIsMainThreadELM);
MOZ_ASSERT(mIsMainThreadELM);
return aLs->mEventType == aEvent->message;
}
@ -595,11 +594,6 @@ nsEventListenerManager::SetEventHandlerInternal(JS::Handle<JSObject*> aScopeObje
nsCOMPtr<nsIJSEventListener> scriptListener;
NS_NewJSEventListener(aScopeObject, mTarget, aName,
aHandler, getter_AddRefs(scriptListener));
if (!aName && aTypeString.EqualsLiteral("error")) {
eventType = NS_LOAD_ERROR;
}
EventListenerHolder holder(scriptListener);
AddEventListenerInternal(holder, eventType, aName, aTypeString, flags,
true);

View File

@ -482,7 +482,7 @@ public:
if (mIsMainThreadELM) {
handler = GetEventHandlerInternal(nsGkAtoms::onerror, EmptyString());
} else {
handler = GetEventHandlerInternal(nullptr, NS_LITERAL_STRING("onerror"));
handler = GetEventHandlerInternal(nullptr, NS_LITERAL_STRING("error"));
}
return handler ? handler->OnErrorEventHandler() : nullptr;
}

View File

@ -169,7 +169,9 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
NS_ENSURE_TRUE(aEvent, NS_ERROR_UNEXPECTED);
InternalScriptErrorEvent* scriptEvent =
aEvent->GetInternalNSEvent()->AsScriptErrorEvent();
if (scriptEvent && scriptEvent->message == NS_LOAD_ERROR) {
if (scriptEvent &&
(scriptEvent->message == NS_LOAD_ERROR ||
scriptEvent->typeString.EqualsLiteral("error"))) {
errorMsg = scriptEvent->errorMsg;
msgOrEvent.SetAsString() = static_cast<nsAString*>(&errorMsg);

View File

@ -1223,7 +1223,8 @@ public:
MOZ_ASSERT(target == globalTarget->GetWrapperPreserveColor());
// Icky, we have to fire an InternalScriptErrorEvent...
InternalScriptErrorEvent event(true, NS_LOAD_ERROR);
MOZ_ASSERT(!NS_IsMainThread());
InternalScriptErrorEvent event(true, NS_USER_DEFINED_EVENT);
event.lineNr = aLineNumber;
event.errorMsg = aMessage.get();
event.fileName = aFilename.get();
@ -1238,6 +1239,7 @@ public:
}
else if ((sgo = nsJSUtils::GetStaticScriptGlobal(target))) {
// Icky, we have to fire an InternalScriptErrorEvent...
MOZ_ASSERT(NS_IsMainThread());
InternalScriptErrorEvent event(true, NS_LOAD_ERROR);
event.lineNr = aLineNumber;
event.errorMsg = aMessage.get();
@ -3213,6 +3215,7 @@ WorkerPrivateParent<Derived>::BroadcastErrorToSharedWorkers(
do_QueryInterface(windowAction.mWindow);
MOZ_ASSERT(sgo);
MOZ_ASSERT(NS_IsMainThread());
InternalScriptErrorEvent event(true, NS_LOAD_ERROR);
event.lineNr = aLineNumber;
event.errorMsg = aMessage.BeginReading();

View File

@ -36,3 +36,7 @@ onmessage = function(event) {
}
onerror = errorHandler;
onerror = onerror;
if (!onerror || onerror != onerror) {
throw "onerror wasn't set properly";
}

View File

@ -29,14 +29,18 @@ if (!xhr.onload) {
postMessage(message);
}
xhr.addEventListener("error", function(event) {
xhr.onerror = function(event) {
if (event.target != xhr) {
throw "onerror event.target != xhr";
}
var message = { type: "error",
error: event.target.status };
postMessage(message);
}, false);
};
xhr.onerror = xhr.onerror;
if (!xhr.onerror || xhr.onerror != xhr.onerror) {
throw "onerror wasn't set properly";
}
function onprogress(event) {
if (event.target != xhr) {