diff --git a/src/util/web_worker_transfer.js b/src/util/web_worker_transfer.js index 84a41469bfc..b8aa03c154a 100644 --- a/src/util/web_worker_transfer.js +++ b/src/util/web_worker_transfer.js @@ -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. * @@ -128,7 +134,7 @@ export function serialize(input: mixed, transferables?: Array): Se return input; } - if (input instanceof ArrayBuffer) { + if (isArrayBuffer(input)) { if (transferables) { transferables.push(input); } @@ -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;