-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: set PromiseHooks by Environment
The new JS PromiseHooks introduced in the referenced PR are per v8::Context. This meant that code depending on them, such as AsyncLocalStorage, wouldn't behave correctly across vm.Context instances. PromiseHooks are now synchronized across the main Context and any Context created via vm.Context. Refs: #36394 Fixes: #38781 Signed-off-by: Bryan English <[email protected]>
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const vm = require('vm'); | ||
const { AsyncLocalStorage } = require('async_hooks'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/38781 | ||
|
||
const context = vm.createContext({ | ||
AsyncLocalStorage, | ||
assert | ||
}); | ||
|
||
vm.runInContext(` | ||
const storage = new AsyncLocalStorage() | ||
async function test() { | ||
return storage.run({ test: 'vm' }, async () => { | ||
assert.strictEqual(storage.getStore().test, 'vm'); | ||
await 42; | ||
assert.strictEqual(storage.getStore().test, 'vm'); | ||
}); | ||
} | ||
test() | ||
`, context); | ||
|
||
const storage = new AsyncLocalStorage(); | ||
async function test() { | ||
return storage.run({ test: 'main context' }, async () => { | ||
assert.strictEqual(storage.getStore().test, 'main context'); | ||
await 42; | ||
assert.strictEqual(storage.getStore().test, 'main context'); | ||
}); | ||
} | ||
test(); |