-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See whatwg/html#5572 Bug: 1296665 Change-Id: I63938700518941d0f65a2a1c7fd13910bd095261
- Loading branch information
1 parent
a4da364
commit 6befcde
Showing
4 changed files
with
129 additions
and
20 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-object.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// META: global=dedicatedworker-module,sharedworker-module,serviceworker-module | ||
|
||
test(() => { | ||
assert_equals(typeof import.meta, "object"); | ||
assert_not_equals(import.meta, null); | ||
}, "import.meta is an object"); | ||
|
||
test(() => { | ||
import.meta.newProperty = 1; | ||
assert_true(Object.isExtensible(import.meta)); | ||
}, "import.meta is extensible"); | ||
|
||
test(() => { | ||
for (const name of Reflect.ownKeys(import.meta)) { | ||
const desc = Object.getOwnPropertyDescriptor(import.meta, name); | ||
assert_equals(desc.writable, true); | ||
assert_equals(desc.enumerable, true); | ||
assert_equals(desc.configurable, true); | ||
} | ||
}, "import.meta's properties are writable, configurable, and enumerable"); |
46 changes: 46 additions & 0 deletions
46
...tics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-importmap.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<!-- | ||
More extensive tests of import maps and import.meta.resolve() will be | ||
located in the import maps test suite. This contains some basic tests plus | ||
tests some tricky parts of the import.meta.resolve() algorithm around string | ||
conversion which are only testable with import maps. | ||
--> | ||
|
||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"bare": "https://example.com/", | ||
"https://example.com/rewrite": "https://example.com/rewritten", | ||
|
||
"1": "https://example.com/PASS-1", | ||
"null": "https://example.com/PASS-null", | ||
"undefined": "https://example.com/PASS-undefined", | ||
"[object Object]": "https://example.com/PASS-object" | ||
} | ||
} | ||
</script> | ||
|
||
<script type="module"> | ||
test(() => { | ||
assert_equals(import.meta.resolve("bare"), "https://example.com/"); | ||
}, "import.meta.resolve() given an import mapped bare specifier"); | ||
|
||
test(() => { | ||
assert_equals(import.meta.resolve("https://example.com/rewrite"), "https://example.com/rewritten"); | ||
}, "import.meta.resolve() given an import mapped URL-like specifier"); | ||
|
||
test(() => { | ||
assert_equals(import.meta.resolve(), "https://example.com/PASS-undefined", "no-arg case"); | ||
|
||
assert_equals(import.meta.resolve(1), "https://example.com/PASS-1"); | ||
assert_equals(import.meta.resolve(null), "https://example.com/PASS-null"); | ||
assert_equals(import.meta.resolve(undefined), "https://example.com/PASS-undefined"); | ||
|
||
// Only toString() methods are consulted by ToString, not valueOf() ones. | ||
// So this becomes "[object Object]". | ||
assert_equals(import.meta.resolve({ valueOf() { return "./x"; } }), "https://example.com/PASS-object"); | ||
}, "Testing the ToString() step of import.meta.resolve() via import maps"); | ||
</script> |
63 changes: 63 additions & 0 deletions
63
html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// META: global=dedicatedworker-module,sharedworker-module,serviceworker-module | ||
|
||
import { importMetaOnRootModule, importMetaOnDependentModule } | ||
from "./import-meta-root.js"; | ||
|
||
test(() => { | ||
assert_equals(typeof import.meta.resolve, "function"); | ||
assert_equals(import.meta.resolve.name, "resolve"); | ||
assert_equals(import.meta.resolve.length, 1); | ||
assert_equals(Object.getPrototypeOf(import.meta.resolve), Function.prototype); | ||
}, "import.meta.resolve is a function with the right properties"); | ||
|
||
test(() => { | ||
assert_false(isConstructor(import.meta.resolve)); | ||
|
||
assert_throws_js(TypeError, () => new import.meta.resolve("./x")); | ||
}, "import.meta.resolve is not a constructor"); | ||
|
||
test(() => { | ||
// See also tests in ./import-meta-resolve-importmap.html. | ||
|
||
assert_equals(import.meta.resolve({ toString() { return "./x"; } }), resolveURL(import.meta, "x")); | ||
assert_throws_js(TypeError, () => import.meta.resolve(Symbol("./x")), | ||
"symbol"); | ||
assert_throws_js(TypeError, () => import.meta.resolve(), | ||
"no argument (which is treated like \"undefined\")"); | ||
}, "import.meta.resolve ToString()s its argument"); | ||
|
||
test(() => { | ||
assert_equals(import.meta.resolve("./x"), resolveURL(import.meta, "x"), | ||
"current module import.meta"); | ||
assert_equals(importMetaOnRootModule.resolve("./x"), resolveURL(importMetaOnRootModule, "x"), | ||
"sibling module import.meta"); | ||
assert_equals(importMetaOnDependentModule.resolve("./x"), resolveURL(importMetaOnDependentModule, "x"), | ||
"dependency module import.meta"); | ||
}, "Relative URL-like specifier resolution"); | ||
|
||
test(() => { | ||
assert_equals(import.meta.resolve("https://example.com/"), "https://example.com/", | ||
"current module import.meta"); | ||
assert_equals(importMetaOnRootModule.resolve("https://example.com/"), "https://example.com/", | ||
"sibling module import.meta"); | ||
assert_equals(importMetaOnDependentModule.resolve("https://example.com/"), "https://example.com/", | ||
"dependency module import.meta"); | ||
}, "Absolute URL-like specifier resolution"); | ||
|
||
test(() => { | ||
const { resolve } = import.meta; | ||
assert_equals(resolve("https://example.com/"), "https://example.com/", "current module import.meta"); | ||
}, "Works fine with no this value"); | ||
|
||
function resolveURL(importMeta, relativeURL) { | ||
return (new URL(relativeURL, importMeta.url)).href; | ||
} | ||
|
||
function isConstructor(o) { | ||
try { | ||
new (new Proxy(o, { construct: () => ({}) })); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters