-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks: add constructor check to async-hooks
This fixes the async_hooks.AsyncHook constructor such that it throws an error when provided with falsy values other than undefined. PR-URL: #13096 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
- Loading branch information
1 parent
ef71824
commit 6fb27af
Showing
2 changed files
with
19 additions
and
4 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,15 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
// This tests that using falsy values in createHook throws an error. | ||
|
||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
|
||
for (const badArg of [0, 1, false, true, null, 'hello']) { | ||
for (const field of ['init', 'before', 'after', 'destroy']) { | ||
assert.throws(() => { | ||
async_hooks.createHook({ [field]: badArg }); | ||
}, new RegExp(`^TypeError: ${field} must be a function$`)); | ||
} | ||
} |