tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

checkpoint-importScripts.any.js (1330B)


      1 // META: global=dedicatedworker,sharedworker
      2 
      3 // The `then` handlers for `Promise.resolve()` are evaluated in the first
      4 // microtasks checkpoint after `Promise.resolve()`.
      5 
      6 // ----------------------------------------------------------------
      7 // Check when microtasks checkpoint is performed around importScripts().
      8 
      9 // The expectation is: the `then` handlers are evaluated after the script
     10 // calling importScripts() is finished, not immediately after importScripts().
     11 // Although #clean-up-after-running-script is executed as a part of
     12 // #run-a-classic-script for importScripts()ed scripts, but at that time
     13 // microtasks checkpoint is NOT performed because JavaScript execution context
     14 // stack is not empty.
     15 
     16 self.log = [];
     17 
     18 // Microtasks should be executed before
     19 // #run-a-classic-script/#run-a-module-script is completed, and thus before
     20 // script evaluation scheduled by setTimeout().
     21 async_test(t => {
     22  self.addEventListener('error',
     23      t.unreached_func('error event should not be fired'));
     24 
     25  t.step_timeout(() => {
     26      assert_array_equals(log, [
     27          'importScripts()ed script',
     28          'catch',
     29          'promise'
     30        ]);
     31      t.done();
     32    },
     33    0);
     34 }, "Promise resolved during importScripts()");
     35 
     36 try {
     37  importScripts('resources/resolve-then-throw.js');
     38 } catch (e) {
     39  self.log.push('catch');
     40 }