From 5c5da1d86f10294906ec8c6f117bb73aa06c46b9 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Wed, 2 Jan 2019 14:07:36 +0100 Subject: [PATCH] Fix passing streams to workers in Safari 9 Safari 9 does not expose the MessagePort object in workers (but does expose it on window, and also exposes MessageChannel in workers). --- src/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.js b/src/util.js index dbc8de3f..3a1f5f7e 100644 --- a/src/util.js +++ b/src/util.js @@ -88,7 +88,7 @@ export default { } return; } - if (typeof MessagePort !== 'undefined' && MessagePort.prototype.isPrototypeOf(value)) { + if (Object.prototype.toString.call(value) === '[object MessagePort]') { throw new Error("Can't transfer the same stream twice."); } util.collectTransferables(value, collection); @@ -104,7 +104,7 @@ export default { restoreStreams: function(obj) { if (Object.prototype.isPrototypeOf(obj) && !Uint8Array.prototype.isPrototypeOf(obj)) { Object.entries(obj).forEach(([key, value]) => { // recursively search all children - if (MessagePort.prototype.isPrototypeOf(value)) { + if (Object.prototype.toString.call(value) === '[object MessagePort]') { obj[key] = new ReadableStream({ pull(controller) { return new Promise(resolve => {