lib: expose all type checks from the internal types module
Combine all type checks on the internal types module and do not use the types binding anywhere else anymore. This makes sure all of those checks exist when required. PR-URL: https://github.com/nodejs/node/pull/25149 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
parent
d385e2cc5a
commit
5ac30c99a9
@ -37,7 +37,6 @@ const {
|
|||||||
kMaxLength,
|
kMaxLength,
|
||||||
kStringMaxLength
|
kStringMaxLength
|
||||||
} = internalBinding('buffer');
|
} = internalBinding('buffer');
|
||||||
const { isAnyArrayBuffer } = internalBinding('types');
|
|
||||||
const {
|
const {
|
||||||
getOwnNonIndexProperties,
|
getOwnNonIndexProperties,
|
||||||
propertyFilter: {
|
propertyFilter: {
|
||||||
@ -52,6 +51,7 @@ const {
|
|||||||
kIsEncodingSymbol
|
kIsEncodingSymbol
|
||||||
} = require('internal/util');
|
} = require('internal/util');
|
||||||
const {
|
const {
|
||||||
|
isAnyArrayBuffer,
|
||||||
isArrayBufferView,
|
isArrayBufferView,
|
||||||
isUint8Array
|
isUint8Array
|
||||||
} = require('internal/util/types');
|
} = require('internal/util/types');
|
||||||
|
@ -228,7 +228,7 @@ function startup() {
|
|||||||
// TODO(addaleax): Turn into a full runtime deprecation.
|
// TODO(addaleax): Turn into a full runtime deprecation.
|
||||||
const pendingDeprecation = getOptionValue('--pending-deprecation');
|
const pendingDeprecation = getOptionValue('--pending-deprecation');
|
||||||
const utilBinding = internalBinding('util');
|
const utilBinding = internalBinding('util');
|
||||||
const types = internalBinding('types');
|
const types = NativeModule.require('internal/util/types');
|
||||||
for (const name of [
|
for (const name of [
|
||||||
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
|
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
|
||||||
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
|
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
|
||||||
|
@ -21,11 +21,10 @@ const {
|
|||||||
customInspectSymbol: inspect
|
customInspectSymbol: inspect
|
||||||
} = require('internal/util');
|
} = require('internal/util');
|
||||||
|
|
||||||
const { isArrayBufferView } = require('internal/util/types');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isArrayBuffer
|
isArrayBuffer,
|
||||||
} = internalBinding('types');
|
isArrayBufferView
|
||||||
|
} = require('internal/util/types');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
encodeUtf8String
|
encodeUtf8String
|
||||||
|
@ -14,7 +14,7 @@ const {
|
|||||||
} = internalBinding('util');
|
} = internalBinding('util');
|
||||||
const {
|
const {
|
||||||
isNativeError
|
isNativeError
|
||||||
} = internalBinding('types');
|
} = require('internal/util/types');
|
||||||
|
|
||||||
const { errmap } = internalBinding('uv');
|
const { errmap } = internalBinding('uv');
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { compare } = internalBinding('buffer');
|
const { compare } = internalBinding('buffer');
|
||||||
const { isArrayBufferView } = require('internal/util/types');
|
|
||||||
const {
|
const {
|
||||||
isAnyArrayBuffer,
|
isAnyArrayBuffer,
|
||||||
|
isArrayBufferView,
|
||||||
isDate,
|
isDate,
|
||||||
isMap,
|
isMap,
|
||||||
isRegExp,
|
isRegExp,
|
||||||
@ -15,7 +15,7 @@ const {
|
|||||||
isBooleanObject,
|
isBooleanObject,
|
||||||
isBigIntObject,
|
isBigIntObject,
|
||||||
isSymbolObject
|
isSymbolObject
|
||||||
} = internalBinding('types');
|
} = require('internal/util/types');
|
||||||
const {
|
const {
|
||||||
getOwnNonIndexProperties,
|
getOwnNonIndexProperties,
|
||||||
propertyFilter: {
|
propertyFilter: {
|
||||||
|
@ -27,8 +27,6 @@ const {
|
|||||||
isStackOverflowError
|
isStackOverflowError
|
||||||
} = require('internal/errors');
|
} = require('internal/errors');
|
||||||
|
|
||||||
const types = internalBinding('types');
|
|
||||||
Object.assign(types, require('internal/util/types'));
|
|
||||||
const {
|
const {
|
||||||
isAnyArrayBuffer,
|
isAnyArrayBuffer,
|
||||||
isArrayBuffer,
|
isArrayBuffer,
|
||||||
@ -38,6 +36,8 @@ const {
|
|||||||
isExternal,
|
isExternal,
|
||||||
isMap,
|
isMap,
|
||||||
isMapIterator,
|
isMapIterator,
|
||||||
|
isModuleNamespaceObject,
|
||||||
|
isNativeError,
|
||||||
isPromise,
|
isPromise,
|
||||||
isSet,
|
isSet,
|
||||||
isSetIterator,
|
isSetIterator,
|
||||||
@ -61,7 +61,7 @@ const {
|
|||||||
isFloat64Array,
|
isFloat64Array,
|
||||||
isBigInt64Array,
|
isBigInt64Array,
|
||||||
isBigUint64Array
|
isBigUint64Array
|
||||||
} = types;
|
} = require('internal/util/types');
|
||||||
|
|
||||||
const ReflectApply = Reflect.apply;
|
const ReflectApply = Reflect.apply;
|
||||||
|
|
||||||
@ -385,9 +385,9 @@ function getKeys(value, showHidden) {
|
|||||||
try {
|
try {
|
||||||
keys = Object.keys(value);
|
keys = Object.keys(value);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (types.isNativeError(err) &&
|
if (isNativeError(err) &&
|
||||||
err.name === 'ReferenceError' &&
|
err.name === 'ReferenceError' &&
|
||||||
types.isModuleNamespaceObject(value)) {
|
isModuleNamespaceObject(value)) {
|
||||||
keys = Object.getOwnPropertyNames(value);
|
keys = Object.getOwnPropertyNames(value);
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
@ -693,7 +693,7 @@ function formatRaw(ctx, value, recurseTimes) {
|
|||||||
} else if (isWeakMap(value)) {
|
} else if (isWeakMap(value)) {
|
||||||
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
|
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
|
||||||
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
|
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
|
||||||
} else if (types.isModuleNamespaceObject(value)) {
|
} else if (isModuleNamespaceObject(value)) {
|
||||||
braces[0] = `[${tag}] {`;
|
braces[0] = `[${tag}] {`;
|
||||||
formatter = formatNamespaceObject;
|
formatter = formatNamespaceObject;
|
||||||
skip = true;
|
skip = true;
|
||||||
@ -880,7 +880,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
|
|||||||
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
|
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
|
||||||
kObjectType);
|
kObjectType);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
|
if (!(isNativeError(err) && err.name === 'ReferenceError')) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// Use the existing functionality. This makes sure the indentation and
|
// Use the existing functionality. This makes sure the indentation and
|
||||||
|
@ -70,6 +70,7 @@ function isBigUint64Array(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
...internalBinding('types'),
|
||||||
isArrayBufferView,
|
isArrayBufferView,
|
||||||
isTypedArray,
|
isTypedArray,
|
||||||
isUint8Array,
|
isUint8Array,
|
||||||
|
12
lib/util.js
12
lib/util.js
@ -31,13 +31,7 @@ const {
|
|||||||
const { validateNumber } = require('internal/validators');
|
const { validateNumber } = require('internal/validators');
|
||||||
const { TextDecoder, TextEncoder } = require('internal/encoding');
|
const { TextDecoder, TextEncoder } = require('internal/encoding');
|
||||||
const { isBuffer } = require('buffer').Buffer;
|
const { isBuffer } = require('buffer').Buffer;
|
||||||
|
const types = require('internal/util/types');
|
||||||
const types = internalBinding('types');
|
|
||||||
Object.assign(types, require('internal/util/types'));
|
|
||||||
const {
|
|
||||||
isRegExp,
|
|
||||||
isDate,
|
|
||||||
} = types;
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
deprecate,
|
deprecate,
|
||||||
@ -432,9 +426,9 @@ module.exports = exports = {
|
|||||||
isString,
|
isString,
|
||||||
isSymbol,
|
isSymbol,
|
||||||
isUndefined,
|
isUndefined,
|
||||||
isRegExp,
|
isRegExp: types.isRegExp,
|
||||||
isObject,
|
isObject,
|
||||||
isDate,
|
isDate: types.isDate,
|
||||||
isError(e) {
|
isError(e) {
|
||||||
return objectToString(e) === '[object Error]' || e instanceof Error;
|
return objectToString(e) === '[object Error]' || e instanceof Error;
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user