Skip to content
Permalink
Browse files

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: #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>

Backport-PR-URL: #25446
  • Loading branch information...
BridgeAR authored and addaleax committed Dec 20, 2018
1 parent 207612c commit 6528ce61765619b7b6a08006219bbce7128b710c
@@ -37,7 +37,6 @@ const {
kMaxLength,
kStringMaxLength
} = internalBinding('buffer');
const { isAnyArrayBuffer } = internalBinding('types');
const {
getOwnNonIndexProperties,
propertyFilter: {
@@ -52,6 +51,7 @@ const {
kIsEncodingSymbol
} = require('internal/util');
const {
isAnyArrayBuffer,
isArrayBufferView,
isUint8Array
} = require('internal/util/types');
@@ -178,7 +178,7 @@ function startup() {
// TODO(addaleax): Turn into a full runtime deprecation.
const pendingDeprecation = getOptionValue('--pending-deprecation');
const utilBinding = internalBinding('util');
const types = internalBinding('types');
const types = NativeModule.require('internal/util/types');
for (const name of [
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
@@ -21,11 +21,10 @@ const {
customInspectSymbol: inspect
} = require('internal/util');

const { isArrayBufferView } = require('internal/util/types');

const {
isArrayBuffer
} = internalBinding('types');
isArrayBuffer,
isArrayBufferView
} = require('internal/util/types');

const {
encodeUtf8String
@@ -14,7 +14,7 @@ const {
} = internalBinding('util');
const {
isNativeError
} = internalBinding('types');
} = require('internal/util/types');

const noCrypto = !process.versions.openssl;

@@ -1,9 +1,9 @@
'use strict';

const { compare } = internalBinding('buffer');
const { isArrayBufferView } = require('internal/util/types');
const {
isAnyArrayBuffer,
isArrayBufferView,
isDate,
isMap,
isRegExp,
@@ -15,7 +15,7 @@ const {
isBooleanObject,
isBigIntObject,
isSymbolObject
} = internalBinding('types');
} = require('internal/util/types');
const {
getOwnNonIndexProperties,
propertyFilter: {
@@ -27,8 +27,6 @@ const {
isStackOverflowError
} = require('internal/errors');

const types = internalBinding('types');
Object.assign(types, require('internal/util/types'));
const {
isAnyArrayBuffer,
isArrayBuffer,
@@ -38,6 +36,8 @@ const {
isExternal,
isMap,
isMapIterator,
isModuleNamespaceObject,
isNativeError,
isPromise,
isSet,
isSetIterator,
@@ -61,7 +61,7 @@ const {
isFloat64Array,
isBigInt64Array,
isBigUint64Array
} = types;
} = require('internal/util/types');

const ReflectApply = Reflect.apply;

@@ -386,9 +386,9 @@ function getKeys(value, showHidden) {
try {
keys = Object.keys(value);
} catch (err) {
if (types.isNativeError(err) &&
if (isNativeError(err) &&
err.name === 'ReferenceError' &&
types.isModuleNamespaceObject(value)) {
isModuleNamespaceObject(value)) {
keys = Object.getOwnPropertyNames(value);
} else {
throw err;
@@ -700,7 +700,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
} else if (isWeakMap(value)) {
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
} else if (types.isModuleNamespaceObject(value)) {
} else if (isModuleNamespaceObject(value)) {
braces[0] = `[${tag}] {`;
formatter = formatNamespaceObject;
skip = true;
@@ -887,7 +887,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
kObjectType);
} catch (err) {
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
if (!(isNativeError(err) && err.name === 'ReferenceError')) {
throw err;
}
// Use the existing functionality. This makes sure the indentation and
@@ -70,6 +70,7 @@ function isBigUint64Array(value) {
}

module.exports = {
...internalBinding('types'),
isArrayBufferView,
isTypedArray,
isUint8Array,
@@ -31,13 +31,7 @@ const {
const { validateNumber } = require('internal/validators');
const { TextDecoder, TextEncoder } = require('internal/encoding');
const { isBuffer } = require('buffer').Buffer;

const types = internalBinding('types');
Object.assign(types, require('internal/util/types'));
const {
isRegExp,
isDate,
} = types;
const types = require('internal/util/types');

const {
deprecate,
@@ -433,9 +427,9 @@ module.exports = exports = {
isString,
isSymbol,
isUndefined,
isRegExp,
isRegExp: types.isRegExp,
isObject,
isDate,
isDate: types.isDate,
isError(e) {
return objectToString(e) === '[object Error]' || e instanceof Error;
},

0 comments on commit 6528ce6

Please sign in to comment.
You can’t perform that action at this time.