Skip to content

Commit bff201a

Browse files
Trottdanielleadams
authored andcommitted
util: remove unreachable defensive coding
Now that we are using primordials in the first part of isIdenticalTypedArrayType(), the defensive coding to get the correct result (when Symbol.toStringTag is manipulated) is no longer reachable or necessary. Remove the code. Refs: https://coverage.nodejs.org/coverage-873d21cdc1266273/lib/internal/util/comparisons.js.html#L135 PR-URL: #36744 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 8f672eb commit bff201a

File tree

1 file changed

+3
-42
lines changed

1 file changed

+3
-42
lines changed

lib/internal/util/comparisons.js

+3-42
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ const {
4444
isSymbolObject,
4545
isFloat32Array,
4646
isFloat64Array,
47-
isUint8Array,
48-
isUint8ClampedArray,
49-
isUint16Array,
50-
isUint32Array,
51-
isInt8Array,
52-
isInt16Array,
53-
isInt32Array,
54-
isBigInt64Array,
55-
isBigUint64Array
5647
} = types;
5748
const {
5849
getOwnNonIndexProperties,
@@ -126,38 +117,6 @@ function isEqualBoxedPrimitive(val1, val2) {
126117
assert.fail(`Unknown boxed type ${val1}`);
127118
}
128119

129-
function isIdenticalTypedArrayType(a, b) {
130-
// Fast path to reduce type checks in the common case.
131-
const check = types[`is${TypedArrayPrototypeGetSymbolToStringTag(a)}`];
132-
if (check !== undefined && check(a)) {
133-
return check(b);
134-
}
135-
// Manipulated Symbol.toStringTag.
136-
for (const check of [
137-
isUint16Array,
138-
isUint32Array,
139-
isInt8Array,
140-
isInt16Array,
141-
isInt32Array,
142-
isFloat32Array,
143-
isFloat64Array,
144-
isBigInt64Array,
145-
isBigUint64Array,
146-
isUint8ClampedArray,
147-
isUint8Array
148-
]) {
149-
if (check(a)) {
150-
return check(b);
151-
}
152-
}
153-
/* c8 ignore next 4 */
154-
assert.fail(
155-
'Unknown TypedArray type checking ' +
156-
`${TypedArrayPrototypeGetSymbolToStringTag(a)} ${a}\n` +
157-
`and ${TypedArrayPrototypeGetSymbolToStringTag(b)} ${b}`
158-
);
159-
}
160-
161120
// Notes: Type tags are historical [[Class]] properties that can be set by
162121
// FunctionTemplate::SetClassName() in C++ or Symbol.toStringTag in JS
163122
// and retrieved using Object.prototype.toString.call(obj) in JS
@@ -241,8 +200,10 @@ function innerDeepEqual(val1, val2, strict, memos) {
241200
return false;
242201
}
243202
} else if (isArrayBufferView(val1)) {
244-
if (!isIdenticalTypedArrayType(val1, val2))
203+
if (TypedArrayPrototypeGetSymbolToStringTag(val1) !==
204+
TypedArrayPrototypeGetSymbolToStringTag(val2)) {
245205
return false;
206+
}
246207
if (!strict && (isFloat32Array(val1) || isFloat64Array(val1))) {
247208
if (!areSimilarFloatArrays(val1, val2)) {
248209
return false;

0 commit comments

Comments
 (0)