summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/microtasks/resources/evaluation-order-setup.js
blob: d2e28935c437150b88f50b1c3b4a3834f66899b9 (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
globalThis.setup({allow_uncaught_exception: true});

// Must be called after previous tests are completed.
globalThis.setupTest = (description, expectedLog) => {
  globalThis.log = [];
  globalThis.onerror = message => {
      globalThis.log.push("global-error");
      return true;
  };
  globalThis.onunhandledrejection =
      () => globalThis.log.push('unhandled-promise-rejection');

  globalThis.unreachable = () => globalThis.log.push("unreachable");

  globalThis.test_load = async_test(description);
  globalThis.testDone = globalThis.test_load.step_func_done(() => {
    assert_array_equals(globalThis.log, expectedLog);
  });

  if (!('Window' in globalThis && globalThis instanceof Window)) {
    // In workers, there are no <script> load event, so scheduling `testDone()`
    // here, assuming the target script is loaded and evaluated soon.
    globalThis.test_load.step_timeout(() => globalThis.testDone(), 1000);

    // In workers, call `done()` here because the auto-generated `done()` calls
    // by `any.js` etc. are at the end of main script and thus are not
    // evaluated when the target script throws an exception.
    done();
  }
};