Skip to content
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

Relax check for webworker transferability #8868

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/util/web_worker_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ 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,9 +133,9 @@ export function serialize(input: mixed, transferables?: Array<Transferable>): Se
return input;
}

if (input instanceof ArrayBuffer) {
if (isArrayBuffer(input)) {
if (transferables) {
transferables.push(input);
transferables.push(((input: any): ArrayBuffer));
}
return input;
}
Expand Down Expand Up @@ -218,7 +223,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