11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst vm = require('vm'); 61cb0ef41Sopenharmony_ciconst { AsyncLocalStorage } = require('async_hooks'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/38781 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst context = vm.createContext({ 111cb0ef41Sopenharmony_ci AsyncLocalStorage, 121cb0ef41Sopenharmony_ci assert 131cb0ef41Sopenharmony_ci}); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_civm.runInContext(` 161cb0ef41Sopenharmony_ci const storage = new AsyncLocalStorage() 171cb0ef41Sopenharmony_ci async function test() { 181cb0ef41Sopenharmony_ci return storage.run({ test: 'vm' }, async () => { 191cb0ef41Sopenharmony_ci assert.strictEqual(storage.getStore().test, 'vm'); 201cb0ef41Sopenharmony_ci await 42; 211cb0ef41Sopenharmony_ci assert.strictEqual(storage.getStore().test, 'vm'); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci test() 251cb0ef41Sopenharmony_ci`, context); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst storage = new AsyncLocalStorage(); 281cb0ef41Sopenharmony_ciasync function test() { 291cb0ef41Sopenharmony_ci return storage.run({ test: 'main context' }, async () => { 301cb0ef41Sopenharmony_ci assert.strictEqual(storage.getStore().test, 'main context'); 311cb0ef41Sopenharmony_ci await 42; 321cb0ef41Sopenharmony_ci assert.strictEqual(storage.getStore().test, 'main context'); 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_citest(); 36