[w3c/FileAPI] Disparity in `loadend` event dispatch between spec, implementation & tests (#175)

Disclaimer: I might be wrong!

According to the spec, the `loadend` event is synchronously fired right after the `load` event is dispatched. This all happens inside a single "queue a task". This means that the `load` and `loadend` events should be fired in the same turn of the event loop. There is no separate "queue a task" for the dispatching of the `loadend` event.

[The WPT test](https://github.com/web-platform-tests/wpt/blob/a85ad4ce635b330f78c3a720f3a2fde7002d6c5b/FileAPI/reading-data-section/filereader_events.any.js) for this does not agree however. It tests that the `loadend` event is dispatched one turn of the event loop later (note the await point between `eventWatcher.wait_for('load')` and `eventWatcher.wait_for('loadend')`):

```js
  // wpt/FileAPI/reading-data-section/filereader_events.any.js
  var reader = new FileReader();
  var eventWatcher = new EventWatcher(t, reader, ['loadstart', 'progress', 'abort', 'error', 'load', 'loadend']);
  reader.readAsText(new Blob(['a']));
  await eventWatcher.wait_for('loadstart');
  await eventWatcher.wait_for('progress');
  await eventWatcher.wait_for('load');
  await eventWatcher.wait_for('loadend');
```

The test that would agree with spec behaviour would be the following:

```js
  var reader = new FileReader();
  var eventWatcher = new EventWatcher(t, reader, ['loadstart', 'progress', 'abort', 'error', 'load', 'loadend']);
  reader.readAsText(new Blob(['a']));
  await eventWatcher.wait_for('loadstart');
  await eventWatcher.wait_for('progress');
  await eventWatcher.wait_for(['load', 'loadend']);
```

All of Chrome, Firefox and Safari implement this according to the current WPT test: https://wpt.fyi/results/FileAPI/reading-data-section/filereader_events.any.html?label=master&label=experimental&product=chrome&product=firefox&product=safari&aligned

So my question: as all browsers agree to disagree here, should the spec be updated? Alternatively I can file issues with all vendors to get this aligned to spec (and correct the test).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/FileAPI/issues/175

Received on Thursday, 12 August 2021 10:45:12 UTC