Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-of-promise-result.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>import() inside compiled strings inside a classic script</title>
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<base href="scripts/foo/">
<script>
"use strict";
// This test is based on the current specification, but all browser
// implementations aren't conformant. See
// Tweak the base URL of the document here to distinguish:
// - document URL
// - document base URL = ../
// - This inline script's base URL = ./scripts/foo/
document.querySelector("base").remove();
const base = document.createElement("base");
base.setAttribute("href", "../");
document.body.appendChild(base);
self.ran = false;
// The active script for the dynamic import is this inline script
promise_test(t => {
t.add_cleanup(() => {
self.ran = false;
})
return Promise.resolve(`import("../../../imports-a.js?1").then(() => { self.ran = true; })`)
.then(eval)
.then(() => {
assert_true(self.ran);
});
}, "Evaled the script via eval, successful import");
promise_test(t => {
t.add_cleanup(() => {
self.ran = false;
})
return Promise.resolve(`import("bad-specifier?1").catch(() => { self.ran = true; })`)
.then(eval)
.then(() => {
assert_true(self.ran);
});
}, "Evaled the script via eval, failed import");
promise_test(t => {
t.add_cleanup(() => {
self.ran = false;
})
return Promise.resolve(`return import("../../../imports-a.js?2").then(() => { self.ran = true; })`)
.then(Function)
.then(Function.prototype.call.bind(Function.prototype.call))
.then(() => {
assert_true(self.ran);
});
}, "Evaled the script via Function, successful import");
promise_test(t => {
t.add_cleanup(() => {
self.ran = false;
})
return Promise.resolve(`return import("bad-specifier?2").catch(() => { self.ran = true; })`)
.then(Function)
.then(Function.prototype.call.bind(Function.prototype.call))
.then(() => {
assert_true(self.ran);
});
}, "Evaled the script via Function, failed import");
</script>