Skip to content

Commit 80aad55

Browse files
committed
lib vm: 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.
1 parent 26607a6 commit 80aad55

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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
7+
// it has its own microtask queue), when resolved in the surrounding context,
8+
// will schedule a task back onto the inner context queue. This test checks that
9+
// the async execution progresses normally.
10+
11+
const common = require('../common');
12+
const assert = require('assert');
13+
const vm = require('vm');
14+
15+
const context = vm.createContext({}, {
16+
microtaskMode: "afterEvaluate",
17+
});
18+
19+
(async () => {
20+
const module = new vm.SourceTextModule(
21+
'',
22+
{context},
23+
);
24+
25+
await module.link(common.mustNotCall());
26+
await module.evaluate();
27+
})().then(
28+
// mustNotCall to illustrate the issue, it should of course be called.
29+
common.mustNotCall());
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
// https://github.com/nodejs/node/issues/59541
4+
//
5+
// Promises created in a context using microtaskMode: "aferEvaluate" (meaning
6+
// it has its own microtask queue), when resolved in the surrounding context,
7+
// will schedule a task back onto the inner context queue. This test checks that
8+
// the async execution progresses normally.
9+
10+
const common = require('../common');
11+
const assert = require('assert');
12+
const vm = require('vm');
13+
14+
vm.runInNewContext(
15+
`Promise.resolve()`,
16+
{}, { microtaskMode: 'afterEvaluate' })
17+
// We need to first resolve to a native promise object, to hit
18+
// the behavior described at
19+
// https://issues.chromium.org/issues/441679231
20+
.then(Promise.resolve())
21+
.then(
22+
// mustNotCall to illustrate the issue, it should of course be called.
23+
common.mustNotCall());

0 commit comments

Comments
 (0)