tor-browser

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

dynamic-import-module.js (940B)


      1 function testImport(path, name, value) {
      2    let result = null;
      3    let error = null;
      4    let promise = import(path);
      5    promise.then((ns) => {
      6        result = ns;
      7    }).catch((e) => {
      8        error = e;
      9    });
     10 
     11    drainJobQueue();
     12    assertEq(error, null);
     13    assertEq(result[name], value);
     14 }
     15 
     16 // Resolved via module load path.
     17 testImport("module1.js", "a", 1);
     18 
     19 // Relative path resolved relative to this script.
     20 testImport("../../modules/module1a.js", "a", 2);
     21 
     22 // Import inside function.
     23 function f() {
     24    testImport("../../modules/module2.js", "b", 2);
     25 }
     26 f();
     27 
     28 // Import inside direct eval.
     29 eval(`testImport("../../modules/module3.js", "c", 3)`);
     30 
     31 // Import inside indirect eval.
     32 const indirect = eval;
     33 const defineTestFunc = testImport.toString();
     34 indirect(defineTestFunc + `testImport("../../modules/module3.js");`);
     35 
     36 // Import inside dynamic function.
     37 Function(defineTestFunc + `testImport("../../modules/module3.js");`)();