-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix xhr.abort() during XHR readystatechange
Closes #1808.
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/web-platform-tests/to-upstream/XMLHttpRequest/abort-during-readystatechange.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<title>abort() during readystatechange should work fine</title> | ||
<link rel="author" title="Domenic Denicola" href="mailto:[email protected]"> | ||
<link rel="help" href="https://xhr.spec.whatwg.org/#the-abort()-method"> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const xhr = new XMLHttpRequest(); | ||
|
||
// In jsdom's implementation, this would cause a crash, as after firing readystatechange for HEADERS_RECEIVED, it would | ||
// try to manipulate internal state. But that internal state got cleared during abort(). So jsdom needed to be modified | ||
// to check if that internal state had gone away as a result of firing readystatechange, and if so, bail out. | ||
|
||
xhr.addEventListener("readystatechange", () => { | ||
if (xhr.readyState === xhr.HEADERS_RECEIVED) { | ||
xhr.abort(); | ||
} else if (xhr.readyState === xhr.DONE) { | ||
done(); | ||
} | ||
}); | ||
|
||
xhr.open("GET", "/common/blank.html"); | ||
xhr.send(); | ||
|
||
</script> |