Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* Any copyright is dedicated to the Public Domain.
// Test that top-level await with dynamic import works as expected.
"use strict";
const TEST_URI =
add_task(async function () {
// Enable dynamic import
await pushPref("javascript.options.dynamicImport", true);
// Enable await mapping.
await pushPref("devtools.debugger.features.map-await-expression", true);
const hud = await openNewTabAndConsole(TEST_URI);
info("Evaluate an expression with a dynamic import");
let importAwaitExpression = `
var {sum} = await import("./test-dynamic-import.mjs");
sum(1, 2, 3);
`;
await executeAndWaitForResultMessage(
hud,
importAwaitExpression,
`1 + 2 + 3 = 6`
);
ok(true, "The `sum` module was imported and used successfully");
info("Import the same module a second time");
// This used to make the content page crash (See Bug 1523897).
importAwaitExpression = `
var {sum} = await import("./test-dynamic-import.mjs");
sum(2, 3, 4);
`;
await executeAndWaitForResultMessage(
hud,
importAwaitExpression,
`2 + 3 + 4 = 9`
);
ok(true, "The `sum` module was imported and used successfully a second time");
});