Bug 1515590 part 3 - Fix some debugger tests by forcing separate compartments for the debugger and debuggee. r=ochameau
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 22 Dec 2018 21:39:56 +0000
changeset 508950 4ebe565c65f90c7b964f67dd6ed8ccf361918630
parent 508949 11d454511a09a05cf69b79b5013816ee82fa5794
child 508951 93ce93d1510dc67de28e4fe5ad7bea2c5831eb17
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1515590
milestone66.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 1515590 part 3 - Fix some debugger tests by forcing separate compartments for the debugger and debuggee. r=ochameau With same-compartment chrome globals these would end up in the same compartment. We need to prevent that because the debugger doesn't support it. Differential Revision: https://phabricator.services.mozilla.com/D15093
devtools/server/tests/mochitest/test_Debugger.Source.prototype.element.html
devtools/server/tests/mochitest/test_Debugger.Source.prototype.introductionType.html
devtools/server/tests/mochitest/test_makeGlobalObjectReference.html
dom/base/test/jsmodules/iframe_extractIntroType.html
dom/promise/tests/test_on_new_promise.html
dom/promise/tests/test_on_promise_settled.html
dom/promise/tests/test_on_promise_settled_duplicates.html
js/ductwork/debugger/jsdebugger.jsm
js/xpconnect/tests/chrome/test_evalInSandbox.xul
js/xpconnect/tests/chrome/test_onGarbageCollection.html
tools/lint/eslint/modules.json
--- a/devtools/server/tests/mochitest/test_Debugger.Source.prototype.element.html
+++ b/devtools/server/tests/mochitest/test_Debugger.Source.prototype.element.html
@@ -13,17 +13,17 @@ element to which code is attached (if an
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
 </head>
 <body>
 <pre id="test">
 <script>
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-addDebuggerToGlobal(this);
+addSandboxedDebuggerToGlobal(this);
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   let log = "";
   let doc, dieter, ulrich, isolde, albrecht;
   let dbg, iframeDO, DOFor;
 
--- a/devtools/server/tests/mochitest/test_Debugger.Source.prototype.introductionType.html
+++ b/devtools/server/tests/mochitest/test_Debugger.Source.prototype.introductionType.html
@@ -14,17 +14,17 @@ JavaScrip appearing in an inline event h
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
 </head>
 <body>
 <pre id="test">
 <script>
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-addDebuggerToGlobal(this);
+addSandboxedDebuggerToGlobal(this);
 
 let dbg;
 let iframeDO, doc;
 let Tootles, TootlesDO;
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
   runNextTest();
--- a/devtools/server/tests/mochitest/test_makeGlobalObjectReference.html
+++ b/devtools/server/tests/mochitest/test_makeGlobalObjectReference.html
@@ -13,23 +13,26 @@ Debugger.prototype.makeGlobalObjectRefer
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
 </head>
 <body>
 <pre id="test">
 <script>
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-addDebuggerToGlobal(this);
+addSandboxedDebuggerToGlobal(this);
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
+  // Load one of our iframes over http to force it in a different compartment
+  // from the current window and the other iframe.
   const iframe = document.createElement("iframe");
-  iframe.src = "iframe1_makeGlobalObjectReference.html";
+  const baseURL = "http://mochi.test:8888/chrome/devtools/server/tests/mochitest/";
+  iframe.src = baseURL + "iframe1_makeGlobalObjectReference.html";
   iframe.onload = iframeOnLoad;
   document.body.appendChild(iframe);
 
   function iframeOnLoad() {
     const dbg = new Debugger();
 
     // 'o' for 'outer window'
     const g1o = iframe.contentWindow;
--- a/dom/base/test/jsmodules/iframe_extractIntroType.html
+++ b/dom/base/test/jsmodules/iframe_extractIntroType.html
@@ -1,14 +1,14 @@
 <!DOCTYPE html>
 <meta charset=utf-8>
 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 <script>
   // Hook up the debugger statement to extract the calling script's
   // introductionType and set it in a property on the parent global.
   ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-  addDebuggerToGlobal(this);
+  addSandboxedDebuggerToGlobal(this);
   var dbg = new Debugger;
   dbg.addDebuggee(parent);
   dbg.onDebuggerStatement = function (frame) {
     parent.introType = frame.script.source.introductionType;
   }
 </script>
--- a/dom/promise/tests/test_on_new_promise.html
+++ b/dom/promise/tests/test_on_new_promise.html
@@ -21,17 +21,18 @@ Debugger.prototype.onNewPromise.
 </div>
 <pre id="test">
   <script type="application/javascript">
   is(Object.prototype.toString.call(new Promise(function () {})),
      "[object Promise]",
      "We should have the native DOM promise implementation.");
 
   ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal);
+  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal,
+                                 {freshCompartment: true});
   addDebuggerToGlobal(dbgGlobal);
   var dbg = new dbgGlobal.Debugger(this);
 
   var wrappedPromise;
   dbg.onNewPromise = function (wp) { wrappedPromise = wp; };
 
   var promise = new Promise(function () {});
   debugger;
--- a/dom/promise/tests/test_on_promise_settled.html
+++ b/dom/promise/tests/test_on_promise_settled.html
@@ -23,17 +23,18 @@ Debugger.prototype.onPromiseResolved.
   <script type="application/javascript">
   SimpleTest.waitForExplicitFinish();
 
   is(Object.prototype.toString.call(new Promise(function () {})),
      "[object Promise]",
      "We should have the native DOM promise implementation.");
 
   ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal);
+  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal,
+                                 {freshCompartment: true});
   addDebuggerToGlobal(dbgGlobal);
   var dbg = new dbgGlobal.Debugger(this);
 
   var wrappedPromise;
   dbg.onPromiseSettled = function (wp) { wrappedPromise = wp; };
 
   var promise = Promise.resolve();
   promise
--- a/dom/promise/tests/test_on_promise_settled_duplicates.html
+++ b/dom/promise/tests/test_on_promise_settled_duplicates.html
@@ -22,17 +22,18 @@ Bug 1084065 - Test that Debugger.prototy
   <script type="application/javascript">
   SimpleTest.waitForExplicitFinish();
 
   is(Object.prototype.toString.call(new Promise(function () {})),
      "[object Promise]",
      "We should have the native DOM promise implementation.");
 
   ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
-  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal);
+  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal,
+                                 {freshCompartment: true});
   addDebuggerToGlobal(dbgGlobal);
   var dbg = new dbgGlobal.Debugger(this);
 
   var seen = new Set();
   dbg.onPromiseSettled = function (wp) {
     is(seen.has(wp), false);
     seen.add(wp);
   };
--- a/js/ductwork/debugger/jsdebugger.jsm
+++ b/js/ductwork/debugger/jsdebugger.jsm
@@ -1,14 +1,14 @@
 /* -*-  indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* 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/. */
 
-var EXPORTED_SYMBOLS = [ "addDebuggerToGlobal" ];
+var EXPORTED_SYMBOLS = [ "addDebuggerToGlobal", "addSandboxedDebuggerToGlobal" ];
 
 /*
  * This is the js module for Debugger. Import it like so:
  *   Components.utils.import("resource://gre/modules/jsdebugger.jsm");
  *   addDebuggerToGlobal(this);
  *
  * This will create a 'Debugger' object, which provides an interface to debug
  * JavaScript code running in other compartments in the same process, on the
@@ -19,16 +19,24 @@ var EXPORTED_SYMBOLS = [ "addDebuggerToG
  */
 
 const init = Cc["@mozilla.org/jsdebugger;1"].createInstance(Ci.IJSDebugger);
 function addDebuggerToGlobal(global) {
   init.addClass(global);
   initPromiseDebugging(global);
 }
 
+// Defines the Debugger in a sandbox global in a separate compartment. This
+// ensures the debugger and debuggee are in different compartments.
+function addSandboxedDebuggerToGlobal(global) {
+  var sb = Cu.Sandbox(global, {freshCompartment: true});
+  addDebuggerToGlobal(sb);
+  global.Debugger = sb.Debugger;
+}
+
 function initPromiseDebugging(global) {
   if (global.Debugger.Object.prototype.PromiseDebugging) {
     return;
   }
 
   // If the PromiseDebugging object doesn't have all legacy functions, we're
   // using the new accessors on Debugger.Object already.
   if (!PromiseDebugging.getDependentPromises) {
--- a/js/xpconnect/tests/chrome/test_evalInSandbox.xul
+++ b/js/xpconnect/tests/chrome/test_evalInSandbox.xul
@@ -178,17 +178,20 @@ https://bugzilla.mozilla.org/show_bug.cg
       outerSB.sop = this;
       Cu.evalInSandbox('checkExplicitVersions();', outerSB);
 
       ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
       addDebuggerToGlobal(this);
 
       try {
         let dbg = new Debugger();
-        let sandbox = new Cu.Sandbox(this, { invisibleToDebugger: false });
+        let sandbox = new Cu.Sandbox(this, {
+          invisibleToDebugger: false,
+          freshCompartment: true,
+        });
         dbg.addDebuggee(sandbox);
         ok(true, "debugger added visible value");
       } catch(e) {
         ok(false, "debugger could not add visible value");
       }
 
       try {
         let dbg = new Debugger();
--- a/js/xpconnect/tests/chrome/test_onGarbageCollection.html
+++ b/js/xpconnect/tests/chrome/test_onGarbageCollection.html
@@ -11,17 +11,18 @@
 
     <script type="application/javascript">
     SimpleTest.waitForExplicitFinish();
 
     const { gc } = Cu.getJSTestingFunctions();
 
     // Instanciate `Debugger` in a sandbox as Debugger requires to be created
     // in a compartment different than the debuggee.
-    let sandbox = Cu.Sandbox(Components.Constructor("@mozilla.org/systemprincipal;1", "nsIPrincipal")());
+    let sandbox = Cu.Sandbox(Components.Constructor("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
+                             {freshCompartment: true});
     Cu.evalInSandbox(
       "Components.utils.import('resource://gre/modules/jsdebugger.jsm');" +
       "addDebuggerToGlobal(this);",
       sandbox
     );
 
     const dbg = new sandbox.Debugger(this);
 
--- a/tools/lint/eslint/modules.json
+++ b/tools/lint/eslint/modules.json
@@ -89,17 +89,17 @@
   "helper.js": ["workerHelper"],
   "history.js": ["HistoryEngine", "HistoryRec"],
   "history.jsm": ["HistoryEntry", "DumpHistory"],
   "Http.jsm": ["httpRequest", "percentEncode"],
   "httpd.js": ["HTTP_400", "HTTP_401", "HTTP_402", "HTTP_403", "HTTP_404", "HTTP_405", "HTTP_406", "HTTP_407", "HTTP_408", "HTTP_409", "HTTP_410", "HTTP_411", "HTTP_412", "HTTP_413", "HTTP_414", "HTTP_415", "HTTP_417", "HTTP_500", "HTTP_501", "HTTP_502", "HTTP_503", "HTTP_504", "HTTP_505", "HttpError", "HttpServer"],
   "import_module.jsm": ["MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope", "SUBMODULE_IMPORTED_TO_SCOPE"],
   "import_sub_module.jsm": ["SUBMODULE_IMPORTED", "test_obj"],
   "InlineSpellChecker.jsm": ["InlineSpellChecker", "SpellCheckHelper"],
-  "jsdebugger.jsm": ["addDebuggerToGlobal"],
+  "jsdebugger.jsm": ["addDebuggerToGlobal", "addSandboxedDebuggerToGlobal"],
   "jsesc.js": ["jsesc"],
   "json2.js": ["JSON"],
   "keys.js": ["BulkKeyBundle", "SyncKeyBundle"],
   "KeyValueParser.jsm": ["parseKeyValuePairsFromLines", "parseKeyValuePairs", "parseKeyValuePairsFromFile", "parseKeyValuePairsFromFileAsync"],
   "kinto-http-client.js": ["KintoHttpClient"],
   "kinto-offline-client.js": ["Kinto"],
   "kinto-storage-adapter.js": ["FirefoxAdapter"],
   "L10nRegistry.jsm": ["L10nRegistry", "FileSource", "IndexedFileSource"],