From ca86e34f5557bd58b5ac81a2b716e52d7562b661 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 2 Jan 2021 11:01:37 -0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/36744 Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig --- lib/internal/util/comparisons.js | 45 +++----------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 0bc46257e829fc..ed8ddf6ad321d8 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -44,15 +44,6 @@ const { isSymbolObject, isFloat32Array, isFloat64Array, - isUint8Array, - isUint8ClampedArray, - isUint16Array, - isUint32Array, - isInt8Array, - isInt16Array, - isInt32Array, - isBigInt64Array, - isBigUint64Array } = types; const { getOwnNonIndexProperties, @@ -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 @@ -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;