dom/workers/test/multi_sharedWorker_frame.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 <!--
michael@0 2 Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 -->
michael@0 5 <!DOCTYPE HTML>
michael@0 6 <html>
michael@0 7 <head>
michael@0 8 <title>Test for SharedWorker</title>
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <script type="text/javascript;version=1.7">
michael@0 12 "use strict";
michael@0 13
michael@0 14 function debug(message) {
michael@0 15 if (typeof(message) != "string") {
michael@0 16 throw new Error("debug() only accepts strings!");
michael@0 17 }
michael@0 18 parent.postMessage(message, "*");
michael@0 19 }
michael@0 20
michael@0 21 let worker;
michael@0 22
michael@0 23 window.addEventListener("message", function(event) {
michael@0 24 if (!worker) {
michael@0 25 worker = new SharedWorker("multi_sharedWorker_sharedWorker.js",
michael@0 26 "FrameWorker");
michael@0 27 worker.onerror = function(event) {
michael@0 28 debug("Worker error: " + event.message);
michael@0 29 event.preventDefault();
michael@0 30
michael@0 31 let data = {
michael@0 32 type: "error",
michael@0 33 message: event.message,
michael@0 34 filename: event.filename,
michael@0 35 lineno: event.lineno,
michael@0 36 isErrorEvent: event instanceof ErrorEvent
michael@0 37 };
michael@0 38 parent.postMessage(data, "*");
michael@0 39 };
michael@0 40
michael@0 41 worker.port.onmessage = function(event) {
michael@0 42 debug("Worker message: " + JSON.stringify(event.data));
michael@0 43 parent.postMessage(event.data, "*");
michael@0 44 };
michael@0 45 }
michael@0 46
michael@0 47 debug("Posting message: " + JSON.stringify(event.data));
michael@0 48 worker.port.postMessage(event.data);
michael@0 49 });
michael@0 50 </script>
michael@0 51 </body>
michael@0 52 </html>

mercurial