diff options
Diffstat (limited to 'testing/web-platform/tests/workers/support/SharedWorker-common.js')
-rw-r--r-- | testing/web-platform/tests/workers/support/SharedWorker-common.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/support/SharedWorker-common.js b/testing/web-platform/tests/workers/support/SharedWorker-common.js new file mode 100644 index 0000000000..1c1dac3971 --- /dev/null +++ b/testing/web-platform/tests/workers/support/SharedWorker-common.js @@ -0,0 +1,32 @@ +function generateError() +{ + // Generate an exception by accessing an undefined variable. + foo.bar = 0; +} + +onconnect = function(event) { + event.ports[0].onmessage = function(evt) { handleMessage(evt, event.ports[0]); }; +}; + +function handleMessage(event, port) { + self.port = port; + if (event.data == "ping") + port.postMessage("PASS: Received ping message"); + else if (event.data == "close") + close(); + else if (event.data == "done") + port.postMessage("DONE"); + else if (event.data == "throw") + generateError(); + else if (event.data == "testingNameAttribute") + port.postMessage(self.name); + else if (/eval.+/.test(event.data)) { + try { + port.postMessage(event.data.substr(5) + ": " + eval(event.data.substr(5))); + } catch (ex) { + port.postMessage(event.data.substr(5) + ": " + ex); + } + } + else + port.postMessage("FAILURE: Received unknown message: " + event.data); +} |