-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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 <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
- 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]); | ||
} |