From ce8435b003413734bd3a57551fd15bc3d2e4deca Mon Sep 17 00:00:00 2001 From: Eric Rannaud Date: Sun, 7 Sep 2025 16:09:42 -0700 Subject: [PATCH] test: testcase demonstrating issue 59541 Check that we lose the execution flow in the outer context, upon resolving a promise created in in the inner context. PR-URL: https://github.com/nodejs/node/pull/59801 Fixes: https://github.com/nodejs/node/issues/59541 Refs: https://issues.chromium.org/issues/441679231 Refs: https://groups.google.com/g/v8-dev/c/YIeRg8CUNS8/m/rEQdFuNZAAAJ Refs: https://tc39.es/ecma262/#sec-newpromiseresolvethenablejob Reviewed-By: Anna Henningsen --- .../parallel/test-vm-module-after-evaluate.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/parallel/test-vm-module-after-evaluate.js diff --git a/test/parallel/test-vm-module-after-evaluate.js b/test/parallel/test-vm-module-after-evaluate.js new file mode 100644 index 00000000000..823fe285f4d --- /dev/null +++ b/test/parallel/test-vm-module-after-evaluate.js @@ -0,0 +1,34 @@ +// Flags: --experimental-vm-modules +'use strict'; + +// https://github.com/nodejs/node/issues/59541 +// +// Promises created in a context using microtaskMode: "aferEvaluate" (meaning it +// has its own microtask queue), when resolved in the surrounding context, will +// schedule a task back onto the inner context queue. + +const common = require('../common'); +const vm = require('vm'); + +const microtaskMode = 'afterEvaluate'; + +(async () => { + const mustNotCall1 = common.mustNotCall(); + const mustNotCall2 = common.mustNotCall(); + + const inner = {}; + + const context = vm.createContext({ inner }, { microtaskMode }); + + const module = new vm.SourceTextModule( + 'inner.promise = Promise.resolve();', + { context }, + ); + + await module.link(mustNotCall1); + await module.evaluate(); + + // This is Issue 59541, the next statement is not executed, of course + // it should be. + mustNotCall2(); +})().then(common.mustNotCall());