mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
7b97102c91
--HG-- extra : transplant_source : %D6%8C%9Ajc%3C%F0%0E%DB%C6%7E2%AA%97%B8%AA%B2%7EY%B6
73 lines
1.4 KiB
JavaScript
73 lines
1.4 KiB
JavaScript
/**
|
|
* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
*/
|
|
"use strict";
|
|
|
|
if (self.name != "FrameWorker") {
|
|
throw new Error("Bad worker name: " + self.name);
|
|
}
|
|
|
|
var registeredPorts = [];
|
|
var errorCount = 0;
|
|
var storedData;
|
|
|
|
self.onconnect = function(event) {
|
|
var port = event.ports[0];
|
|
|
|
if (registeredPorts.length) {
|
|
var data = {
|
|
type: "connect"
|
|
};
|
|
|
|
registeredPorts.forEach(function(registeredPort) {
|
|
registeredPort.postMessage(data);
|
|
});
|
|
}
|
|
|
|
port.onmessage = function(event) {
|
|
switch (event.data.command) {
|
|
case "start":
|
|
break;
|
|
|
|
case "error":
|
|
throw new Error("Expected");
|
|
|
|
case "store":
|
|
storedData = event.data.data;
|
|
break;
|
|
|
|
case "retrieve":
|
|
var data = {
|
|
type: "result",
|
|
data: storedData
|
|
};
|
|
port.postMessage(data);
|
|
break;
|
|
|
|
default:
|
|
throw new Error("Unknown command '" + error.data.command + "'");
|
|
}
|
|
};
|
|
|
|
registeredPorts.push(port);
|
|
};
|
|
|
|
self.onerror = function(message, filename, lineno) {
|
|
if (!errorCount++) {
|
|
var data = {
|
|
type: "worker-error",
|
|
message: message,
|
|
filename: filename,
|
|
lineno: lineno
|
|
};
|
|
|
|
registeredPorts.forEach(function (registeredPort) {
|
|
registeredPort.postMessage(data);
|
|
});
|
|
|
|
// Prevent the error from propagating the first time only.
|
|
return true;
|
|
}
|
|
};
|