Skip to content

Commit

Permalink
util: remove unreachable defensive coding
Browse files Browse the repository at this point in the history
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 <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Trott authored and danielleadams committed Jan 12, 2021
1 parent 8f672eb commit bff201a
Showing 1 changed file with 3 additions and 42 deletions.
45 changes: 3 additions & 42 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ const {
isSymbolObject,
isFloat32Array,
isFloat64Array,
isUint8Array,
isUint8ClampedArray,
isUint16Array,
isUint32Array,
isInt8Array,
isInt16Array,
isInt32Array,
isBigInt64Array,
isBigUint64Array
} = types;
const {
getOwnNonIndexProperties,
Expand Down Expand Up @@ -126,38 +117,6 @@ function isEqualBoxedPrimitive(val1, val2) {
assert.fail(`Unknown boxed type ${val1}`);
}

function isIdenticalTypedArrayType(a, b) {
// Fast path to reduce type checks in the common case.
const check = types[`is${TypedArrayPrototypeGetSymbolToStringTag(a)}`];
if (check !== undefined && check(a)) {
return check(b);
}
// Manipulated Symbol.toStringTag.
for (const check of [
isUint16Array,
isUint32Array,
isInt8Array,
isInt16Array,
isInt32Array,
isFloat32Array,
isFloat64Array,
isBigInt64Array,
isBigUint64Array,
isUint8ClampedArray,
isUint8Array
]) {
if (check(a)) {
return check(b);
}
}
/* c8 ignore next 4 */
assert.fail(
'Unknown TypedArray type checking ' +
`${TypedArrayPrototypeGetSymbolToStringTag(a)} ${a}\n` +
`and ${TypedArrayPrototypeGetSymbolToStringTag(b)} ${b}`
);
}

// Notes: Type tags are historical [[Class]] properties that can be set by
// FunctionTemplate::SetClassName() in C++ or Symbol.toStringTag in JS
// and retrieved using Object.prototype.toString.call(obj) in JS
Expand Down Expand Up @@ -241,8 +200,10 @@ function innerDeepEqual(val1, val2, strict, memos) {
return false;
}
} else if (isArrayBufferView(val1)) {
if (!isIdenticalTypedArrayType(val1, val2))
if (TypedArrayPrototypeGetSymbolToStringTag(val1) !==
TypedArrayPrototypeGetSymbolToStringTag(val2)) {
return false;
}
if (!strict && (isFloat32Array(val1) || isFloat64Array(val1))) {
if (!areSimilarFloatArrays(val1, val2)) {
return false;
Expand Down

0 comments on commit bff201a

Please sign in to comment.