michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: "use strict"; michael@0: michael@0: function messageListener(event) { michael@0: var exception; michael@0: try { michael@0: event.bubbles = true; michael@0: } michael@0: catch(e) { michael@0: exception = e; michael@0: } michael@0: michael@0: if (!(exception instanceof TypeError)) { michael@0: throw exception; michael@0: } michael@0: michael@0: switch (event.data) { michael@0: case "no-op": michael@0: break; michael@0: case "components": michael@0: postMessage(Components.toString()); michael@0: break; michael@0: case "start": michael@0: for (var i = 0; i < 1000; i++) { } michael@0: postMessage("started"); michael@0: break; michael@0: case "stop": michael@0: self.postMessage('no-op'); michael@0: postMessage("stopped"); michael@0: self.removeEventListener("message", messageListener, false); michael@0: break; michael@0: default: michael@0: throw 'Bad message: ' + event.data; michael@0: } michael@0: } michael@0: michael@0: if (!("DedicatedWorkerGlobalScope" in self)) { michael@0: throw new Error("DedicatedWorkerGlobalScope should be visible!"); michael@0: } michael@0: if (!(self instanceof DedicatedWorkerGlobalScope)) { michael@0: throw new Error("The global should be a SharedWorkerGlobalScope!"); michael@0: } michael@0: if (!(self instanceof WorkerGlobalScope)) { michael@0: throw new Error("The global should be a WorkerGlobalScope!"); michael@0: } michael@0: if ("SharedWorkerGlobalScope" in self) { michael@0: throw new Error("SharedWorkerGlobalScope should not be visible!"); michael@0: } michael@0: michael@0: addEventListener("message", { handleEvent: messageListener });