question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Safari: ArrayBuffers are sometimes not `instanceof ArrayBuffer`

See original GitHub issue

Summary

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: screen shot 2017-07-22 at 11 06 09 pm

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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
maximeretycommented, May 23, 2018

Hi!

I found this bug report while investigating a similar issue (not using the buffer library) and wanted to add two things:

Best regards,

1reaction
jvilkcommented, May 23, 2018

@maximerety Thanks for reminding me of this issue! I just added a minimal complete test case to that bug report.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ArrayBuffer - JavaScript - MDN Web Docs
Chrome Edge ArrayBuffer Full support. Chrome7. Toggle history Full support. Edge12. Tog... @@species Full support. Chrome51. Toggle history Full support. Edge13. Tog... ArrayBuffer() constructor Full support....
Read more >
Check for an instance of ArrayBufferView? - Stack Overflow
I would use either: function isAbv(value) { return value && value.buffer instanceof ArrayBuffer && value.byteLength !== undefined; }.
Read more >
194268 – Safari does not free ArrayBuffers being transferred ...
Safari frequently runs out of memory running webapps using WebGL libraries such as Mapbox GL-JS and Tangram that transfer large number of ...
Read more >
Typed Arrays and ArrayBuffers / Jules Blom - Observable
An ArrayBuffer is an object representing a chunk of fixed-length binary data; it has no format to speak of and offers no mechanism...
Read more >
datatables.txt - tds.ms
_data; // when reading an arraybuffer, the CompressedObject mechanism will ... It is not necessary to compare scan[2] and match[2] since they *...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found