-
-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safari: ArrayBuffers are sometimes not instanceof ArrayBuffer
#166
Comments
Fixes: #166 ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check but they should be treated as valid.
Interesting... Please see this PR with a potential solution: #170 Let me know if that works for you. If so, I'll merge it and do a new release. |
I want to agree with you, but I can't really blame JavaScript on this one! With that said, it seems like the other browsers do not have this issue; perhaps they already use the appropriate constructor object from the context in which programs invoke native APIs that create
I just ran my test suite against it, and it appears to work wonderfully!
Thanks for fixing this! |
Released as 5.0.7 |
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 sharing. Hope it gets fixed one day so we can remove this hack! |
@maximerety Thanks for reminding me of this issue! I just added a minimal complete test case to that bug report. |
…views and array buffers. Using instanceof to determine ArrayBuffers is fraught with problems in Javascript. See, for example, lodash’s implementation of isArrayBuffer, or the many isArrayBuffer libraries out there. Apparently, ArrayBuffers from a different context (like an iframe, or perhaps something in a test setup) so instanceof won’t work always. See feross/buffer#166 for some more examples.
Fixes: feross/buffer#166 ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check but they should be treated as valid.
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: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, theArrayBuffer
constructor object in the code's context is not referentially equivalent to theArrayBuffer
constructor object in the main window context. This is similar to the age-oldArray
problem, where arrays from other contexts are not necessarilyinstanceof Array
, necessitating the use ofArray.isArray
.Safari chooses the main window's constructor for the
ArrayBuffer
object retrieved from IndexedDB, so it is not aninstanceof 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?).The text was updated successfully, but these errors were encountered: