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: if (!("self" in this)) { michael@0: throw new Error("No 'self' exists on SharedWorkerGlobalScope!"); michael@0: } michael@0: if (this !== self) { michael@0: throw new Error("'self' not equal to global object!"); michael@0: } michael@0: if (!(self instanceof SharedWorkerGlobalScope)) { michael@0: throw new Error("self not a SharedWorkerGlobalScope instance!"); michael@0: } michael@0: michael@0: var propsToCheck = [ michael@0: "location", michael@0: "navigator", michael@0: "close", michael@0: "importScripts", michael@0: "setTimeout", michael@0: "clearTimeout", michael@0: "setInterval", michael@0: "clearInterval", michael@0: "dump", michael@0: "atob", michael@0: "btoa" michael@0: ]; michael@0: michael@0: for (var index = 0; index < propsToCheck.length; index++) { michael@0: var prop = propsToCheck[index]; michael@0: if (!(prop in self)) { michael@0: throw new Error("SharedWorkerGlobalScope has no '" + prop + "' property!"); michael@0: } michael@0: } michael@0: michael@0: onconnect = function(event) { michael@0: if (!("SharedWorkerGlobalScope" in self)) { michael@0: throw new Error("SharedWorkerGlobalScope should be visible!"); michael@0: } michael@0: if (!(self instanceof SharedWorkerGlobalScope)) { 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 ("DedicatedWorkerGlobalScope" in self) { michael@0: throw new Error("DedicatedWorkerGlobalScope should not be visible!"); michael@0: } michael@0: if (!(event instanceof MessageEvent)) { michael@0: throw new Error("'connect' event is not a MessageEvent!"); michael@0: } michael@0: if (!("ports" in event)) { michael@0: throw new Error("'connect' event doesn't have a 'ports' property!"); michael@0: } michael@0: if (event.ports.length != 1) { michael@0: throw new Error("'connect' event has a 'ports' property with length '" + michael@0: event.ports.length + "'!"); michael@0: } michael@0: if (!event.ports[0]) { michael@0: throw new Error("'connect' event has a null 'ports[0]' property!"); michael@0: } michael@0: if (!(event.ports[0] instanceof MessagePort)) { michael@0: throw new Error("'connect' event has a 'ports[0]' property that isn't a " + michael@0: "MessagePort!"); michael@0: } michael@0: if (!(event.ports[0] == event.source)) { michael@0: throw new Error("'connect' event source property is incorrect!"); michael@0: } michael@0: if (event.data) { michael@0: throw new Error("'connect' event has data: " + event.data); michael@0: } michael@0: michael@0: event.ports[0].onmessage = function(event) { michael@0: if (!(event instanceof MessageEvent)) { michael@0: throw new Error("'message' event is not a MessageEvent!"); michael@0: } michael@0: if (!("ports" in event)) { michael@0: throw new Error("'message' event doesn't have a 'ports' property!"); michael@0: } michael@0: if (!(event.ports === null)) { michael@0: throw new Error("'message' event has a non-null 'ports' property!"); michael@0: } michael@0: event.target.postMessage(event.data); michael@0: throw new Error(event.data); michael@0: }; michael@0: };