Bug 1565001 - Part 19: Make tests for toSource conditional where necessary. r=evilpie

Allow these `toSource` specific tests to run even when `toSource` is not defined.

Depends on D56934

Differential Revision: https://phabricator.services.mozilla.com/D56935

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2019-12-13 19:19:12 +00:00
parent c42a565756
commit 88fb1d0fe1
10 changed files with 74 additions and 42 deletions

View File

@ -28,10 +28,10 @@ function test()
actual = Array.prototype.toLocaleString.call((new String('foo')));
assertEq(actual, expect, summary);
assertEq('["f", "o", "o"]', Array.prototype.toSource.call(new String('foo')));
if (typeof Array.prototype.toSource != 'undefined')
{
assertEq('["f", "o", "o"]', Array.prototype.toSource.call(new String('foo')));
try
{
Array.prototype.toSource.call('foo');

View File

@ -8,8 +8,10 @@ const nativeErrors = [
URIError
];
assertEq(Reflect.ownKeys(Error.prototype).toString(), "toSource,toString,message,name,stack,constructor");
const expectedOwnKeys = "toSource" in Object.prototype
? "toSource,toString,message,name,stack,constructor"
: "toString,message,name,stack,constructor";
assertEq(Reflect.ownKeys(Error.prototype).toString(), expectedOwnKeys);
assertEq(Error.prototype.name, "Error");
assertEq(Error.prototype.message, "");

View File

@ -1,9 +1,12 @@
const t = RegExp.prototype;
let properties = "toSource,toString,compile,exec,test," +
let properties = "toString,compile,exec,test," +
"flags,global,ignoreCase,multiline,source,sticky,unicode," +
"constructor," +
"Symbol(Symbol.match),Symbol(Symbol.replace),Symbol(Symbol.search),Symbol(Symbol.split)";
if (Object.prototype.toSource) {
properties = "toSource," + properties;
}
if (Symbol.matchAll) {
properties += ",Symbol(Symbol.matchAll)";
}

View File

@ -33,7 +33,9 @@ function runTests() {
assertEq(A.length, 10);
assertEq(A.elementType, uint8);
assertEq(A.byteLength, 10);
assertEq(A.toSource(), "new ArrayType(uint8, 10)");
if (Object.prototype.toSource) {
assertEq(A.toSource(), "new ArrayType(uint8, 10)");
}
//assertEq(A.prototype.__proto__.__proto__, ArrayType.prototype.prototype);

View File

@ -89,7 +89,9 @@ function runTests()
check(() => type(+Infinity) === 0);
check(() => type(-Infinity) === 0);
check(() => type(NaN) === 0);
check(() => type.toSource() === strings[i]);
if (Object.prototype.toSource) {
check(() => type.toSource() === strings[i]);
}
check(() => type(null) == 0);
check(() => type(undefined) == 0);
check(() => type([]) == 0);
@ -110,7 +112,9 @@ function runTests()
check(() => type(+Infinity) === Infinity);
check(() => type(-Infinity) === -Infinity);
check(() => Number.isNaN(type(NaN)));
check(() => type.toSource() === floatStrings[i]);
if (Object.prototype.toSource) {
check(() => type.toSource() === floatStrings[i]);
}
check(() => type(null) == 0);
check(() => Number.isNaN(type(undefined)));
check(() => type([]) == 0);

View File

@ -4,6 +4,8 @@ var summary = 'TypedObjects reference type coercions';
var actual = '';
var expect = '';
var hasObjectPrototypeToSource = !!Object.prototype.toSource;
var ArrayType = TypedObject.ArrayType;
var StructType = TypedObject.StructType;
var Any = TypedObject.Any;
@ -60,9 +62,12 @@ function runTests()
assertThrows(() => Object(undefined));
TestValues(Object, [{input: x, output: x},
{input: 22.22, source: true, output: "(new Number(22.22))"},
{input: true, source: true, output: "(new Boolean(true))"}]);
TestValues(Object, [{input: x, output: x}]);
if (hasObjectPrototypeToSource) {
TestValues(Object, [{input: 22.22, source: true, output: "(new Number(22.22))"},
{input: true, source: true, output: "(new Boolean(true))"}]);
}
reportCompare(true, true, "TypedObjects reference type tests");
}

View File

@ -21,7 +21,9 @@ function runTests() {
var T = new StructType({x: int32, y: uint8, z: float64});
assertEq(S.__proto__, StructType.prototype);
assertEq(S.prototype.__proto__, StructType.prototype.prototype);
assertEq(S.toSource(), "new StructType({x: int32, y: uint8, z: float64})");
if (Object.prototype.toSource) {
assertEq(S.toSource(), "new StructType({x: int32, y: uint8, z: float64})");
}
assertEq(S.byteLength, 16);
assertEq(S.byteAlignment, 8);
var fieldNames = Object.getOwnPropertyNames(S.fieldTypes);

View File

@ -46,7 +46,9 @@ function primitive(a) {
for (var i = 0; i < a.length; i++) {
var x = a[i];
var expectedSource = x.toSource();
if (x.toSource) {
var expectedSource = x.toSource();
}
var expectedPrimitive = primitive(x);
var expectedProto = x.__proto__;
var expectedString = Object.prototype.toString.call(x);
@ -54,7 +56,9 @@ for (var i = 0; i < a.length; i++) {
x.__proto__ = {};
var y = deserialize(serialize(x));
assertEq(y.toSource(), expectedSource);
if (x.toSource) {
assertEq(y.toSource(), expectedSource);
}
assertEq(primitive(y), expectedPrimitive);
assertEq(y.__proto__, expectedProto);
assertEq(Object.prototype.toString.call(y), expectedString);

View File

@ -28,16 +28,18 @@ catch(ex)
reportCompare(expect, actual, summary + ': 1');
}
try
{
expect = 'function a(){\n return 1..toSource();\n}';
actual = a.toSource();
compareSource(expect, actual, summary + ': 2');
}
catch(ex)
{
actual = ex + '';
reportCompare(expect, actual, summary + ': 2');
if (Function.prototype.toSource) {
try
{
expect = 'function a(){\n return 1..toSource();\n}';
actual = a.toSource();
compareSource(expect, actual, summary + ': 2');
}
catch(ex)
{
actual = ex + '';
reportCompare(expect, actual, summary + ': 2');
}
}
expect = a;

View File

@ -78,9 +78,11 @@ function test1()
var e = new InternalError ("msg", "file", 2);
reportCompare ("(new InternalError(\"msg\", \"file\", 2))",
e.toSource(),
"toSource() returned unexpected result.");
if (Error.prototype.toSource) {
reportCompare ("(new InternalError(\"msg\", \"file\", 2))",
e.toSource(),
"toSource() returned unexpected result.");
}
reportCompare ("file", e.fileName,
"fileName property returned unexpected value.");
reportCompare (2, e.lineNumber,
@ -99,17 +101,19 @@ function test2()
test file and assumes the path to the test case
is a subdirectory of the directory containing jsDriver.pl
*/
var expectedLine = 106;
var expectedLine = 108;
var expectedFileName = 'non262/extensions/regress-50447-1.js';
var expectedSource = /\(new InternalError\("msg", "([^"]+)", ([0-9]+)\)\)/;
var e = new InternalError ("msg");
var actual = expectedSource.exec(e.toSource());
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
"toSource() returned unexpected result (filename).");
reportCompare (actual[2], String(expectedLine),
"toSource() returned unexpected result (line).");
if (Error.prototype.toSource) {
var actual = expectedSource.exec(e.toSource());
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
"toSource() returned unexpected result (filename).");
reportCompare (actual[2], String(expectedLine),
"toSource() returned unexpected result (line).");
}
reportCompare (normalize(e.fileName).endsWith(expectedFileName), true,
"fileName property returned unexpected value.");
reportCompare (expectedLine, e.lineNumber,
@ -137,11 +141,13 @@ function test3()
var e = new InternalError ("msg");
e.lineNumber = expectedLine;
var actual = expectedSource.exec(e.toSource());
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
"toSource() returned unexpected result (filename).");
reportCompare (actual[2], String(expectedLine),
"toSource() returned unexpected result (line).");
if (Error.prototype.toSource) {
var actual = expectedSource.exec(e.toSource());
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
"toSource() returned unexpected result (filename).");
reportCompare (actual[2], String(expectedLine),
"toSource() returned unexpected result (line).");
}
reportCompare (normalize(e.fileName).endsWith(expectedFileName), true,
"fileName property returned unexpected value.");
reportCompare (expectedLine, e.lineNumber,
@ -156,12 +162,14 @@ function test4()
/* generate an error with only msg and filename properties */
var expectedLine = 161;
var expectedLine = 167;
var e = new InternalError ("msg", "file");
reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))",
e.toSource(),
"toSource() returned unexpected result.");
if (Error.prototype.toSource) {
reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))",
e.toSource(),
"toSource() returned unexpected result.");
}
reportCompare ("file", e.fileName,
"fileName property returned unexpected value.");
reportCompare (expectedLine, e.lineNumber,