Safari: ArrayBuffers are sometimes not `instanceof ArrayBuffer`
See original GitHub issueSummary
I’m storing and retrieving ArrayBuffer objects from IndexedDB, and I noticed that in my test environment, the ArrayBuffer objects are not always instanceof ArrayBuffer
in Safari. As a result, the Buffer package throws the following exception:
TypeError: First argument must be a string, Buffer, ArrayBuffer, Array,or array-like object.
This behavior does not occur in any other web browser.
Detailed Explanation
The test environment is that of the Karma test runner, which uses an iframe
to isolate test code from the runner’s code. As a result, the ArrayBuffer
constructor object in the code’s context is not referentially equivalent to the ArrayBuffer
constructor object in the main window context. This is similar to the age-old Array
problem, where arrays from other contexts are not necessarily instanceof Array
, necessitating the use of Array.isArray
.
Safari chooses the main window’s constructor for the ArrayBuffer
object retrieved from IndexedDB, so it is not an instanceof ArrayBuffer
in the test code’s context.
Here’s a screenshot, just so you know I’m not totally mad here. This is evaluated at a breakpoint in the stack frame that throws the TypeError
:
I do not have a good solution to the problem without resorting to some hack (e.g., is the byteLength
property present?).
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Hi!
I found this bug report while investigating a similar issue (not using the buffer library) and wanted to add two things:
Best regards,
@maximerety Thanks for reminding me of this issue! I just added a minimal complete test case to that bug report.