Re: [whatwg/xhr] Wrong state after abort() (#88)

@annevk: you are right.

I updated my previous comment with more code.

The test [open-during-abort](https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/open-during-abort.htm) *does* set the state to UNSENT in the end. It does not show up in the test however because no `readystatechange` event is fired when setting the state to `UNSENT` in `abort()`. This can be proved by adding a line at the end:

 test(function() {
 var client = new XMLHttpRequest(),
  abort_flag = false,
  result = [],
  expected = [1, 4, 1] // open() => 1, abort() => 4, open() => 1
  
 client.onreadystatechange = this.step_func(function() {
   result.push(client.readyState)
   if (abort_flag) {
  abort_flag = false
  client.open("GET", "...")
   }
 })
 client.open("GET", "resources/well-formed.xml")
 client.send(null)
 abort_flag = true
 client.abort()
 assert_array_equals(result, expected)
 // succeeds in Firefox (as per spec), but fails in Chrome (readyState == UNSENT)
 assert_equals(client.readyState, 1)
 })

Maybe calling `open()` during `abort()` should not be supported, but if it is, the current behavior of Chrome leaves the request in a broken state. The user called `open()` but a subsequent call to `setRequestHeader()` would fail because the state is `UNSENT`.

At the very least, the final `readyState` should be asserted in the test.


As for the other part of this issue, the sequence

1. `xhr.open()`
2. `xhr.abort()`

will set the state to `UNSENT` (not respecting the spec) as the test [abort-during-open](https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/abort-during-open.js) dictates and as the code shows.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/xhr/issues/88#issuecomment-254582071

Received on Tuesday, 18 October 2016 17:38:04 UTC