Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Jul 6, 2018
1 parent 8173466 commit 9f5d1fe
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,26 @@ var PromiseWorker = function () {
});
}
} else {
if (worker instanceof Worker) {
// The following if statement used to check `worker instanceof Worker` but I have recieved
// reports that in some weird cases, Safari will inappropriately return false for that, even
// in obvious cases like:
//
// blob = new Blob(["self.onmessage = function() {};"], { type: "text/javascript" });
// worker = new Worker(window.URL.createObjectURL(blob));
// console.log(worker instanceof Worker);
//
// So instead, let's do this test for worker.port which only exists on shared workers.
if (worker.port === undefined) {
this._workerType = "Worker";

// $FlowFixMe Seems to not recognize 'message' as valid type, but it is
worker.addEventListener("message", this._onMessage);
} else {
this._workerType = "SharedWorker";

// $FlowFixMe - it doesn't know if _worker is Worker or SharedWorker, but I do
worker.port.addEventListener("message", this._onMessage);
// $FlowFixMe - it doesn't know if _worker is Worker or SharedWorker, but I do
worker.port.start();

// Handle tab close. This isn't perfect, but there is no perfect method
Expand Down Expand Up @@ -188,9 +199,11 @@ var PromiseWorker = function () {
});
} else if (!this._worker && this._workerType === "Worker") {
self.postMessage(obj);
} else if (this._worker instanceof Worker) {
} else if (this._workerType === "Worker") {
// $FlowFixMe - it doesn't know if _worker is Worker or SharedWorker, but I do
this._worker.postMessage(obj);
} else if (this._worker instanceof SharedWorker) {
} else if (this._workerType === "SharedWorker") {
// $FlowFixMe - it doesn't know if _worker is Worker or SharedWorker, but I do
this._worker.port.postMessage(obj);
} else {
throw new Error("WTF");
Expand Down

0 comments on commit 9f5d1fe

Please sign in to comment.