mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 10:42:18 +00:00

This commit fixes up some issues in #18394. * Switch vm.Module internals to use the new link method properly * Fix bug with ModuleWrap::Link * Add tests for ModuleWrap::Link PR-URL: https://github.com/nodejs/node/pull/18509 Fixes: https://github.com/nodejs/node/issues/18249 Refs: https://github.com/nodejs/node/pull/18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
30 lines
847 B
JavaScript
30 lines
847 B
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
const common = require('../common');
|
|
common.crashOnUnhandledRejection();
|
|
const assert = require('assert');
|
|
|
|
const ModuleWrap = require('internal/loader/ModuleWrap');
|
|
const { getPromiseDetails, isPromise } = process.binding('util');
|
|
const setTimeoutAsync = require('util').promisify(setTimeout);
|
|
|
|
const foo = new ModuleWrap('export * from "bar"; 6;', 'foo');
|
|
const bar = new ModuleWrap('export const five = 5', 'bar');
|
|
|
|
(async () => {
|
|
const promises = foo.link(() => setTimeoutAsync(1000).then(() => bar));
|
|
assert.strictEqual(promises.length, 1);
|
|
assert(isPromise(promises[0]));
|
|
|
|
await Promise.all(promises);
|
|
|
|
assert.strictEqual(getPromiseDetails(promises[0])[1], bar);
|
|
|
|
foo.instantiate();
|
|
|
|
assert.strictEqual(await foo.evaluate(), 6);
|
|
assert.strictEqual(foo.namespace().five, 5);
|
|
})();
|