Bug 1459984 - avoid firing progress type ProgressEvents for sync XHRs in workers. r?baku
MozReview-Commit-ID: LVOMGGy73HV
--- a/dom/xhr/XMLHttpRequestWorker.cpp
+++ b/dom/xhr/XMLHttpRequestWorker.cpp
@@ -1008,27 +1008,31 @@ Proxy::HandleEvent(Event* aEvent)
if (!GetOrCreateDOMReflectorNoWrap(cx, mXHR, &value)) {
return NS_ERROR_FAILURE;
}
JS::Rooted<JSObject*> scope(cx, &value.toObject());
RefPtr<EventRunnable> runnable;
if (progressEvent) {
- runnable = new EventRunnable(this, isUploadTarget, type,
- progressEvent->LengthComputable(),
- progressEvent->Loaded(),
- progressEvent->Total(),
- scope);
+ if (!mIsSyncXHR || !type.EqualsASCII(sEventStrings[STRING_progress])) {
+ runnable = new EventRunnable(this, isUploadTarget, type,
+ progressEvent->LengthComputable(),
+ progressEvent->Loaded(),
+ progressEvent->Total(),
+ scope);
+ }
}
else {
runnable = new EventRunnable(this, isUploadTarget, type, scope);
}
- runnable->Dispatch();
+ if (runnable) {
+ runnable->Dispatch();
+ }
}
if (!isUploadTarget) {
if (type.EqualsASCII(sEventStrings[STRING_loadstart])) {
mMainThreadSeenLoadStart = true;
}
else if (mMainThreadSeenLoadStart &&
type.EqualsASCII(sEventStrings[STRING_loadend])) {
@@ -1736,16 +1740,21 @@ XMLHttpRequestWorker::DispatchPrematureA
}
RefPtr<Event> event;
if (aEventType.EqualsLiteral("readystatechange")) {
event = NS_NewDOMEvent(aTarget, nullptr, nullptr);
event->InitEvent(aEventType, false, false);
}
else {
+ if (mProxy->mIsSyncXHR &&
+ aEventType.EqualsASCII(sEventStrings[STRING_progress])) {
+ return;
+ }
+
ProgressEventInit init;
init.mBubbles = false;
init.mCancelable = false;
if (aUploadTarget) {
init.mLengthComputable = mProxy->mLastUploadLengthComputable;
init.mLoaded = mProxy->mLastUploadLoaded;
init.mTotal = mProxy->mLastUploadTotal;
}
deleted file mode 100644
--- a/testing/web-platform/meta/xhr/sync-no-progress.any.js.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[sync-no-progress.any.worker.html]
- [progress event should not be fired by sync XHR]
- expected: FAIL
-