summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/wasm/webapi/abort.any.js
blob: f5ddd353aa9e358409d82b98f816dd01d45d53f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const methods = [
  "compileStreaming",
  "instantiateStreaming",
];

for (const method of methods) {
  promise_test(async t => {
    const controller = new AbortController();
    const signal = controller.signal;
    controller.abort();
    const request = fetch('../incrementer.wasm', { signal });
    return promise_rejects_dom(t, 'AbortError', WebAssembly[method](request),
                              `${method} should reject`);
  }, `${method}() on an already-aborted request should reject with AbortError`);

  promise_test(async t => {
    const controller = new AbortController();
    const signal = controller.signal;
    const request = fetch('../incrementer.wasm', { signal });
    const promise = WebAssembly[method](request);
    controller.abort();
    return promise_rejects_dom(t, 'AbortError', promise, `${method} should reject`);
  }, `${method}() synchronously followed by abort should reject with AbortError`);

  promise_test(async t => {
    const controller = new AbortController();
    const signal = controller.signal;
    return fetch('../incrementer.wasm', { signal })
    .then(response => {
      Promise.resolve().then(() => controller.abort());
      return WebAssembly[method](response);
    })
    .catch(err => {
      assert_equals(err.name, "AbortError");
    });
  }, `${method}() asynchronously racing with abort should succeed or reject with AbortError`);
}