gecko-dev/dom/workers/test/sharedWorker_sharedWorker.js

94 строки
2.9 KiB
JavaScript
Исходник Обычный вид История

/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
if (!("self" in this)) {
throw new Error("No 'self' exists on SharedWorkerGlobalScope!");
}
if (this !== self) {
throw new Error("'self' not equal to global object!");
}
if (!(self instanceof SharedWorkerGlobalScope)) {
throw new Error("self not a SharedWorkerGlobalScope instance!");
}
var propsToCheck = [
"location",
"navigator",
"close",
"importScripts",
"setTimeout",
"clearTimeout",
"setInterval",
"clearInterval",
"dump",
"atob",
"btoa"
];
for (var index = 0; index < propsToCheck.length; index++) {
var prop = propsToCheck[index];
if (!(prop in self)) {
throw new Error("SharedWorkerGlobalScope has no '" + prop + "' property!");
}
}
onconnect = function(event) {
if (!("SharedWorkerGlobalScope" in self)) {
throw new Error("SharedWorkerGlobalScope should be visible!");
}
if (!(self instanceof SharedWorkerGlobalScope)) {
throw new Error("The global should be a SharedWorkerGlobalScope!");
}
if (!(self instanceof WorkerGlobalScope)) {
throw new Error("The global should be a WorkerGlobalScope!");
}
if ("DedicatedWorkerGlobalScope" in self) {
throw new Error("DedicatedWorkerGlobalScope should not be visible!");
}
if (!(event instanceof MessageEvent)) {
throw new Error("'connect' event is not a MessageEvent!");
}
if (!("ports" in event)) {
throw new Error("'connect' event doesn't have a 'ports' property!");
}
if (event.ports.length != 1) {
throw new Error("'connect' event has a 'ports' property with length '" +
event.ports.length + "'!");
}
if (!event.ports[0]) {
throw new Error("'connect' event has a null 'ports[0]' property!");
}
if (!(event.ports[0] instanceof MessagePort)) {
throw new Error("'connect' event has a 'ports[0]' property that isn't a " +
"MessagePort!");
}
if (!(event.ports[0] == event.source)) {
throw new Error("'connect' event source property is incorrect!");
}
if (event.data) {
throw new Error("'connect' event has data: " + event.data);
}
// The expression closures should trigger a warning in debug builds, but NOT
// fire error events at us. If we ever actually remove expression closures
// (in bug 1083458), we'll need something else to test this case.
(function() "Expected console warning: expression closures are deprecated");
event.ports[0].onmessage = function(event) {
if (!(event instanceof MessageEvent)) {
throw new Error("'message' event is not a MessageEvent!");
}
if (!("ports" in event)) {
throw new Error("'message' event doesn't have a 'ports' property!");
}
Bug 911972 - MessagePort and MessageChannel in workers, r=smaug, r=bent --HG-- rename : dom/base/MessageChannel.cpp => dom/messagechannel/MessageChannel.cpp rename : dom/base/MessageChannel.h => dom/messagechannel/MessageChannel.h rename : dom/base/MessagePort.cpp => dom/messagechannel/MessagePort.cpp rename : dom/base/MessagePort.h => dom/messagechannel/MessagePort.h rename : dom/base/MessagePortList.cpp => dom/messagechannel/MessagePortList.cpp rename : dom/base/MessagePortList.h => dom/messagechannel/MessagePortList.h rename : dom/base/test/iframe_messageChannel_chrome.html => dom/messagechannel/tests/iframe_messageChannel_chrome.html rename : dom/base/test/iframe_messageChannel_cloning.html => dom/messagechannel/tests/iframe_messageChannel_cloning.html rename : dom/base/test/iframe_messageChannel_pingpong.html => dom/messagechannel/tests/iframe_messageChannel_pingpong.html rename : dom/base/test/iframe_messageChannel_post.html => dom/messagechannel/tests/iframe_messageChannel_post.html rename : dom/base/test/test_messageChannel.html => dom/messagechannel/tests/test_messageChannel.html rename : dom/base/test/test_messageChannel.xul => dom/messagechannel/tests/test_messageChannel.xul rename : dom/base/test/test_messageChannel_cloning.html => dom/messagechannel/tests/test_messageChannel_cloning.html rename : dom/base/test/test_messageChannel_pingpong.html => dom/messagechannel/tests/test_messageChannel_pingpong.html rename : dom/base/test/test_messageChannel_post.html => dom/messagechannel/tests/test_messageChannel_post.html rename : dom/base/test/test_messageChannel_pref.html => dom/messagechannel/tests/test_messageChannel_pref.html rename : dom/base/test/test_messageChannel_start.html => dom/messagechannel/tests/test_messageChannel_start.html rename : dom/base/test/test_messageChannel_transferable.html => dom/messagechannel/tests/test_messageChannel_transferable.html rename : dom/base/test/test_messageChannel_unshipped.html => dom/messagechannel/tests/test_messageChannel_unshipped.html
2015-06-17 13:44:27 +03:00
if (event.ports === null) {
throw new Error("'message' event has a null 'ports' property!");
}
event.target.postMessage(event.data);
throw new Error(event.data);
};
};