Open nicolo-ribaudo opened 2 years ago
This is how the different engines schedule the settlement of the import()
promise.
Test code (./dep.js
is an empty file):
(async() => {
{
let i = 0;
(async () => { while (++i<1000) await Promise.resolve() })();
await import("<invalid>").catch(() => console.log("counter after error is", i));
}
await new Promise(r => setTimeout(r, 0)); // cleanup microtask queue
{
let i = 0;
(async () => { while (++i<1000) await Promise.resolve() })();
await import("./dep.js").then(() => console.log("counter after success (first time) is", i));
}
await new Promise(r => setTimeout(r, 0)); // cleanup microtask queue
{
let i = 0;
(async () => { while (++i<1000) await Promise.resolve() })();
await import("./dep.js").then(() => console.log("counter after success (second time) is", i));
}
})();
Node.js:
counter after error is 11
counter after success (first time) is 1000
counter after success (second time) is 14
Deno:
counter after error is 1000
counter after success (first time) is 1000
counter after success (second time) is 1000
Firefox/Chrome (I think that they don't match the HTML spec for counter after success (second time)
):
counter after error is 2
counter after success (first time) is 1000
counter after success (second time) is 1000
Safari:
counter after error is 2
counter after success (first time) is 1000
counter after success (second time) is 3
With this refactor it would be:
counter after error is **host defined**
counter after success (first time) is **host defined**
counter after success (second time) is 3
ModuleWrap
(C++)vm.Module
(JS)ModuleWrap::Link
Module#[kLink]
(called byModule#link
)ModuleWrap::Instantiate
Module#link
module.Link()
ModuleWrap::Evaluate
Module#evaluate
module.Evaluate()