tor-browser

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

test_import_meta_resolve.html (2211B)


      1 <!DOCTYPE html>
      2 <head>
      3  <meta charset=utf-8>
      4  <title>Test import.meta.resolve</title>
      5 </head>
      6 <body onload='testLoaded()'>
      7 
      8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      9 <script>
     10  SimpleTest.waitForExplicitFinish();
     11 
     12  // eslint-disable-next-line no-unused-vars
     13  function assertThrowsTypeError(fn, msg) {
     14    let hasThrown = false;
     15    try {
     16      fn();
     17    } catch (error) {
     18      hasThrown = true;
     19      ok(error instanceof TypeError, "Thrown error should be TypeError.");
     20    }
     21    ok(hasThrown, msg);
     22  }
     23 
     24  // eslint-disable-next-line no-unused-vars
     25  function testLoaded() {
     26    SimpleTest.finish();
     27  }
     28 </script>
     29 
     30 <script type="module">
     31  is(typeof import.meta.resolve, "function", "resolve should be a function.");
     32  is(import.meta.resolve.name, "resolve", "resolve.name should be 'resolve'.");
     33  is(import.meta.resolve.length, 1, "resolve.length should be 1.");
     34  is(Object.getPrototypeOf(import.meta.resolve), Function.prototype,
     35     "prototype of resolve should be Function.prototype.");
     36 </script>
     37 
     38 <script type="module">
     39  is(import.meta.resolve("http://example.com/"), "http://example.com/",
     40     "resolve specifiers with absolute path.");
     41 </script>
     42 
     43 <script type="module">
     44  is(import.meta.resolve("./x"), (new URL("./x", import.meta.url)).href,
     45     "resolve specifiers with relative path.");
     46 </script>
     47 
     48 <script type="module">
     49  /* global assertThrowsTypeError */
     50  assertThrowsTypeError(() => new import.meta.resolve("./x"),
     51                        "import.meta.resolve is not a constructor.");
     52 </script>
     53 
     54 <script type="module">
     55  /* global assertThrowsTypeError */
     56  // Fails to resolve the specifier should throw a TypeError.
     57  assertThrowsTypeError(() => import.meta.resolve("failed"),
     58                        "import.meta.resolve should throw if fails to resolve");
     59 </script>
     60 
     61 <script type="module">
     62  for (const name of Reflect.ownKeys(import.meta)) {
     63    const desc = Object.getOwnPropertyDescriptor(import.meta, name);
     64    is(desc.writable, true, name + ".writable should be true.");
     65    is(desc.enumerable, true, name + ".enumerable should be true.");
     66    is(desc.configurable, true, name + ".configurable should be true.");
     67  }
     68 </script>
     69 </body>