Skip to content

Commit 27b8585

Browse files
committed
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: nodejs#25149 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Backport-PR-URL: nodejs#25446
1 parent 68bc42a commit 27b8585

File tree

8 files changed

+19
-25
lines changed

8 files changed

+19
-25
lines changed

lib/buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const {
3737
kMaxLength,
3838
kStringMaxLength
3939
} = internalBinding('buffer');
40-
const { isAnyArrayBuffer } = internalBinding('types');
4140
const {
4241
getOwnNonIndexProperties,
4342
propertyFilter: {
@@ -52,6 +51,7 @@ const {
5251
kIsEncodingSymbol
5352
} = require('internal/util');
5453
const {
54+
isAnyArrayBuffer,
5555
isArrayBufferView,
5656
isUint8Array
5757
} = require('internal/util/types');

lib/internal/bootstrap/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function startup() {
178178
// TODO(addaleax): Turn into a full runtime deprecation.
179179
const pendingDeprecation = getOptionValue('--pending-deprecation');
180180
const utilBinding = internalBinding('util');
181-
const types = internalBinding('types');
181+
const types = NativeModule.require('internal/util/types');
182182
for (const name of [
183183
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
184184
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',

lib/internal/encoding.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ const {
2121
customInspectSymbol: inspect
2222
} = require('internal/util');
2323

24-
const { isArrayBufferView } = require('internal/util/types');
25-
2624
const {
27-
isArrayBuffer
28-
} = internalBinding('types');
25+
isArrayBuffer,
26+
isArrayBufferView
27+
} = require('internal/util/types');
2928

3029
const {
3130
encodeUtf8String

lib/internal/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
} = internalBinding('util');
1515
const {
1616
isNativeError
17-
} = internalBinding('types');
17+
} = require('internal/util/types');
1818

1919
const noCrypto = !process.versions.openssl;
2020

lib/internal/util/comparisons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

33
const { compare } = internalBinding('buffer');
4-
const { isArrayBufferView } = require('internal/util/types');
54
const {
65
isAnyArrayBuffer,
6+
isArrayBufferView,
77
isDate,
88
isMap,
99
isRegExp,
@@ -15,7 +15,7 @@ const {
1515
isBooleanObject,
1616
isBigIntObject,
1717
isSymbolObject
18-
} = internalBinding('types');
18+
} = require('internal/util/types');
1919
const {
2020
getOwnNonIndexProperties,
2121
propertyFilter: {

lib/internal/util/inspect.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const {
2727
isStackOverflowError
2828
} = require('internal/errors');
2929

30-
const types = internalBinding('types');
31-
Object.assign(types, require('internal/util/types'));
3230
const {
3331
isAnyArrayBuffer,
3432
isArrayBuffer,
@@ -38,6 +36,8 @@ const {
3836
isExternal,
3937
isMap,
4038
isMapIterator,
39+
isModuleNamespaceObject,
40+
isNativeError,
4141
isPromise,
4242
isSet,
4343
isSetIterator,
@@ -61,7 +61,7 @@ const {
6161
isFloat64Array,
6262
isBigInt64Array,
6363
isBigUint64Array
64-
} = types;
64+
} = require('internal/util/types');
6565

6666
const ReflectApply = Reflect.apply;
6767

@@ -385,9 +385,9 @@ function getKeys(value, showHidden) {
385385
try {
386386
keys = Object.keys(value);
387387
} catch (err) {
388-
if (types.isNativeError(err) &&
388+
if (isNativeError(err) &&
389389
err.name === 'ReferenceError' &&
390-
types.isModuleNamespaceObject(value)) {
390+
isModuleNamespaceObject(value)) {
391391
keys = Object.getOwnPropertyNames(value);
392392
} else {
393393
throw err;
@@ -696,7 +696,7 @@ function formatRaw(ctx, value, recurseTimes) {
696696
} else if (isWeakMap(value)) {
697697
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
698698
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
699-
} else if (types.isModuleNamespaceObject(value)) {
699+
} else if (isModuleNamespaceObject(value)) {
700700
braces[0] = `[${tag}] {`;
701701
formatter = formatNamespaceObject;
702702
skip = true;
@@ -883,7 +883,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
883883
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
884884
kObjectType);
885885
} catch (err) {
886-
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
886+
if (!(isNativeError(err) && err.name === 'ReferenceError')) {
887887
throw err;
888888
}
889889
// Use the existing functionality. This makes sure the indentation and

lib/internal/util/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function isBigUint64Array(value) {
7070
}
7171

7272
module.exports = {
73+
...internalBinding('types'),
7374
isArrayBufferView,
7475
isTypedArray,
7576
isUint8Array,

lib/util.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ const {
3131
const { validateNumber } = require('internal/validators');
3232
const { TextDecoder, TextEncoder } = require('internal/encoding');
3333
const { isBuffer } = require('buffer').Buffer;
34-
35-
const types = internalBinding('types');
36-
Object.assign(types, require('internal/util/types'));
37-
const {
38-
isRegExp,
39-
isDate,
40-
} = types;
34+
const types = require('internal/util/types');
4135

4236
const {
4337
deprecate,
@@ -433,9 +427,9 @@ module.exports = exports = {
433427
isString,
434428
isSymbol,
435429
isUndefined,
436-
isRegExp,
430+
isRegExp: types.isRegExp,
437431
isObject,
438-
isDate,
432+
isDate: types.isDate,
439433
isError(e) {
440434
return objectToString(e) === '[object Error]' || e instanceof Error;
441435
},

0 commit comments

Comments
 (0)