Bug 1790912 - Fix lint issues in js/ductwork/debugger. r=ochameau

When we move this out of the js/ directory, a number of lint exceptions stop
applying so we should just fix the issues now.

Differential Revision: https://phabricator.services.mozilla.com/D157521
This commit is contained in:
Ted Campbell 2022-09-25 09:03:33 +00:00
parent 69dfb519c2
commit 410e8dff3f
6 changed files with 36 additions and 25 deletions

View file

@ -136,7 +136,6 @@ dom/workers/test/threadErrors_worker1.js
intl/l10n/ intl/l10n/
# Exclude everything but self-hosted JS # Exclude everything but self-hosted JS
js/ductwork/
js/examples/ js/examples/
js/public/ js/public/
js/xpconnect/ js/xpconnect/

View file

@ -54,6 +54,7 @@ const extraXpcshellTestPaths = [
"intl/benchmarks/", "intl/benchmarks/",
"intl/l10n/test/", "intl/l10n/test/",
"ipc/testshell/tests/", "ipc/testshell/tests/",
"js/ductwork/debugger/tests/",
"memory/replace/dmd/test/", "memory/replace/dmd/test/",
"netwerk/test/httpserver/test/", "netwerk/test/httpserver/test/",
"testing/modules/tests/xpcshell/", "testing/modules/tests/xpcshell/",

View file

@ -35,7 +35,7 @@ JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx) {
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
JS::RootedObject obj(cx, &global.toObject()); JS::Rooted<JSObject*> obj(cx, &global.toObject());
obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false); obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
if (!obj) { if (!obj) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;

View file

@ -3,7 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = [ "addDebuggerToGlobal", "addSandboxedDebuggerToGlobal" ]; "use strict";
var EXPORTED_SYMBOLS = ["addDebuggerToGlobal", "addSandboxedDebuggerToGlobal"];
/* /*
* This is the js module for Debugger. Import it like so: * This is the js module for Debugger. Import it like so:
@ -29,7 +31,7 @@ function addDebuggerToGlobal(global) {
// Defines the Debugger in a sandbox global in a separate compartment. This // Defines the Debugger in a sandbox global in a separate compartment. This
// ensures the debugger and debuggee are in different compartments. // ensures the debugger and debuggee are in different compartments.
function addSandboxedDebuggerToGlobal(global) { function addSandboxedDebuggerToGlobal(global) {
var sb = Cu.Sandbox(global, {freshCompartment: true}); const sb = Cu.Sandbox(global, { freshCompartment: true });
addDebuggerToGlobal(sb); addDebuggerToGlobal(sb);
global.Debugger = sb.Debugger; global.Debugger = sb.Debugger;
} }
@ -50,7 +52,7 @@ function initPromiseDebugging(global) {
global.eval(polyfillSource); global.eval(polyfillSource);
} }
let polyfillSource = ` const polyfillSource = `
Object.defineProperty(Debugger.Object.prototype, "promiseState", { Object.defineProperty(Debugger.Object.prototype, "promiseState", {
get() { get() {
const state = this.PromiseDebugging.getState(this.unsafeDereference()); const state = this.PromiseDebugging.getState(this.unsafeDereference());

View file

@ -3,11 +3,12 @@
"use strict"; "use strict";
function testGlobal(aName) { function testGlobal(name) {
let systemPrincipal = Cc["@mozilla.org/systemprincipal;1"] const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
.createInstance(Ci.nsIPrincipal); Ci.nsIPrincipal
);
let sandbox = Cu.Sandbox(systemPrincipal); const sandbox = Cu.Sandbox(systemPrincipal);
Cu.evalInSandbox("this.__name = '" + aName + "'", sandbox); Cu.evalInSandbox("this.__name = '" + name + "'", sandbox);
return sandbox; return sandbox;
} }

View file

@ -1,6 +1,9 @@
function run_test() "use strict";
{
const {addDebuggerToGlobal} = ChromeUtils.import("resource://gre/modules/jsdebugger.jsm"); function run_test() {
const { addDebuggerToGlobal } = ChromeUtils.import(
"resource://gre/modules/jsdebugger.jsm"
);
Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
registerCleanupFunction(() => { registerCleanupFunction(() => {
@ -8,30 +11,35 @@ function run_test()
}); });
addDebuggerToGlobal(globalThis); addDebuggerToGlobal(globalThis);
var g = testGlobal("test1"); const g = testGlobal("test1");
var dbg = new Debugger(); const dbg = new Debugger();
dbg.addDebuggee(g); dbg.addDebuggee(g);
dbg.onDebuggerStatement = function(aFrame) { dbg.onDebuggerStatement = function(frame) {
let args = aFrame["arguments"]; const args = frame.arguments;
try { try {
args[0]; args[0];
Assert.ok(true); Assert.ok(true);
} catch(ex) { } catch (ex) {
Assert.ok(false); Assert.ok(false);
} }
}; };
g.eval("function stopMe(arg) {debugger;}"); g.eval("function stopMe(arg) {debugger;}");
g2 = testGlobal("test2"); const g2 = testGlobal("test2");
g2.g = g; g2.g = g;
g2.eval("(" + function createBadEvent() { g2.eval(
Cu.importGlobalProperties(["DOMParser"]); "(" +
let parser = new DOMParser(); function createBadEvent() {
let doc = parser.parseFromString("<foo></foo>", "text/xml"); // eslint-disable-next-line mozilla/reject-importGlobalProperties
g.stopMe(doc.createEvent("MouseEvent")); Cu.importGlobalProperties(["DOMParser"]);
} + ")()"); const parser = new DOMParser();
const doc = parser.parseFromString("<foo></foo>", "text/xml");
g.stopMe(doc.createEvent("MouseEvent"));
} +
")()"
);
dbg.removeAllDebuggees(); dbg.removeAllDebuggees();
} }