mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
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:
parent
c42a565756
commit
88fb1d0fe1
@ -28,10 +28,10 @@ function test()
|
|||||||
actual = Array.prototype.toLocaleString.call((new String('foo')));
|
actual = Array.prototype.toLocaleString.call((new String('foo')));
|
||||||
assertEq(actual, expect, summary);
|
assertEq(actual, expect, summary);
|
||||||
|
|
||||||
assertEq('["f", "o", "o"]', Array.prototype.toSource.call(new String('foo')));
|
|
||||||
|
|
||||||
if (typeof Array.prototype.toSource != 'undefined')
|
if (typeof Array.prototype.toSource != 'undefined')
|
||||||
{
|
{
|
||||||
|
assertEq('["f", "o", "o"]', Array.prototype.toSource.call(new String('foo')));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Array.prototype.toSource.call('foo');
|
Array.prototype.toSource.call('foo');
|
||||||
|
@ -8,8 +8,10 @@ const nativeErrors = [
|
|||||||
URIError
|
URIError
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const expectedOwnKeys = "toSource" in Object.prototype
|
||||||
assertEq(Reflect.ownKeys(Error.prototype).toString(), "toSource,toString,message,name,stack,constructor");
|
? "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.name, "Error");
|
||||||
assertEq(Error.prototype.message, "");
|
assertEq(Error.prototype.message, "");
|
||||||
|
|
||||||
|
5
js/src/tests/non262/RegExp/prototype.js
vendored
5
js/src/tests/non262/RegExp/prototype.js
vendored
@ -1,9 +1,12 @@
|
|||||||
const t = RegExp.prototype;
|
const t = RegExp.prototype;
|
||||||
|
|
||||||
let properties = "toSource,toString,compile,exec,test," +
|
let properties = "toString,compile,exec,test," +
|
||||||
"flags,global,ignoreCase,multiline,source,sticky,unicode," +
|
"flags,global,ignoreCase,multiline,source,sticky,unicode," +
|
||||||
"constructor," +
|
"constructor," +
|
||||||
"Symbol(Symbol.match),Symbol(Symbol.replace),Symbol(Symbol.search),Symbol(Symbol.split)";
|
"Symbol(Symbol.match),Symbol(Symbol.replace),Symbol(Symbol.search),Symbol(Symbol.split)";
|
||||||
|
if (Object.prototype.toSource) {
|
||||||
|
properties = "toSource," + properties;
|
||||||
|
}
|
||||||
if (Symbol.matchAll) {
|
if (Symbol.matchAll) {
|
||||||
properties += ",Symbol(Symbol.matchAll)";
|
properties += ",Symbol(Symbol.matchAll)";
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,9 @@ function runTests() {
|
|||||||
assertEq(A.length, 10);
|
assertEq(A.length, 10);
|
||||||
assertEq(A.elementType, uint8);
|
assertEq(A.elementType, uint8);
|
||||||
assertEq(A.byteLength, 10);
|
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);
|
//assertEq(A.prototype.__proto__.__proto__, ArrayType.prototype.prototype);
|
||||||
|
|
||||||
|
@ -89,7 +89,9 @@ function runTests()
|
|||||||
check(() => type(+Infinity) === 0);
|
check(() => type(+Infinity) === 0);
|
||||||
check(() => type(-Infinity) === 0);
|
check(() => type(-Infinity) === 0);
|
||||||
check(() => type(NaN) === 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(null) == 0);
|
||||||
check(() => type(undefined) == 0);
|
check(() => type(undefined) == 0);
|
||||||
check(() => type([]) == 0);
|
check(() => type([]) == 0);
|
||||||
@ -110,7 +112,9 @@ function runTests()
|
|||||||
check(() => type(+Infinity) === Infinity);
|
check(() => type(+Infinity) === Infinity);
|
||||||
check(() => type(-Infinity) === -Infinity);
|
check(() => type(-Infinity) === -Infinity);
|
||||||
check(() => Number.isNaN(type(NaN)));
|
check(() => Number.isNaN(type(NaN)));
|
||||||
check(() => type.toSource() === floatStrings[i]);
|
if (Object.prototype.toSource) {
|
||||||
|
check(() => type.toSource() === floatStrings[i]);
|
||||||
|
}
|
||||||
check(() => type(null) == 0);
|
check(() => type(null) == 0);
|
||||||
check(() => Number.isNaN(type(undefined)));
|
check(() => Number.isNaN(type(undefined)));
|
||||||
check(() => type([]) == 0);
|
check(() => type([]) == 0);
|
||||||
|
@ -4,6 +4,8 @@ var summary = 'TypedObjects reference type coercions';
|
|||||||
var actual = '';
|
var actual = '';
|
||||||
var expect = '';
|
var expect = '';
|
||||||
|
|
||||||
|
var hasObjectPrototypeToSource = !!Object.prototype.toSource;
|
||||||
|
|
||||||
var ArrayType = TypedObject.ArrayType;
|
var ArrayType = TypedObject.ArrayType;
|
||||||
var StructType = TypedObject.StructType;
|
var StructType = TypedObject.StructType;
|
||||||
var Any = TypedObject.Any;
|
var Any = TypedObject.Any;
|
||||||
@ -60,9 +62,12 @@ function runTests()
|
|||||||
|
|
||||||
assertThrows(() => Object(undefined));
|
assertThrows(() => Object(undefined));
|
||||||
|
|
||||||
TestValues(Object, [{input: x, output: x},
|
TestValues(Object, [{input: x, output: x}]);
|
||||||
{input: 22.22, source: true, output: "(new Number(22.22))"},
|
|
||||||
{input: true, source: true, output: "(new Boolean(true))"}]);
|
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");
|
reportCompare(true, true, "TypedObjects reference type tests");
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,9 @@ function runTests() {
|
|||||||
var T = new StructType({x: int32, y: uint8, z: float64});
|
var T = new StructType({x: int32, y: uint8, z: float64});
|
||||||
assertEq(S.__proto__, StructType.prototype);
|
assertEq(S.__proto__, StructType.prototype);
|
||||||
assertEq(S.prototype.__proto__, StructType.prototype.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.byteLength, 16);
|
||||||
assertEq(S.byteAlignment, 8);
|
assertEq(S.byteAlignment, 8);
|
||||||
var fieldNames = Object.getOwnPropertyNames(S.fieldTypes);
|
var fieldNames = Object.getOwnPropertyNames(S.fieldTypes);
|
||||||
|
@ -46,7 +46,9 @@ function primitive(a) {
|
|||||||
|
|
||||||
for (var i = 0; i < a.length; i++) {
|
for (var i = 0; i < a.length; i++) {
|
||||||
var x = a[i];
|
var x = a[i];
|
||||||
var expectedSource = x.toSource();
|
if (x.toSource) {
|
||||||
|
var expectedSource = x.toSource();
|
||||||
|
}
|
||||||
var expectedPrimitive = primitive(x);
|
var expectedPrimitive = primitive(x);
|
||||||
var expectedProto = x.__proto__;
|
var expectedProto = x.__proto__;
|
||||||
var expectedString = Object.prototype.toString.call(x);
|
var expectedString = Object.prototype.toString.call(x);
|
||||||
@ -54,7 +56,9 @@ for (var i = 0; i < a.length; i++) {
|
|||||||
x.__proto__ = {};
|
x.__proto__ = {};
|
||||||
|
|
||||||
var y = deserialize(serialize(x));
|
var y = deserialize(serialize(x));
|
||||||
assertEq(y.toSource(), expectedSource);
|
if (x.toSource) {
|
||||||
|
assertEq(y.toSource(), expectedSource);
|
||||||
|
}
|
||||||
assertEq(primitive(y), expectedPrimitive);
|
assertEq(primitive(y), expectedPrimitive);
|
||||||
assertEq(y.__proto__, expectedProto);
|
assertEq(y.__proto__, expectedProto);
|
||||||
assertEq(Object.prototype.toString.call(y), expectedString);
|
assertEq(Object.prototype.toString.call(y), expectedString);
|
||||||
|
@ -28,16 +28,18 @@ catch(ex)
|
|||||||
reportCompare(expect, actual, summary + ': 1');
|
reportCompare(expect, actual, summary + ': 1');
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (Function.prototype.toSource) {
|
||||||
{
|
try
|
||||||
expect = 'function a(){\n return 1..toSource();\n}';
|
{
|
||||||
actual = a.toSource();
|
expect = 'function a(){\n return 1..toSource();\n}';
|
||||||
compareSource(expect, actual, summary + ': 2');
|
actual = a.toSource();
|
||||||
}
|
compareSource(expect, actual, summary + ': 2');
|
||||||
catch(ex)
|
}
|
||||||
{
|
catch(ex)
|
||||||
actual = ex + '';
|
{
|
||||||
reportCompare(expect, actual, summary + ': 2');
|
actual = ex + '';
|
||||||
|
reportCompare(expect, actual, summary + ': 2');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect = a;
|
expect = a;
|
||||||
|
@ -78,9 +78,11 @@ function test1()
|
|||||||
|
|
||||||
|
|
||||||
var e = new InternalError ("msg", "file", 2);
|
var e = new InternalError ("msg", "file", 2);
|
||||||
reportCompare ("(new InternalError(\"msg\", \"file\", 2))",
|
if (Error.prototype.toSource) {
|
||||||
e.toSource(),
|
reportCompare ("(new InternalError(\"msg\", \"file\", 2))",
|
||||||
"toSource() returned unexpected result.");
|
e.toSource(),
|
||||||
|
"toSource() returned unexpected result.");
|
||||||
|
}
|
||||||
reportCompare ("file", e.fileName,
|
reportCompare ("file", e.fileName,
|
||||||
"fileName property returned unexpected value.");
|
"fileName property returned unexpected value.");
|
||||||
reportCompare (2, e.lineNumber,
|
reportCompare (2, e.lineNumber,
|
||||||
@ -99,17 +101,19 @@ function test2()
|
|||||||
test file and assumes the path to the test case
|
test file and assumes the path to the test case
|
||||||
is a subdirectory of the directory containing jsDriver.pl
|
is a subdirectory of the directory containing jsDriver.pl
|
||||||
*/
|
*/
|
||||||
var expectedLine = 106;
|
var expectedLine = 108;
|
||||||
var expectedFileName = 'non262/extensions/regress-50447-1.js';
|
var expectedFileName = 'non262/extensions/regress-50447-1.js';
|
||||||
var expectedSource = /\(new InternalError\("msg", "([^"]+)", ([0-9]+)\)\)/;
|
var expectedSource = /\(new InternalError\("msg", "([^"]+)", ([0-9]+)\)\)/;
|
||||||
|
|
||||||
var e = new InternalError ("msg");
|
var e = new InternalError ("msg");
|
||||||
|
|
||||||
var actual = expectedSource.exec(e.toSource());
|
if (Error.prototype.toSource) {
|
||||||
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
|
var actual = expectedSource.exec(e.toSource());
|
||||||
"toSource() returned unexpected result (filename).");
|
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
|
||||||
reportCompare (actual[2], String(expectedLine),
|
"toSource() returned unexpected result (filename).");
|
||||||
"toSource() returned unexpected result (line).");
|
reportCompare (actual[2], String(expectedLine),
|
||||||
|
"toSource() returned unexpected result (line).");
|
||||||
|
}
|
||||||
reportCompare (normalize(e.fileName).endsWith(expectedFileName), true,
|
reportCompare (normalize(e.fileName).endsWith(expectedFileName), true,
|
||||||
"fileName property returned unexpected value.");
|
"fileName property returned unexpected value.");
|
||||||
reportCompare (expectedLine, e.lineNumber,
|
reportCompare (expectedLine, e.lineNumber,
|
||||||
@ -137,11 +141,13 @@ function test3()
|
|||||||
var e = new InternalError ("msg");
|
var e = new InternalError ("msg");
|
||||||
e.lineNumber = expectedLine;
|
e.lineNumber = expectedLine;
|
||||||
|
|
||||||
var actual = expectedSource.exec(e.toSource());
|
if (Error.prototype.toSource) {
|
||||||
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
|
var actual = expectedSource.exec(e.toSource());
|
||||||
"toSource() returned unexpected result (filename).");
|
reportCompare (normalize(actual[1]).endsWith(expectedFileName), true,
|
||||||
reportCompare (actual[2], String(expectedLine),
|
"toSource() returned unexpected result (filename).");
|
||||||
"toSource() returned unexpected result (line).");
|
reportCompare (actual[2], String(expectedLine),
|
||||||
|
"toSource() returned unexpected result (line).");
|
||||||
|
}
|
||||||
reportCompare (normalize(e.fileName).endsWith(expectedFileName), true,
|
reportCompare (normalize(e.fileName).endsWith(expectedFileName), true,
|
||||||
"fileName property returned unexpected value.");
|
"fileName property returned unexpected value.");
|
||||||
reportCompare (expectedLine, e.lineNumber,
|
reportCompare (expectedLine, e.lineNumber,
|
||||||
@ -156,12 +162,14 @@ function test4()
|
|||||||
/* generate an error with only msg and filename properties */
|
/* generate an error with only msg and filename properties */
|
||||||
|
|
||||||
|
|
||||||
var expectedLine = 161;
|
var expectedLine = 167;
|
||||||
|
|
||||||
var e = new InternalError ("msg", "file");
|
var e = new InternalError ("msg", "file");
|
||||||
reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))",
|
if (Error.prototype.toSource) {
|
||||||
e.toSource(),
|
reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))",
|
||||||
"toSource() returned unexpected result.");
|
e.toSource(),
|
||||||
|
"toSource() returned unexpected result.");
|
||||||
|
}
|
||||||
reportCompare ("file", e.fileName,
|
reportCompare ("file", e.fileName,
|
||||||
"fileName property returned unexpected value.");
|
"fileName property returned unexpected value.");
|
||||||
reportCompare (expectedLine, e.lineNumber,
|
reportCompare (expectedLine, e.lineNumber,
|
||||||
|
Loading…
Reference in New Issue
Block a user