node/lib/internal/legacy/processbinding.js
Joyee Cheung e1fa85133f
src: implement natives binding without special casing
This patch removes special case in the internal binding loader
for natives, and implements it using the builtins internal
binding. Internally we do not actually need the natives binding,
so implement it as a legacy wrapper instead.

PR-URL: https://github.com/nodejs/node/pull/48186
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-06-09 15:32:55 +02:00

45 lines
1.1 KiB
JavaScript

'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);
})));
},
natives() {
const { natives: result, configs } = internalBinding('builtins');
// Legacy feature: process.binding('natives').config contains stringified
// config.gypi. We do not use this object internally so it's fine to mutate
// it.
result.configs = configs;
return result;
},
};