-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
errors: extract type detection & use in
ERR_INVALID_RETURN_VALUE
PR-URL: #43558 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
78bedcd
commit 9f75f26
Showing
4 changed files
with
187 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Flags: --expose-internals | ||
|
||
import '../common/index.mjs'; | ||
import { strictEqual } from 'node:assert'; | ||
import errorsModule from 'internal/errors'; | ||
|
||
|
||
const { determineSpecificType } = errorsModule; | ||
|
||
strictEqual( | ||
determineSpecificType(1n), | ||
'type bigint (1n)', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(false), | ||
'type boolean (false)', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(2), | ||
'type number (2)', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(NaN), | ||
'type number (NaN)', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(Infinity), | ||
'type number (Infinity)', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(Object.create(null)), | ||
'[Object: null prototype] {}', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(''), | ||
"type string ('')", | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(Symbol('foo')), | ||
'type symbol (Symbol(foo))', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(function foo() {}), | ||
'function foo', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(null), | ||
'null', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(undefined), | ||
'undefined', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType([]), | ||
'an instance of Array', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(new Array()), | ||
'an instance of Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new BigInt64Array()), | ||
'an instance of BigInt64Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new BigUint64Array()), | ||
'an instance of BigUint64Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Int8Array()), | ||
'an instance of Int8Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Int16Array()), | ||
'an instance of Int16Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Int32Array()), | ||
'an instance of Int32Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Float32Array()), | ||
'an instance of Float32Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Float64Array()), | ||
'an instance of Float64Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Uint8Array()), | ||
'an instance of Uint8Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Uint8ClampedArray()), | ||
'an instance of Uint8ClampedArray', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Uint16Array()), | ||
'an instance of Uint16Array', | ||
); | ||
strictEqual( | ||
determineSpecificType(new Uint32Array()), | ||
'an instance of Uint32Array', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(new Date()), | ||
'an instance of Date', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(new Map()), | ||
'an instance of Map', | ||
); | ||
strictEqual( | ||
determineSpecificType(new WeakMap()), | ||
'an instance of WeakMap', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType({}), | ||
'an instance of Object', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(Promise.resolve('foo')), | ||
'an instance of Promise', | ||
); | ||
|
||
strictEqual( | ||
determineSpecificType(new Set()), | ||
'an instance of Set', | ||
); | ||
strictEqual( | ||
determineSpecificType(new WeakSet()), | ||
'an instance of WeakSet', | ||
); |
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