1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// |jit-test| module
// import.meta is an object.
assertEq(typeof import.meta, "object");
assertEq(import.meta !== null, true);
// import.meta always returns the same object.
let obj = import.meta;
assertEq(import.meta, obj);
// Test calling from lazily compile function.
function get() {
return import.meta;
}
assertEq(get(), import.meta);
// import.meta.url: This property will contain the module script's base URL,
// serialized.
assertEq("url" in import.meta, true);
assertEq(import.meta.url.endsWith("import-meta.js"), true);
assertEq("resolve" in import.meta, true);
assertEq(import.meta.resolve("./x"),
import.meta.url.replace("import-meta.js", "x"));
import getOtherMetaObject from "exportImportMeta.js";
let otherImportMeta = getOtherMetaObject();
assertEq(otherImportMeta.url.endsWith("exportImportMeta.js"), true);
// By default the import.meta object will be extensible, and its properties will
// be writable, configurable, and enumerable.
assertEq(Object.isExtensible(import.meta), true);
for (const name of Reflect.ownKeys(import.meta)) {
const desc = Object.getOwnPropertyDescriptor(import.meta, name);
assertEq(desc.writable, true);
assertEq(desc.enumerable, true);
assertEq(desc.configurable, true);
assertEq(desc.value, import.meta[name]);
}
// The import.meta object's prototype is null.
assertEq(Object.getPrototypeOf(import.meta), null);
import.meta.url = 0;
assertEq(import.meta.url, 0);
import.meta.newProp = 42;
assertEq(import.meta.newProp, 42);
let found = new Set(Reflect.ownKeys(import.meta));
assertEq(found.size, 3);
assertEq(found.has("url"), true);
assertEq(found.has("newProp"), true);
assertEq(found.has("resolve"), true);
delete import.meta.url;
delete import.meta.newProp;
delete import.meta.resolve;
found = new Set(Reflect.ownKeys(import.meta));
assertEq(found.size, 0);
|