Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

1.9 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
function worker_url(source) {
  return "data:text/javascript," + encodeURIComponent(source);
}

function next_message(worker) {
  return new Promise(function (resolve) {
    worker.addEventListener("message", resolve, { once: true });
  });
}

promise_test(async function () {
  const depUrl = worker_url("export const answer = 42;");
  const source = [
    "import * as dep from " + JSON.stringify(depUrl) + ";",
    "const topLevelThisUndefined = this === undefined;",
    "function functionThis() { return this; }",
    "let implicitGlobalError = 'none';",
    "try {",
    "  namespaceImportGlobal = 7;",
    "} catch (error) {",
    "  implicitGlobalError = error && error.name;",
    "}",
    "postMessage({",
    "  answer: dep.answer,",
    "  topLevelThisUndefined,",
    "  functionThisUndefined: functionThis() === undefined,",
    "  implicitGlobalError,",
    "  leakedGlobal: Object.prototype.hasOwnProperty.call(self, 'namespaceImportGlobal')",
    "});",
  ].join("\n");
  const worker = new Worker(worker_url(source), { type: "module" });

  try {
    const message = await next_message(worker);
    assert_equals(message.data.answer, 42, "namespace import should remain usable");
    assert_true(message.data.topLevelThisUndefined, "module top-level this should be undefined");
    assert_true(message.data.functionThisUndefined, "module functions should run in strict mode");
    assert_equals(message.data.implicitGlobalError, "ReferenceError", "implicit global assignment should throw");
    assert_false(message.data.leakedGlobal, "implicit global assignment should not leak onto self");
  } finally {
    worker.terminate();
  }
}, "Dedicated namespace-import module workers run with strict-mode semantics");
</script>