mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
- Make sure that the vm.Module.evaluate() method is conditionally synchronous based on the specification. Previously, the returned promise is unconditionally pending (even for synthetic modules and source text modules without top-level await) instead of immediately fulfilled, making it harder to debug as it deviates from the specified behavior. - Clarify the synchronicity of this method in the documentation - Add more tests for the synchronicity of this method. PR-URL: https://github.com/nodejs/node/pull/60205 Refs: https://github.com/nodejs/node/issues/59656 Refs: https://github.com/nodejs/node/issues/37648 Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
35 lines
811 B
JavaScript
35 lines
811 B
JavaScript
// Flags: --experimental-vm-modules
|
|
'use strict';
|
|
|
|
// This tests the result of evaluating a vm.Module while it is evaluating.
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
const vm = require('vm');
|
|
|
|
{
|
|
let mod;
|
|
globalThis.evaluate = common.mustCall(() => {
|
|
assert.rejects(() => mod.evaluate(), {
|
|
code: 'ERR_VM_MODULE_STATUS'
|
|
}).then(common.mustCall());
|
|
});
|
|
common.allowGlobals(globalThis.evaluate);
|
|
mod = new vm.SourceTextModule(`
|
|
globalThis.evaluate();
|
|
export const a = 42;
|
|
`);
|
|
mod.linkRequests([]);
|
|
mod.instantiate();
|
|
mod.evaluate();
|
|
}
|
|
|
|
{
|
|
const mod = new vm.SyntheticModule(['a'], common.mustCall(() => {
|
|
assert.rejects(() => mod.evaluate(), {
|
|
code: 'ERR_VM_MODULE_STATUS'
|
|
}).then(common.mustCall());
|
|
}));
|
|
mod.evaluate();
|
|
}
|