You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I compare two ArrayBuffer variables, the result is always true. Here is a PoC:
import{defaultasassert}from"assert";importdeepEqualfrom"deep-equal";constbuffer1=newArrayBuffer(8);// initial value of 0'sconstbuffer2=newArrayBuffer(8);// initial value of 0'sconstview1=newInt8Array(buffer1);constview2=newInt8Array(buffer2);view1.fill(9);// change all values to 9's//view2.fill(9);//console.dir(buffer1);//console.dir(buffer2);console.log(deepEqual(buffer1,buffer2));assert.deepEqual(buffer1,buffer2);//assert.deepStrictEqual(buffer1, buffer2);
deepEqual() returns true while Node.js built-in assert.deepEqual() fails correctly with the following:
One options to fix this would be to test if the value is of type ArrayBuffer, then create a temporary view of it and compare this view. This works correctly with deepEqual(). However, there may be a more generic fix which I'm unaware of.
The text was updated successfully, but these errors were encountered:
We indeed don't have any special support for ArrayBuffers, so it treats them as regular objects.
You should already be able to compare view1 and view2, at least :-)
As for creating a temporary typed array around the buffers, would that work no matter the length of the buffers? or would i need to always make a Uint8Array to ensure that it did work?
I'm not an expert in JavaScript but my here is my research.
Docs say that ArrayBuffer is an array of bytes, often referred to in other languages as a "byte array". This means that its internal representation is of integer elements between 0 and 255 which is also confirmed if we dump a new ArrayBuffer(8):
Hello,
If I compare two
ArrayBuffer
variables, the result is alwaystrue
. Here is a PoC:deepEqual()
returnstrue
while Node.js built-inassert.deepEqual()
fails correctly with the following:One options to fix this would be to test if the value is of type
ArrayBuffer
, then create a temporaryview
of it and compare this view. This works correctly withdeepEqual()
. However, there may be a more generic fix which I'm unaware of.The text was updated successfully, but these errors were encountered: