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).
This commit is contained in:
Daniel Huigens 2019-01-02 14:07:36 +01:00
parent ae1af189ef
commit 5c5da1d86f

View File

@ -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 => {