Skip to content

Commit 6528ce6

Browse files
BridgeARaddaleax
authored andcommittedJan 14, 2019
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]> Backport-PR-URL: #25446
1 parent 207612c commit 6528ce6

File tree

8 files changed

+19
-25
lines changed

8 files changed

+19
-25
lines changed
 

‎lib/buffer.js

+1-1
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

+1-1
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

+3-4
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

+1-1
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

+2-2
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

+7-7
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

@@ -386,9 +386,9 @@ function getKeys(value, showHidden) {
386386
try {
387387
keys = Object.keys(value);
388388
} catch (err) {
389-
if (types.isNativeError(err) &&
389+
if (isNativeError(err) &&
390390
err.name === 'ReferenceError' &&
391-
types.isModuleNamespaceObject(value)) {
391+
isModuleNamespaceObject(value)) {
392392
keys = Object.getOwnPropertyNames(value);
393393
} else {
394394
throw err;
@@ -700,7 +700,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
700700
} else if (isWeakMap(value)) {
701701
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
702702
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
703-
} else if (types.isModuleNamespaceObject(value)) {
703+
} else if (isModuleNamespaceObject(value)) {
704704
braces[0] = `[${tag}] {`;
705705
formatter = formatNamespaceObject;
706706
skip = true;
@@ -887,7 +887,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
887887
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
888888
kObjectType);
889889
} catch (err) {
890-
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
890+
if (!(isNativeError(err) && err.name === 'ReferenceError')) {
891891
throw err;
892892
}
893893
// Use the existing functionality. This makes sure the indentation and

‎lib/internal/util/types.js

+1
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

+3-9
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)
Please sign in to comment.