1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/workers/test/sharedWorker_sharedWorker.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/** 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 +"use strict"; 1.9 + 1.10 +if (!("self" in this)) { 1.11 + throw new Error("No 'self' exists on SharedWorkerGlobalScope!"); 1.12 +} 1.13 +if (this !== self) { 1.14 + throw new Error("'self' not equal to global object!"); 1.15 +} 1.16 +if (!(self instanceof SharedWorkerGlobalScope)) { 1.17 + throw new Error("self not a SharedWorkerGlobalScope instance!"); 1.18 +} 1.19 + 1.20 +var propsToCheck = [ 1.21 + "location", 1.22 + "navigator", 1.23 + "close", 1.24 + "importScripts", 1.25 + "setTimeout", 1.26 + "clearTimeout", 1.27 + "setInterval", 1.28 + "clearInterval", 1.29 + "dump", 1.30 + "atob", 1.31 + "btoa" 1.32 +]; 1.33 + 1.34 +for (var index = 0; index < propsToCheck.length; index++) { 1.35 + var prop = propsToCheck[index]; 1.36 + if (!(prop in self)) { 1.37 + throw new Error("SharedWorkerGlobalScope has no '" + prop + "' property!"); 1.38 + } 1.39 +} 1.40 + 1.41 +onconnect = function(event) { 1.42 + if (!("SharedWorkerGlobalScope" in self)) { 1.43 + throw new Error("SharedWorkerGlobalScope should be visible!"); 1.44 + } 1.45 + if (!(self instanceof SharedWorkerGlobalScope)) { 1.46 + throw new Error("The global should be a SharedWorkerGlobalScope!"); 1.47 + } 1.48 + if (!(self instanceof WorkerGlobalScope)) { 1.49 + throw new Error("The global should be a WorkerGlobalScope!"); 1.50 + } 1.51 + if ("DedicatedWorkerGlobalScope" in self) { 1.52 + throw new Error("DedicatedWorkerGlobalScope should not be visible!"); 1.53 + } 1.54 + if (!(event instanceof MessageEvent)) { 1.55 + throw new Error("'connect' event is not a MessageEvent!"); 1.56 + } 1.57 + if (!("ports" in event)) { 1.58 + throw new Error("'connect' event doesn't have a 'ports' property!"); 1.59 + } 1.60 + if (event.ports.length != 1) { 1.61 + throw new Error("'connect' event has a 'ports' property with length '" + 1.62 + event.ports.length + "'!"); 1.63 + } 1.64 + if (!event.ports[0]) { 1.65 + throw new Error("'connect' event has a null 'ports[0]' property!"); 1.66 + } 1.67 + if (!(event.ports[0] instanceof MessagePort)) { 1.68 + throw new Error("'connect' event has a 'ports[0]' property that isn't a " + 1.69 + "MessagePort!"); 1.70 + } 1.71 + if (!(event.ports[0] == event.source)) { 1.72 + throw new Error("'connect' event source property is incorrect!"); 1.73 + } 1.74 + if (event.data) { 1.75 + throw new Error("'connect' event has data: " + event.data); 1.76 + } 1.77 + 1.78 + event.ports[0].onmessage = function(event) { 1.79 + if (!(event instanceof MessageEvent)) { 1.80 + throw new Error("'message' event is not a MessageEvent!"); 1.81 + } 1.82 + if (!("ports" in event)) { 1.83 + throw new Error("'message' event doesn't have a 'ports' property!"); 1.84 + } 1.85 + if (!(event.ports === null)) { 1.86 + throw new Error("'message' event has a non-null 'ports' property!"); 1.87 + } 1.88 + event.target.postMessage(event.data); 1.89 + throw new Error(event.data); 1.90 + }; 1.91 +};