Skip to content

Commit 5ac30c9

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: #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]>
1 parent d385e2c commit 5ac30c9

8 files changed

Lines changed: 19 additions & 25 deletions

File tree

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
@@ -228,7 +228,7 @@ function startup() {
228228
// TODO(addaleax): Turn into a full runtime deprecation.
229229
const pendingDeprecation = getOptionValue('--pending-deprecation');
230230
const utilBinding = internalBinding('util');
231-
const types = internalBinding('types');
231+
const types = NativeModule.require('internal/util/types');
232232
for (const name of [
233233
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
234234
'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 { errmap } = internalBinding('uv');
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;
@@ -693,7 +693,7 @@ function formatRaw(ctx, value, recurseTimes) {
693693
} else if (isWeakMap(value)) {
694694
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
695695
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
696-
} else if (types.isModuleNamespaceObject(value)) {
696+
} else if (isModuleNamespaceObject(value)) {
697697
braces[0] = `[${tag}] {`;
698698
formatter = formatNamespaceObject;
699699
skip = true;
@@ -880,7 +880,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
880880
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
881881
kObjectType);
882882
} catch (err) {
883-
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
883+
if (!(isNativeError(err) && err.name === 'ReferenceError')) {
884884
throw err;
885885
}
886886
// 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,
@@ -432,9 +426,9 @@ module.exports = exports = {
432426
isString,
433427
isSymbol,
434428
isUndefined,
435-
isRegExp,
429+
isRegExp: types.isRegExp,
436430
isObject,
437-
isDate,
431+
isDate: types.isDate,
438432
isError(e) {
439433
return objectToString(e) === '[object Error]' || e instanceof Error;
440434
},

0 commit comments

Comments
 (0)