Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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
with
74 additions
and 0 deletions.
| @@ -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); | ||
| }))); | ||
| } | ||
| }; |
| @@ -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]); | ||
| } |

