mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-28 03:18:41 +00:00
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:
parent
abb96de92a
commit
e979b883fc
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -36,3 +36,7 @@ onmessage = function(event) {
|
||||
}
|
||||
|
||||
onerror = errorHandler;
|
||||
onerror = onerror;
|
||||
if (!onerror || onerror != onerror) {
|
||||
throw "onerror wasn't set properly";
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user