Skip to content

Commit 7df9558

Browse files
LiviaMedeirosRafaelGSS
authored andcommitted
assert: support Float16Array in loose deep equality checks
PR-URL: #57881 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent b4f6aa8 commit 7df9558

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/internal/util/comparisons.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const {
110110
isBooleanObject,
111111
isBigIntObject,
112112
isSymbolObject,
113+
isFloat16Array,
113114
isFloat32Array,
114115
isFloat64Array,
115116
isKeyObject,
@@ -315,7 +316,8 @@ function objectComparisonStart(val1, val2, mode, memos) {
315316
if (!isPartialArrayBufferView(val1, val2)) {
316317
return false;
317318
}
318-
} else if (mode === kLoose && (isFloat32Array(val1) || isFloat64Array(val1))) {
319+
} else if (mode === kLoose &&
320+
(isFloat32Array(val1) || isFloat64Array(val1) || isFloat16Array(val1))) {
319321
if (!areSimilarFloatArrays(val1, val2)) {
320322
return false;
321323
}

test/parallel/test-assert-partial-deep-equal.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// Flags: --js-float16array
2+
// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
13
'use strict';
24

35
const common = require('../common');
46
const vm = require('node:vm');
57
const assert = require('node:assert');
68
const { describe, it } = require('node:test');
79

10+
// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
11+
const { Float16Array } = globalThis;
12+
813
const x = ['x'];
914

1015
function createCircularObject() {
@@ -494,6 +499,11 @@ describe('Object Comparison Tests', () => {
494499
actual: { dataView: new Uint8Array(3) },
495500
expected: { dataView: new DataView(new ArrayBuffer(3)) },
496501
},
502+
{
503+
description: 'throws when comparing Float16Array([+0.0]) with Float16Array([-0.0])',
504+
actual: new Float16Array([+0.0]),
505+
expected: new Float16Array([-0.0]),
506+
},
497507
{
498508
description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])',
499509
actual: new Float32Array([+0.0]),

test/parallel/test-assert-typedarray-deepequal.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
// Flags: --js-float16array
2+
// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
13
'use strict';
24

35
require('../common');
46
const assert = require('assert');
57
const { test, suite } = require('node:test');
68

9+
// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
10+
const { Float16Array } = globalThis;
11+
712
function makeBlock(f) {
813
const args = Array.prototype.slice.call(arguments, 1);
914
return function() {
@@ -20,6 +25,7 @@ suite('equalArrayPairs', () => {
2025
[new Int8Array(1e5), new Int8Array(1e5)],
2126
[new Int16Array(1e5), new Int16Array(1e5)],
2227
[new Int32Array(1e5), new Int32Array(1e5)],
28+
[new Float16Array(1e5), new Float16Array(1e5)],
2329
[new Float32Array(1e5), new Float32Array(1e5)],
2430
[new Float64Array(1e5), new Float64Array(1e5)],
2531
[new Float32Array([+0.0]), new Float32Array([+0.0])],
@@ -41,6 +47,7 @@ suite('equalArrayPairs', () => {
4147

4248
suite('looseEqualArrayPairs', () => {
4349
const looseEqualArrayPairs = [
50+
[new Float16Array([+0.0]), new Float16Array([-0.0])],
4451
[new Float32Array([+0.0]), new Float32Array([-0.0])],
4552
[new Float64Array([+0.0]), new Float64Array([-0.0])],
4653
];
@@ -71,6 +78,8 @@ suite('notEqualArrayPairs', () => {
7178
[new Int16Array([0]), new Uint16Array([256])],
7279
[new Int16Array([-256]), new Uint16Array([0xff00])], // same bits
7380
[new Int32Array([-256]), new Uint32Array([0xffffff00])], // ditto
81+
[new Float16Array([0.1]), new Float16Array([0.0])],
82+
[new Float16Array([0.1]), new Float16Array([0.1, 0.2])],
7483
[new Float32Array([0.1]), new Float32Array([0.0])],
7584
[new Float32Array([0.1]), new Float32Array([0.1, 0.2])],
7685
[new Float64Array([0.1]), new Float64Array([0.0])],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy