xref: /third_party/node/test/parallel/test-domain-vm-promise-isolation.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst domain = require('domain');
61cb0ef41Sopenharmony_ciconst vm = require('vm');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// A promise created in a VM should not include a domain field but
91cb0ef41Sopenharmony_ci// domains should still be able to propagate through them.
101cb0ef41Sopenharmony_ci//
111cb0ef41Sopenharmony_ci// See; https://github.com/nodejs/node/issues/40999
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst context = vm.createContext({});
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction run(code) {
161cb0ef41Sopenharmony_ci  const d = domain.createDomain();
171cb0ef41Sopenharmony_ci  d.run(common.mustCall(() => {
181cb0ef41Sopenharmony_ci    const p = vm.runInContext(code, context)();
191cb0ef41Sopenharmony_ci    assert.strictEqual(p.domain, undefined);
201cb0ef41Sopenharmony_ci    p.then(common.mustCall(() => {
211cb0ef41Sopenharmony_ci      assert.strictEqual(process.domain, d);
221cb0ef41Sopenharmony_ci    }));
231cb0ef41Sopenharmony_ci  }));
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cifor (let i = 0; i < 1000; i++) {
271cb0ef41Sopenharmony_ci  run('async () => null');
281cb0ef41Sopenharmony_ci}
29

Indexes created Thu Nov 07 10:32:03 CST 2024