Skip to content

Commit

Permalink
relax check for webworker transferability
Browse files Browse the repository at this point in the history
In some browser versions, objects can be transfered even though they don't pass the check for `instanceof ArrayBuffer`. We're going to use a more forgiving check that follows a duck-typing approach.
  • Loading branch information
kkaefer committed Oct 14, 2019
1 parent def961a commit dc1e898
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/util/web_worker_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ for (const name in expressions) {
register(`Expression_${name}`, expressions[name]);
}

function isArrayBuffer(val: any): boolean {
return val && typeof ArrayBuffer !== 'undefined' &&
(val instanceof ArrayBuffer ||
(val.constructor && val.constructor.name === 'ArrayBuffer'));
}

/**
* Serialize the given object for transfer to or from a web worker.
*
Expand Down Expand Up @@ -128,7 +134,7 @@ export function serialize(input: mixed, transferables?: Array<Transferable>): Se
return input;
}

if (input instanceof ArrayBuffer) {
if (isArrayBuffer(input)) {
if (transferables) {
transferables.push(input);
}
Expand Down Expand Up @@ -218,7 +224,7 @@ export function deserialize(input: Serialized): mixed {
input instanceof String ||
input instanceof Date ||
input instanceof RegExp ||
input instanceof ArrayBuffer ||
isArrayBuffer(input) ||
ArrayBuffer.isView(input) ||
input instanceof ImageData) {
return input;
Expand Down

0 comments on commit dc1e898

Please sign in to comment.