Skip to content

Commit

Permalink
Use ArrayBuffer.isView rather than instanceof to distinguish between …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jasongrout committed Aug 28, 2020
1 parent 9352d30 commit 901f78a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/services/src/kernel/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function serializeBinary(msg: KernelMessage.IMessage): ArrayBuffer {
// msg.buffers elements could be either views or ArrayBuffers
// buffers elements are ArrayBuffers
const b: any = origBuffers[i];
buffers.push(b instanceof ArrayBuffer ? b : b.buffer);
buffers.push(ArrayBuffer.isView(b) ? b.buffer : b);
}
const nbufs = buffers.length;
offsets.push(4 * (nbufs + 1));
Expand Down

0 comments on commit 901f78a

Please sign in to comment.