Bug 1446258 - Expose `MessageChannel` to `System`. r=baku
authorKit Cambridge <kit@yakshaving.ninja>
Fri, 16 Mar 2018 05:36:50 -0700
changeset 408496 26ab6b737a6d0594ca36768fee1f5c29700378b7
parent 408495 d244284fe14253c740a3d469200199d0bcdea0dd
child 408497 69857d34427ebc0673dd14076e8c838c45298efb
push id100962
push userkcambridge@mozilla.com
push dateFri, 16 Mar 2018 15:11:11 +0000
treeherdermozilla-inbound@26ab6b737a6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1446258
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1446258 - Expose `MessageChannel` to `System`. r=baku MozReview-Commit-ID: Bd8pvsDk4Ow
dom/messagechannel/tests/moz.build
dom/messagechannel/tests/unit/chromeWorker_messageChannel.js
dom/messagechannel/tests/unit/test_messageChannel.js
dom/messagechannel/tests/unit/xpcshell.ini
dom/webidl/MessageChannel.webidl
tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
--- a/dom/messagechannel/tests/moz.build
+++ b/dom/messagechannel/tests/moz.build
@@ -1,8 +1,10 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 MOCHITEST_MANIFESTS += ['mochitest.ini']
 MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
+
+XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
new file mode 100644
--- /dev/null
+++ b/dom/messagechannel/tests/unit/chromeWorker_messageChannel.js
@@ -0,0 +1,14 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+onmessage = function(pingEvt) {
+  if (pingEvt.data == "ping") {
+    let { port1, port2 } = new MessageChannel();
+    port2.onmessage = helloEvt => {
+      if (helloEvt.data == "hello") {
+        helloEvt.ports[0].postMessage("goodbye");
+      }
+    };
+    pingEvt.ports[0].postMessage("pong", [port1]);
+  }
+};
new file mode 100644
--- /dev/null
+++ b/dom/messagechannel/tests/unit/test_messageChannel.js
@@ -0,0 +1,22 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_test(function test_messageChannel() {
+  do_test_pending();
+
+  let chromeWorker = new ChromeWorker(
+    "resource://test/chromeWorker_messageChannel.js");
+  let { port1, port2 } = new MessageChannel();
+  port2.onmessage = pongEvt => {
+    Assert.equal(pongEvt.data, "pong");
+    let { port1, port2 } = new MessageChannel();
+    port2.onmessage = goodbyeEvt => {
+      Assert.equal(goodbyeEvt.data, "goodbye");
+
+      do_test_finished();
+      run_next_test();
+    };
+    pongEvt.ports[0].postMessage("hello", [port1]);
+  };
+  chromeWorker.postMessage("ping", [port1]);
+});
new file mode 100644
--- /dev/null
+++ b/dom/messagechannel/tests/unit/xpcshell.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+head =
+skip-if = toolkit == 'android'
+support-files =
+  chromeWorker_messageChannel.js
+
+[test_messageChannel.js]
--- a/dom/webidl/MessageChannel.webidl
+++ b/dom/webidl/MessageChannel.webidl
@@ -2,13 +2,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * For more information on this interface, please see
  * http://www.whatwg.org/specs/web-apps/current-work/#channel-messaging
  */
 
-[Constructor, Exposed=(Window,Worker)]
+[Constructor, Exposed=(Window,Worker,System)]
 interface MessageChannel {
   readonly attribute MessagePort port1;
   readonly attribute MessagePort port2;
 };
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
@@ -55,16 +55,17 @@ module.exports = {
     "IDBOpenDBRequest": false,
     "IDBRequest": false,
     "IDBTransaction": false,
     "IDBVersionChangeEvent": false,
     "IdleDeadline": false,
     "MatchGlob": false,
     "MatchPattern": false,
     "MatchPatternSet": false,
+    "MessageChannel": false,
     "MessageEvent": false,
     "MessagePort": false,
     "PrecompiledScript": false,
     "PromiseDebugging": false,
     "StreamFilter": false,
     "StreamFilterDataEvent": false,
     "StructuredCloneHolder": false,
     "TCPServerSocket": false,