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 <bryan@bryanenglish.com> PR-URL: nodejs#38821 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
- 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(); |