forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
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: nodejs#36394 Fixes: nodejs#38781 Signed-off-by: Bryan English <[email protected]> PR-URL: nodejs#38821 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
- Loading branch information
Showing
6 changed files
with
106 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
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(); |