-
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.
lib: make process.binding('util') return only type checkers
Ref: #37485 (review) Ref: #37787 PR-URL: #37819 Refs: #37787 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 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,36 @@ | ||
'use strict'; | ||
const { | ||
ArrayPrototypeFilter, | ||
ArrayPrototypeIncludes, | ||
ObjectFromEntries, | ||
ObjectEntries, | ||
SafeArrayIterator, | ||
} = primordials; | ||
const { types } = require('util'); | ||
|
||
module.exports = { | ||
util() { | ||
return ObjectFromEntries(new SafeArrayIterator(ArrayPrototypeFilter( | ||
ObjectEntries(types), | ||
({ 0: key }) => { | ||
return ArrayPrototypeIncludes([ | ||
'isArrayBuffer', | ||
'isArrayBufferView', | ||
'isAsyncFunction', | ||
'isDataView', | ||
'isDate', | ||
'isExternal', | ||
'isMap', | ||
'isMapIterator', | ||
'isNativeError', | ||
'isPromise', | ||
'isRegExp', | ||
'isSet', | ||
'isSetIterator', | ||
'isTypedArray', | ||
'isUint8Array', | ||
'isAnyArrayBuffer', | ||
], key); | ||
}))); | ||
} | ||
}; |
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'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const util = require('util'); | ||
|
||
const utilBinding = process.binding('util'); | ||
assert.deepStrictEqual( | ||
Object.keys(utilBinding).sort(), | ||
[ | ||
'isAnyArrayBuffer', | ||
'isArrayBuffer', | ||
'isArrayBufferView', | ||
'isAsyncFunction', | ||
'isDataView', | ||
'isDate', | ||
'isExternal', | ||
'isMap', | ||
'isMapIterator', | ||
'isNativeError', | ||
'isPromise', | ||
'isRegExp', | ||
'isSet', | ||
'isSetIterator', | ||
'isTypedArray', | ||
'isUint8Array', | ||
]); | ||
|
||
for (const k of Object.keys(utilBinding)) { | ||
assert.strictEqual(utilBinding[k], util.types[k]); | ||
} |