assert: support Float16Array in loose deep equality checks

PR-URL: https://github.com/nodejs/node/pull/57881
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Livia Medeiros authored and GitHub committed 2025-04-19 17:04:03 +00:00
1 parent c326200458
commit afd318db67
3 files changed
+22 -1

No files matched your search

+3 -1
View File
@@ -110,6 +110,7 @@ const {
isBooleanObject,
isBigIntObject,
isSymbolObject,
isFloat16Array,
isFloat32Array,
isFloat64Array,
isKeyObject,
@@ -315,7 +316,8 @@ function objectComparisonStart(val1, val2, mode, memos) {
if (!isPartialArrayBufferView(val1, val2)) {
return false;
}
} else if (mode === kLoose && (isFloat32Array(val1) || isFloat64Array(val1))) {
} else if (mode === kLoose &&
(isFloat32Array(val1) || isFloat64Array(val1) || isFloat16Array(val1))) {
if (!areSimilarFloatArrays(val1, val2)) {
return false;
}
@@ -1,3 +1,5 @@
// Flags: --js-float16array
// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
'use strict';
const common = require('../common');
@@ -5,6 +7,9 @@ const vm = require('node:vm');
const assert = require('node:assert');
const { describe, it } = require('node:test');
// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
const { Float16Array } = globalThis;
const x = ['x'];
function createCircularObject() {
@@ -494,6 +499,11 @@ describe('Object Comparison Tests', () => {
actual: { dataView: new Uint8Array(3) },
expected: { dataView: new DataView(new ArrayBuffer(3)) },
},
{
description: 'throws when comparing Float16Array([+0.0]) with Float16Array([-0.0])',
actual: new Float16Array([+0.0]),
expected: new Float16Array([-0.0]),
},
{
description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])',
actual: new Float32Array([+0.0]),
@@ -1,9 +1,14 @@
// Flags: --js-float16array
// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
'use strict';
require('../common');
const assert = require('assert');
const { test, suite } = require('node:test');
// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
const { Float16Array } = globalThis;
function makeBlock(f) {
const args = Array.prototype.slice.call(arguments, 1);
return function() {
@@ -20,6 +25,7 @@ suite('equalArrayPairs', () => {
[new Int8Array(1e5), new Int8Array(1e5)],
[new Int16Array(1e5), new Int16Array(1e5)],
[new Int32Array(1e5), new Int32Array(1e5)],
[new Float16Array(1e5), new Float16Array(1e5)],
[new Float32Array(1e5), new Float32Array(1e5)],
[new Float64Array(1e5), new Float64Array(1e5)],
[new Float32Array([+0.0]), new Float32Array([+0.0])],
@@ -41,6 +47,7 @@ suite('equalArrayPairs', () => {
suite('looseEqualArrayPairs', () => {
const looseEqualArrayPairs = [
[new Float16Array([+0.0]), new Float16Array([-0.0])],
[new Float32Array([+0.0]), new Float32Array([-0.0])],
[new Float64Array([+0.0]), new Float64Array([-0.0])],
];
@@ -71,6 +78,8 @@ suite('notEqualArrayPairs', () => {
[new Int16Array([0]), new Uint16Array([256])],
[new Int16Array([-256]), new Uint16Array([0xff00])], // same bits
[new Int32Array([-256]), new Uint32Array([0xffffff00])], // ditto
[new Float16Array([0.1]), new Float16Array([0.0])],
[new Float16Array([0.1]), new Float16Array([0.1, 0.2])],
[new Float32Array([0.1]), new Float32Array([0.0])],
[new Float32Array([0.1]), new Float32Array([0.1, 0.2])],
[new Float64Array([0.1]), new Float64Array([0.0])],