Bug 1793227, part 3 - Automatic fixes for js/xpconnect/tests/chrome. r=kmag

Also change .eslintignore to cover the other directories.

This also fixes the indentation the automatic fixer messed up in a few XHTML files.

Differential Revision: https://phabricator.services.mozilla.com/D158503
This commit is contained in:
Andrew McCreight 2022-10-10 22:22:00 +00:00
parent a2486eeeb0
commit d8c43d0ea1
26 changed files with 98 additions and 96 deletions

View file

@ -138,12 +138,17 @@ intl/l10n/
# Exclude everything but self-hosted JS
js/examples/
js/public/
js/xpconnect/
js/src/devtools/
js/src/jit-test/
js/src/tests/
js/src/Y.js
# Changes to XPConnect tests must be carefully audited.
js/xpconnect/loader/
js/xpconnect/tests/browser/
js/xpconnect/tests/mochitest/
js/xpconnect/tests/unit/
# Fuzzing code for testing only, targeting the JS shell
js/src/fuzz-tests/

View file

@ -18,7 +18,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=503926
var gWindowUtils = window.windowUtils;
var passed = false;
// eslint-disable-next-line mozilla/use-chromeutils-generateqi
var obj = { QueryInterface: function() { passed = true; } }
var obj = { QueryInterface() { passed = true; } }
gWindowUtils.xpconnectArgument(obj);
var isDialog = location.hash != '#iframe';
var outer = XPCNativeWrapper.unwrap(isDialog ? window.arguments[0] : parent);

View file

@ -1,4 +1,4 @@
var EXPORTED_SYMBOLS = ['checkFromJSM'];
var EXPORTED_SYMBOLS = ["checkFromJSM"];
function checkFromJSM(target, is_op) {
is_op(target.numProp, 42, "Number expando works");
@ -6,5 +6,7 @@ function checkFromJSM(target, is_op) {
// If is_op is todo_is, target.objProp will be undefined.
try {
is_op(target.objProp.bar, "baz", "Object expando works");
} catch(e) { is_op(0, 1, "No object expando"); }
} catch (e) {
is_op(0, 1, "No object expando");
}
}

View file

@ -3,4 +3,3 @@
function outoflinefunction() {
return 42;
}

View file

@ -29,7 +29,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=634156
function genPropDesc(value) {
return { enumerable: true, configurable: true, writable: true,
value: value };
value };
}
const props = {
'getProp': genPropDesc(function() { ok(true, "called prop that shadowed a getter"); }),

View file

@ -42,7 +42,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1041626
xrayOwnProperties = Object.getOwnPropertyNames(window[0].document);
realOwnProperties = Object.getOwnPropertyNames(window[0].wrappedJSObject.document);
ok(realOwnProperties.length > 0);
ok(!!realOwnProperties.length);
is(xrayOwnProperties.sort().toSource(), realOwnProperties.sort().toSource(),
"Xray enumerates document properties properly");

View file

@ -12,7 +12,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1074863
<script type="application/javascript">
/** Test for Bug 1074863 **/
var sb = new Cu.Sandbox('http://www.example.com');
var sb = new Cu.Sandbox("https://www.example.com");
sb.namedCtor = Image;
ok(true, "Didn't assert");

View file

@ -21,7 +21,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1124898
var w = window.browsingContext.topChromeWindow.open("about:blank", "w", "chrome");
is(w.eval('typeof getAttention'), 'function', 'getAttention exists on regular chrome window');
is(w.eval('typeof messageManager'), 'object', 'messageManager exists on regular chrome window');
var contentURL = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
var contentURL = "https://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
w.location = contentURL;
tryWindow();

View file

@ -36,7 +36,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=503926
// Try with a chrome object.
var passed = false;
// eslint-disable-next-line mozilla/use-chromeutils-generateqi
var obj = { QueryInterface: function() { passed = true; } };
var obj = { QueryInterface() { passed = true; } };
gWindowUtils.xpconnectArgument(obj);
ok(passed, "trusted QIs should be called");

View file

@ -26,11 +26,11 @@
await SpecialPowers.pushPrefEnv({"set": [["security.allow_eval_with_system_principal",
true]]});
Test = {
include: function(p) {
include(p) {
var sawError = false;
try {
Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci["mozIJSSubScriptLoader"]).
getService(Ci.mozIJSSubScriptLoader).
loadSubScript(p);
} catch (e) {
sawError = true;

View file

@ -31,19 +31,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=658909
}
var testFunctions = {
testDocumentElement: function(a, b, name) {
testDocumentElement(a, b, name) {
var getter = Object.prototype.__lookupGetter__.call(a.document, 'documentElement');
is(getter.call(b.document), b.document.documentElement, msg(a, b, name));
},
testInvalidCall: function(a, b, name) {
testInvalidCall(a, b, name) {
var getter = Object.prototype.__lookupGetter__.call(a.document, 'documentElement');
var threw = false;
try { getter.call(b.document.body); } catch (e) { threw = true; };
ok(threw, msg(a, b, name));
},
testStatus: function(a, b, name) {
testStatus(a, b, name) {
var setter = Object.prototype.__lookupSetter__.call(a, 'status');
is(b.status, "", "Empty status");
setter.call(b, "foopy");
@ -51,16 +51,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=658909
b.status = "";
},
testCreateElement: function(a, b, name) {
testCreateElement(a, b, name) {
is(a.document.createElement.call(b.document, 'div').ownerDocument, b.document, msg(a, b, name));
},
testWindowName: function(a, b, name) {
testWindowName(a, b, name) {
var getter = Object.prototype.__lookupGetter__.call(a, 'name');
is(getter.call(b), b.name, msg(a, b, name));
},
testCanvas: function(a, b, name) {
testCanvas(a, b, name) {
var canvasA = a.document.createElement('canvas');
var canvasB = b.document.createElement('canvas');
var contextA = canvasA.getContext('2d');

View file

@ -30,7 +30,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=706301
// Perform the operation.
Object.getOwnPropertyDescriptor(nodelist, 'length');
return nodelist['length'] == 0;
return !nodelist.length;
}
function finishTestInChrome() {

View file

@ -18,10 +18,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=720619
<script type="application/javascript"><![CDATA[
/** Test for Bug 720619 **/
var obj = {
valueOf: function () {
valueOf () {
return 42;
},
toString: function () {
toString () {
return 'str';
}
};

View file

@ -51,7 +51,7 @@ add_task(async () => {
return inner();
}
var contentSb = new Cu.Sandbox('http://www.example.com');
var contentSb = new Cu.Sandbox("https://www.example.com");
var chromeSb = new Cu.Sandbox(window);
chromeSb.ok = contentSb.ok = ok;
Cu.evalInSandbox(nearNativeStackLimit.toSource(), chromeSb);

View file

@ -4,7 +4,8 @@ var top = bottom;
function nearNativeStackLimit() {
function inner() {
try {
with ({}) { // keep things predictable -- stay in the interpreter
with ({}) {
// keep things predictable -- stay in the interpreter
top = stackPointerInfo();
var stepsFromLimit = eval("inner()"); // Use eval to force a number of native stackframes to be created.
}
@ -21,6 +22,13 @@ function nearNativeStackLimit() {
var nbFrames = nearNativeStackLimit();
var frameSize = bottom - top;
print("Max stack size:", frameSize, "bytes",
"\nMaximum number of frames:", nbFrames,
"\nAverage frame size:", Math.ceil(frameSize / nbFrames), "bytes");
print(
"Max stack size:",
frameSize,
"bytes",
"\nMaximum number of frames:",
nbFrames,
"\nAverage frame size:",
Math.ceil(frameSize / nbFrames),
"bytes"
);

View file

@ -32,7 +32,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=760076
}
// Set up the sandbox.
var sb = new Cu.Sandbox('http://www.example.com');
var sb = new Cu.Sandbox("https://www.example.com");
// Import the functions it needs.
sb.ok = ok;

View file

@ -27,7 +27,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=771429
function test(freshCompartment) {
var s = new Cu.Sandbox(window, {
sandboxPrototype: window,
freshCompartment: freshCompartment,
freshCompartment,
});
try {
is(Cu.evalInSandbox('g()', s), window,

View file

@ -40,13 +40,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=795275
}
var gListener = {
observe: onWarning,
QueryInterface: function (iid) {
if (!iid.equals(Ci.nsIConsoleListener) &&
!iid.equals(Ci.nsISupports)) {
throw Cr.NS_ERROR_NO_INTERFACE;
}
return this;
}
QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"])
};
var gConsoleService = Cc["@mozilla.org/consoleservice;1"]
.getService(Ci.nsIConsoleService);

View file

@ -22,19 +22,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=799348
gCalledOnload = false;
var myObserver = {
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
observe: function(win, topic, data) {
observe(win, topic, data) {
if (topic == "domwindowopened") {
ok(!gCalledOnload, "domwindowopened notification fired before onload");
win.addEventListener("load", function(evt) {
gCalledOnload = true;
win.close();
}, false);
});
} else if (topic == "domwindowclosed") {
ok(gCalledOnload, "should have called onload");
Services.ww.unregisterNotification(myObserver);
SimpleTest.finish();
}
else {
} else {
ok(false, "unknown topic");
}
}

View file

@ -27,14 +27,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=895340
.getService(Ci.nsIConsoleService);
let listener = {
QueryInterface: function(iid) {
if (!iid.equals(Ci.nsIConsoleListener) &&
!iid.equals(Ci.nsISupports))
{
throw Cr.NS_ERROR_NO_INTERFACE;
}
return this;
}
QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"])
};
listener.observe = function(aMessage) {

View file

@ -45,10 +45,10 @@
if (Array.isArray(a))
return 'array';
if (a instanceof File)
if (File.isInstance(a))
return 'file';
if (a instanceof Blob)
if (Blob.isInstance(a))
return 'blob';
if (TypedArrayThings.includes(a.constructor.name))
@ -152,7 +152,7 @@
cloneAndTest(tests[i]);
}
checkThrows(function() { Cu.cloneInto({ a: function() {} }, sandbox); },
checkThrows(function() { Cu.cloneInto({ a() {} }, sandbox); },
'Function should not be cloned by default');
checkThrows(function() { Cu.cloneInto({ a: document }, sandbox); },
@ -181,11 +181,11 @@
'wrapReflectors may not wrap cross-origin reflectors', /unsupported value type/);
var test = { a: function() { return 42; } };
var test = { a() { return 42; } };
cloneAndTestWithFunctions(test);
// Check that inputs are properly passed through cloned functions:
test = { a: function(obj) { return obj; } };
test = { a(obj) { return obj; } };
var clonedTest = Cu.cloneInto(test, sandbox, {cloneFunctions: true});
var testInput = {};
is(clonedTest.a(testInput), testInput, "Objects should be identical");

View file

@ -19,7 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=804630
<![CDATA[
/** Test to make sure that COWed objects can't expose properties from their prototypes. **/
// Set up the sandbox.
var sb = new Cu.Sandbox('http://www.example.com');
var sb = new Cu.Sandbox("https://www.example.com");
sb.ok = ok;
sb.is = is;

View file

@ -48,7 +48,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=673468
sandbox.wrapper = null;
sandbox.value = null;
live_dom.xyzabc = {wrappee: wrappee, m: map, sb: sandbox};
live_dom.xyzabc = {wrappee, m: map, sb: sandbox};
let key = ChromeUtils.nondeterministicGetWeakMapKeys(map)[0];
let value = map.get(key);

View file

@ -33,7 +33,7 @@ async function go() {
ok(!checkDead(), "WindowProxy shouldn't be dead yet");
// Load a content page in the chrome frame.
w.location = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
w.location = "https://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
tryWindow();
function tryWindow() {

View file

@ -77,7 +77,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c](...args)).constructor), iwin[c],
"constructor property is set up right: " + c);
let expectedProto = Cu.isOpaqueWrapper(new iwin[c](...args)) ?
iwin['Object'].prototype : iwin[c].prototype;
iwin.Object.prototype : iwin[c].prototype;
is(Object.getPrototypeOf(new iwin[c](...args)), expectedProto,
"prototype is correct: " + c);
is(global(new iwin[c](...args)), iwin, "Got the right global: " + c);
@ -147,7 +147,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin.AggregateError(...args)).constructor), iwin.AggregateError,
"AggregateError constructor property is set up right");
let expectedProto = Cu.isOpaqueWrapper(new iwin.AggregateError(...args)) ?
iwin['Object'].prototype : iwin.AggregateError.prototype;
iwin.Object.prototype : iwin.AggregateError.prototype;
is(Object.getPrototypeOf(new iwin.AggregateError(...args)), expectedProto,
"AggregateError prototype is correct");
is(global(new iwin.AggregateError(...args)), iwin, "Got the right global for AggregateError");
@ -203,7 +203,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
// Some props live on all constructors
return arr.concat(["prototype", "length", "name"]);
}
gPrototypeProperties['Date'] =
gPrototypeProperties.Date =
["getTime", "getTimezoneOffset", "getYear", "getFullYear", "getUTCFullYear",
"getMonth", "getUTCMonth", "getDate", "getUTCDate", "getDay", "getUTCDay",
"getHours", "getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds",
@ -215,36 +215,36 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
"toLocaleDateString", "toLocaleTimeString", "toDateString", "toTimeString",
"toISOString", "toJSON", "toSource", "toString", "valueOf", "constructor",
"toGMTString", Symbol.toPrimitive];
gConstructorProperties['Date'] = constructorProps(["UTC", "parse", "now"]);
gPrototypeProperties['Object'] =
gConstructorProperties.Date = constructorProps(["UTC", "parse", "now"]);
gPrototypeProperties.Object =
["constructor", "toSource", "toString", "toLocaleString", "valueOf",
"hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable",
"__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__",
"__proto__"];
gConstructorProperties['Object'] =
gConstructorProperties.Object =
constructorProps(["setPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyDescriptors",
"keys", "is", "defineProperty", "defineProperties", "create",
"getOwnPropertyNames", "getOwnPropertySymbols",
"preventExtensions", "freeze", "fromEntries", "isFrozen", "seal",
"isSealed", "assign", "getPrototypeOf", "values",
"entries", "isExtensible", "hasOwn"]);
gPrototypeProperties['Array'] =
gPrototypeProperties.Array =
["length", "toSource", "toString", "toLocaleString", "join", "reverse", "sort", "push",
"pop", "shift", "unshift", "splice", "concat", "slice", "lastIndexOf", "indexOf",
"includes", "forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find",
"findIndex", "copyWithin", "fill", Symbol.iterator, Symbol.unscopables, "entries", "keys",
"values", "constructor", "flat", "flatMap", "at", "findLast", "findLastIndex"];
if (isNightlyBuild) {
gPrototypeProperties['Array'].push("group");
gPrototypeProperties['Array'].push("groupToMap");
gPrototypeProperties.Array.push("group");
gPrototypeProperties.Array.push("groupToMap");
}
gConstructorProperties['Array'] =
gConstructorProperties.Array =
constructorProps(["isArray", "from", "of", Symbol.species]);
for (var c of typedArrayClasses) {
gPrototypeProperties[c] = ["constructor", "BYTES_PER_ELEMENT"];
gConstructorProperties[c] = constructorProps(["BYTES_PER_ELEMENT"]);
}
gPrototypeProperties['TypedArray'] =
gPrototypeProperties.TypedArray =
["length", "buffer", "byteLength", "byteOffset", Symbol.iterator, "subarray",
"set", "copyWithin", "find", "findIndex", "forEach","indexOf", "lastIndexOf", "includes",
"reverse", "join", "every", "some", "reduce", "reduceRight", "entries", "keys", "values",
@ -256,68 +256,68 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
gConstructorProperties[c] = constructorProps([]);
}
// toString and toSource only live on the parent proto (Error.prototype).
gPrototypeProperties['Error'].push('toString');
gPrototypeProperties['Error'].push('toSource');
gPrototypeProperties.Error.push('toString');
gPrototypeProperties.Error.push('toSource');
gPrototypeProperties['Function'] =
gPrototypeProperties.Function =
["constructor", "toSource", "toString", "apply", "call", "bind",
"length", "name", "arguments", "caller", Symbol.hasInstance];
gConstructorProperties['Function'] = constructorProps([])
gConstructorProperties.Function = constructorProps([])
gPrototypeProperties['RegExp'] =
gPrototypeProperties.RegExp =
["constructor", "toSource", "toString", "compile", "exec", "test",
Symbol.match, Symbol.matchAll, Symbol.replace, Symbol.search, Symbol.split,
"flags", "dotAll", "global", "hasIndices", "ignoreCase", "multiline", "source", "sticky",
"unicode"];
gConstructorProperties['RegExp'] =
gConstructorProperties.RegExp =
constructorProps(["input", "lastMatch", "lastParen",
"leftContext", "rightContext", "$1", "$2", "$3", "$4",
"$5", "$6", "$7", "$8", "$9", "$_", "$&", "$+",
"$`", "$'", Symbol.species])
gPrototypeProperties['Promise'] =
gPrototypeProperties.Promise =
["constructor", "catch", "then", "finally", Symbol.toStringTag];
gConstructorProperties['Promise'] =
gConstructorProperties.Promise =
constructorProps(["resolve", "reject", "all", "allSettled", "any", "race", Symbol.species]);
gPrototypeProperties['ArrayBuffer'] =
gPrototypeProperties.ArrayBuffer =
["constructor", "byteLength", "slice", Symbol.toStringTag];
gConstructorProperties['ArrayBuffer'] =
gConstructorProperties.ArrayBuffer =
constructorProps(["isView", Symbol.species]);
gPrototypeProperties['SharedArrayBuffer'] = ["constructor", "slice", "byteLength", Symbol.toStringTag];
gConstructorProperties['SharedArrayBuffer'] = constructorProps([Symbol.species]);
gPrototypeProperties.SharedArrayBuffer = ["constructor", "slice", "byteLength", Symbol.toStringTag];
gConstructorProperties.SharedArrayBuffer = constructorProps([Symbol.species]);
gPrototypeProperties['Map'] =
gPrototypeProperties.Map =
["constructor", "size", Symbol.toStringTag, "get", "has", "set", "delete",
"keys", "values", "clear", "forEach", "entries", Symbol.iterator];
gConstructorProperties['Map'] =
gConstructorProperties.Map =
constructorProps([Symbol.species]);
gPrototypeProperties['Set'] =
gPrototypeProperties.Set =
["constructor", "size", Symbol.toStringTag, "has", "add", "delete",
"keys", "values", "clear", "forEach", "entries", Symbol.iterator];
gConstructorProperties['Set'] =
gConstructorProperties.Set =
constructorProps([Symbol.species]);
gPrototypeProperties['WeakMap'] =
gPrototypeProperties.WeakMap =
["constructor", Symbol.toStringTag, "get", "has", "set", "delete"];
gConstructorProperties['WeakMap'] =
gConstructorProperties.WeakMap =
constructorProps([]);
gPrototypeProperties['WeakSet'] =
gPrototypeProperties.WeakSet =
["constructor", Symbol.toStringTag, "has", "add", "delete"];
gConstructorProperties['WeakSet'] =
gConstructorProperties.WeakSet =
constructorProps([]);
gPrototypeProperties['DataView'] =
gPrototypeProperties.DataView =
["constructor", "buffer", "byteLength", "byteOffset", Symbol.toStringTag,
"getInt8", "getUint8", "getInt16", "getUint16",
"getInt32", "getUint32", "getFloat32", "getFloat64",
"setInt8", "setUint8", "setInt16", "setUint16",
"setInt32", "setUint32", "setFloat32", "setFloat64",
"getBigInt64", "getBigUint64", "setBigInt64", "setBigUint64"]
gConstructorProperties['DataView'] = constructorProps([]);
gConstructorProperties.DataView = constructorProps([]);
// Sort an array that may contain symbols as well as strings.
function sortProperties(arr) {
@ -371,7 +371,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
is(lookupCallable(xray), method, "Proto props resolve on the instance");
let local = lookupCallable(localProto);
is(method.length, local.length, "Function.length identical");
if (method.length == 0) {
if (!method.length) {
is(method.call(xray) + "", local.call(xray) + "",
"Xray and local method results stringify identically");
@ -426,7 +426,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
// they live in, as far as I can tell, so testing them over Xrays will be
// wrong: on the Xray they will actaully get the lastMatch of _our_
// global, not the Xrayed one.
if (method.length == 0 &&
if (!method.length &&
!(localCtor.name == "Date" && name == "now") &&
!(localCtor.name == "RegExp" && (name == "lastMatch" || name == "$&"))) {
is(method.call(xrayCtor) + "", local.call(xrayCtor) + "",
@ -457,7 +457,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
let protoCallables = protoProps.filter(name => propertyIsGetter(localProto, name, classname) ||
typeof localProto[name] == 'function' &&
name != 'constructor');
ok(protoCallables.length > 0, "Need something to test");
ok(!!protoCallables.length, "Need something to test");
is(xrayProto, iwin[classname].prototype, "Xray proto is correct");
is(xrayProto, xray.__proto__, "Proto accessors agree");
var protoProto = classname == "Object" ? null : iwin.Object.prototype;
@ -777,7 +777,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
checkThrows(function() { trickyObject.hasOwnProperty = 33; }, /shadow/,
"Should reject shadowing of pre-existing inherited properties over Xrays");
checkThrows(function() { Object.defineProperty(trickyObject, 'rejectedProp', { get: function() {}}); },
checkThrows(function() { Object.defineProperty(trickyObject, 'rejectedProp', { get() {}}); },
/accessor property/, "Should reject accessor property definition");
}

View file

@ -1,3 +1,5 @@
// -*- coding: utf-8; indent-tabs-mode: nil -*-
var str = "π”˜π”«π”¦π” π”¬π”‘π”’";
function f() { return 42; }
function f() {
return 42;
}