test: testcase demonstrating issue 59541 · nodejs/node@ce8435b
1+// Flags: --experimental-vm-modules
2+'use strict';
3+4+// https://github.com/nodejs/node/issues/59541
5+//
6+// Promises created in a context using microtaskMode: "aferEvaluate" (meaning it
7+// has its own microtask queue), when resolved in the surrounding context, will
8+// schedule a task back onto the inner context queue.
9+10+const common = require('../common');
11+const vm = require('vm');
12+13+const microtaskMode = 'afterEvaluate';
14+15+(async () => {
16+const mustNotCall1 = common.mustNotCall();
17+const mustNotCall2 = common.mustNotCall();
18+19+const inner = {};
20+21+const context = vm.createContext({ inner }, { microtaskMode });
22+23+const module = new vm.SourceTextModule(
24+'inner.promise = Promise.resolve();',
25+{ context },
26+);
27+28+await module.link(mustNotCall1);
29+await module.evaluate();
30+31+// This is Issue 59541, the next statement is not executed, of course
32+// it should be.
33+mustNotCall2();
34+})().then(common.mustNotCall());