0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-domain-vm-promise-isolation.js
Stephen Belanger 660d17dde7
domain: fix vm promise tracking while keeping isolation
PR-URL: https://github.com/nodejs/node/pull/43556
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2022-07-14 12:05:50 +01:00

29 lines
710 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const domain = require('domain');
const vm = require('vm');
// A promise created in a VM should not include a domain field but
// domains should still be able to propagate through them.
//
// See; https://github.com/nodejs/node/issues/40999
const context = vm.createContext({});
function run(code) {
const d = domain.createDomain();
d.run(common.mustCall(() => {
const p = vm.runInContext(code, context)();
assert.strictEqual(p.domain, undefined);
p.then(common.mustCall(() => {
assert.strictEqual(process.domain, d);
}));
}));
}
for (let i = 0; i < 1000; i++) {
run('async () => null');
}