tor-browser

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

eval-self-once-script.js (1398B)


      1 // |reftest| async
      2 // Copyright (C) 2018 Rick Waldron. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 description: Script is evaluated exactly once after loaded by import
      6 esid: sec-hostimportmoduledynamically
      7 info: |
      8  Success path
      9 
     10  The completion value of any subsequent call to HostResolveImportedModule after
     11  FinishDynamicImport has completed, given the arguments referencingScriptOrModule
     12  and specifier, must be a module which has already been evaluated, i.e. whose
     13  Evaluate concrete method has already been called and returned a normal completion.
     14 
     15  This test is meant to __not__ be flagged as module code, it should not initially
     16  run as module code or the result will not be the same.
     17 includes: [fnGlobalObject.js]
     18 flags: [async]
     19 features: [dynamic-import]
     20 ---*/
     21 
     22 var global = fnGlobalObject();
     23 
     24 var isFirstScript = typeof global.evaluated === 'undefined';
     25 if (isFirstScript) {
     26  global.evaluated = 0;
     27 }
     28 
     29 global.evaluated++;
     30 
     31 var p = Promise.all([
     32  import('./eval-self-once-script.js'),
     33  import('./eval-self-once-script.js'),
     34 ]).then(async () => {
     35  // Use await to serialize imports
     36  await import('./eval-self-once-script.js');
     37  await import('./eval-self-once-script.js');
     38 
     39  assert.sameValue(global.evaluated, 2, 'global property was defined once and incremented twice');
     40 });
     41 
     42 if (isFirstScript) {
     43  p.then($DONE, $DONE);
     44 }