Bug 1647187 - Use SameValue semantics in browser-chrome is() and similar methods; r=kmag

Use Object.is() instead of == in browser-chrome is() and similar methods.
Also use repr() (adapted from SimpleTest) to report failures more explicitly.

Differential Revision: https://phabricator.services.mozilla.com/D82947
This commit is contained in:
Geoff Brown 2020-07-30 18:50:26 +00:00
Родитель b00293dd89
Коммит 7ef556fb3a
1 изменённых файлов: 51 добавлений и 8 удалений

Просмотреть файл

@ -1325,18 +1325,18 @@ function testScope(aTester, aTest, expected) {
};
this.is = function test_is(a, b, name) {
self.record(
a == b,
Object.is(a, b),
name,
"Got " + a + ", expected " + b,
`Got ${self.repr(a)}, expected ${self.repr(b)}`,
false,
Components.stack.caller
);
};
this.isnot = function test_isnot(a, b, name) {
self.record(
a != b,
!Object.is(a, b),
name,
"Didn't expect " + a + ", but got it",
`Didn't expect ${self.repr(a)}, but got it`,
false,
Components.stack.caller
);
@ -1355,23 +1355,66 @@ function testScope(aTester, aTest, expected) {
};
this.todo_is = function test_todo_is(a, b, name) {
self.todo(
a == b,
Object.is(a, b),
name,
"Got " + a + ", expected " + b,
`Got ${self.repr(a)}, expected ${self.repr(b)}`,
Components.stack.caller
);
};
this.todo_isnot = function test_todo_isnot(a, b, name) {
self.todo(
a != b,
!Object.is(a, b),
name,
"Didn't expect " + a + ", but got it",
`Didn't expect ${self.repr(a)}, but got it`,
Components.stack.caller
);
};
this.info = function test_info(name) {
aTest.addResult(new testMessage(name));
};
this.repr = function repr(o) {
if (typeof o == "undefined") {
return "undefined";
} else if (o === null) {
return "null";
}
try {
if (typeof o.__repr__ == "function") {
return o.__repr__();
} else if (typeof o.repr == "function" && o.repr != repr) {
return o.repr();
}
} catch (e) {}
try {
if (
typeof o.NAME == "string" &&
(o.toString == Function.prototype.toString ||
o.toString == Object.prototype.toString)
) {
return o.NAME;
}
} catch (e) {}
var ostring;
try {
if (Object.is(o, +0)) {
ostring = "+0";
} else if (Object.is(o, -0)) {
ostring = "-0";
} else if (typeof o === "string") {
ostring = JSON.stringify(o);
} else if (Array.isArray(o)) {
ostring = "[" + o.map(val => repr(val)).join(", ") + "]";
} else {
ostring = String(o);
}
} catch (e) {
return `[${Object.prototype.toString.call(o)}]`;
}
if (typeof o == "function") {
ostring = ostring.replace(/\) \{[^]*/, ") { ... }");
}
return ostring;
};
this.executeSoon = function test_executeSoon(func) {
Services.tm.dispatchToMainThread({