Open Jarred-Sumner opened 3 years ago
We need the instanceof
check for Node.js, not the browser. It's totally ok to have a if (global.Buffer !== undefined && cur instanceof Buffer)
check.
Would you like to send a Pull Request to address this issue? Remember to add unit tests.
Probably should not use global
but the standardized globalThis
for Buffer
detection. Thought I'm not sure if it's safe to use on node < 12 which does not have globalThis
.
Currently, if you any properties cloned with rfdc are an
ArrayBuffer
in a browser, this exception will appear unless you have polyfilled Buffer:It looks like the responsible code is here:
There are two issues with this function:
ArrayBuffer
, when it only needs to clone the section relevant to the view. In other words,return cur.slice()
would work, asTypedArray.prototype.slice
will copy the section of the underlyingArrayBuffer
.Buffer
extendsUint8Array
[0], you don't need to check ifcur
is aBuffer
..slice
on aBuffer
will return aBuffer
[0]: "The
Buffer
class is a subclass of JavaScript'sUint8Array
class and extends it with methods that cover additional use cases." - https://nodejs.org/api/buffer.html#buffer_buffer