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.
async_hooks: fix Promises with later enabled hooks
Assign a `PromiseWrap` instance to Promises that do not have one yet when the PromiseHook is being called. Fixes: nodejs#13237
- Loading branch information
Showing
2 changed files
with
34 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/13237 | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const async_hooks = require('async_hooks'); | ||
|
||
const seenEvents = []; | ||
|
||
const p = new Promise((resolve) => resolve(1)); | ||
p.then(() => seenEvents.push('then')); | ||
|
||
const hooks = async_hooks.createHook({ | ||
before: common.mustCall((id) => { | ||
assert.ok(id > 1); | ||
seenEvents.push('before'); | ||
}), | ||
|
||
after: common.mustCall((id) => { | ||
assert.ok(id > 1); | ||
seenEvents.push('after'); | ||
hooks.disable(); | ||
}) | ||
}).enable(); | ||
|
||
setImmediate(() => { | ||
assert.deepStrictEqual(seenEvents, ['before', 'then', 'after']); | ||
}); |