// |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);
