1'use strict'; 2 3require('../common'); 4const assert = require('assert'); 5const vm = require('vm'); 6const { AsyncLocalStorage } = require('async_hooks'); 7 8// Regression test for https://github.com/nodejs/node/issues/38781 9 10const context = vm.createContext({ 11 AsyncLocalStorage, 12 assert 13}); 14 15vm.runInContext(` 16 const storage = new AsyncLocalStorage() 17 async function test() { 18 return storage.run({ test: 'vm' }, async () => { 19 assert.strictEqual(storage.getStore().test, 'vm'); 20 await 42; 21 assert.strictEqual(storage.getStore().test, 'vm'); 22 }); 23 } 24 test() 25`, context); 26 27const storage = new AsyncLocalStorage(); 28async function test() { 29 return storage.run({ test: 'main context' }, async () => { 30 assert.strictEqual(storage.getStore().test, 'main context'); 31 await 42; 32 assert.strictEqual(storage.getStore().test, 'main context'); 33 }); 34} 35test(); 36