1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

test-js: Use prettier and format all files

This commit is contained in:
Matthew Olsson 2020-07-05 09:27:00 -07:00 committed by Andreas Kling
parent e532888242
commit 6d58c48c2f
248 changed files with 8291 additions and 7725 deletions

View file

@ -0,0 +1,13 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "lf",
"insertPragma": false,
"printWidth": 100,
"quoteProps": "as-needed",
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}

View file

@ -1,6 +1,5 @@
test("Issue #1829, if-else without braces or semicolons", () => { test("Issue #1829, if-else without braces or semicolons", () => {
const source = const source = `if (1)
`if (1)
return 1; return 1;
else else
return 0; return 0;
@ -19,8 +18,7 @@ else
}); });
test("break/continue, variable declaration, do-while, and return asi", () => { test("break/continue, variable declaration, do-while, and return asi", () => {
const source = const source = `function foo() {
`function foo() {
label: label:
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
break // semicolon inserted here break // semicolon inserted here
@ -45,8 +43,7 @@ return foo();`;
}); });
test("more break and continue asi", () => { test("more break and continue asi", () => {
const source = const source = `let counter = 0;
`let counter = 0;
let outer; let outer;
outer: outer:

View file

@ -30,16 +30,23 @@ try {
assert(a[0][2] === 3); assert(a[0][2] === 3);
a = new Array(1, 2, 3); a = new Array(1, 2, 3);
Object.defineProperty(a, 3, { get() { return 10; } }); Object.defineProperty(a, 3, {
get() {
return 10;
},
});
assert(a.toString() === "1,2,3,10"); assert(a.toString() === "1,2,3,10");
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => { [-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(() => { assertThrowsError(
() => {
new Array(value); new Array(value);
}, { },
{
error: TypeError, error: TypeError,
message: "Invalid array length" message: "Invalid array length",
}); }
);
}); });
console.log("PASS"); console.log("PASS");

View file

@ -32,7 +32,11 @@ try {
assert(a[0][2] === 3); assert(a[0][2] === 3);
let t = [1, 2, 3]; let t = [1, 2, 3];
Object.defineProperty(t, 3, { get() { return 4; } }); Object.defineProperty(t, 3, {
get() {
return 4;
},
});
a = Array.of(...t); a = Array.of(...t);
assert(a.length === 4); assert(a.length === 4);
assert(a[0] === 1); assert(a[0] === 1);

View file

@ -46,7 +46,9 @@ try {
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar"); assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar");
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar"); assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar");
assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~"); assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~");
assert(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz"); assert(
Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz"
);
} }
{ {
@ -85,47 +87,70 @@ try {
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" }; const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
{ {
assertVisitsAll(visit => { assertVisitsAll(
visit => {
Array.prototype.every.call(o, function (value) { Array.prototype.every.call(o, function (value) {
visit(value); visit(value);
return true; return true;
}); });
}, ["foo", "bar", "baz"]); },
["foo", "bar", "baz"]
);
} }
["find", "findIndex"].forEach(name => { ["find", "findIndex"].forEach(name => {
assertVisitsAll(visit => { assertVisitsAll(
visit => {
Array.prototype[name].call(o, function (value) { Array.prototype[name].call(o, function (value) {
visit(value); visit(value);
return false; return false;
}); });
}, ["foo", "bar", undefined, "baz", undefined]); },
["foo", "bar", undefined, "baz", undefined]
);
}); });
["filter", "forEach", "map", "some"].forEach(name => { ["filter", "forEach", "map", "some"].forEach(name => {
assertVisitsAll(visit => { assertVisitsAll(
visit => {
Array.prototype[name].call(o, function (value) { Array.prototype[name].call(o, function (value) {
visit(value); visit(value);
return false; return false;
}); });
}, ["foo", "bar", "baz"]); },
["foo", "bar", "baz"]
);
}); });
{ {
assertVisitsAll(visit => { assertVisitsAll(
Array.prototype.reduce.call(o, function (_, value) { visit => {
Array.prototype.reduce.call(
o,
function (_, value) {
visit(value); visit(value);
return false; return false;
}, "initial"); },
}, ["foo", "bar", "baz"]); "initial"
);
},
["foo", "bar", "baz"]
);
} }
{ {
assertVisitsAll(visit => { assertVisitsAll(
Array.prototype.reduceRight.call(o, function (_, value) { visit => {
Array.prototype.reduceRight.call(
o,
function (_, value) {
visit(value); visit(value);
return false; return false;
}, "initial"); },
}, ["baz", "bar", "foo"]); "initial"
);
},
["baz", "bar", "foo"]
);
} }
console.log("PASS"); console.log("PASS");

View file

@ -8,11 +8,11 @@ try {
var array_concat = array.concat(); var array_concat = array.concat();
assert(array_concat.length === array.length); assert(array_concat.length === array.length);
array_concat = array.concat(1) array_concat = array.concat(1);
assert(array_concat.length === 3); assert(array_concat.length === 3);
assert(array_concat[2] === 1); assert(array_concat[2] === 1);
array_concat = array.concat([1, 2, 3]) array_concat = array.concat([1, 2, 3]);
assert(array_concat.length === 5); assert(array_concat.length === 5);
assert(array_concat[2] === 1); assert(array_concat[2] === 1);
assert(array_concat[3] === 2); assert(array_concat[3] === 2);
@ -30,7 +30,6 @@ try {
assert(array_concat[4][0] === 2); assert(array_concat[4][0] === 2);
assert(array_concat[4][1] === 3); assert(array_concat[4][1] === 3);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);

View file

@ -3,26 +3,29 @@ load("test-common.js");
try { try {
assert(Array.prototype.every.length === 1); assert(Array.prototype.every.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].every(undefined); [].every(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var arrayOne = ["serenity", { test: "serenity"} ]; var arrayOne = ["serenity", { test: "serenity" }];
var arrayTwo = [true, false, 1, 2, 3, "3"]; var arrayTwo = [true, false, 1, 2, 3, "3"];
assert(arrayOne.every(value => value === "hello") === false); assert(arrayOne.every(value => value === "hello") === false);
assert(arrayOne.every(value => value === "serenity") === false); assert(arrayOne.every(value => value === "serenity") === false);
assert(arrayOne.every((value, index, arr) => index < 2) === true); assert(arrayOne.every((value, index, arr) => index < 2) === true);
assert(arrayOne.every(value => typeof(value) === "string") === false); assert(arrayOne.every(value => typeof value === "string") === false);
assert(arrayOne.every(value => arrayOne.pop()) === true); assert(arrayOne.every(value => arrayOne.pop()) === true);
assert(arrayTwo.every((value, index, arr) => index > 0) === false); assert(arrayTwo.every((value, index, arr) => index > 0) === false);
assert(arrayTwo.every((value, index, arr) => index >= 0) === true); assert(arrayTwo.every((value, index, arr) => index >= 0) === true);
assert(arrayTwo.every(value => typeof(value) !== "string") === false); assert(arrayTwo.every(value => typeof value !== "string") === false);
assert(arrayTwo.every(value => typeof(value) === "number") === false); assert(arrayTwo.every(value => typeof value === "number") === false);
assert(arrayTwo.every(value => value > 0) === false); assert(arrayTwo.every(value => value > 0) === false);
assert(arrayTwo.every(value => value >= 0 && value < 4) === true); assert(arrayTwo.every(value => value >= 0 && value < 4) === true);
assert(arrayTwo.every(value => arrayTwo.pop()) === true); assert(arrayTwo.every(value => arrayTwo.pop()) === true);
@ -33,10 +36,12 @@ try {
arrayTwo = [true, false, 1, 2, 3, "3"]; arrayTwo = [true, false, 1, 2, 3, "3"];
// Every only goes up to the original length. // Every only goes up to the original length.
assert(arrayTwo.every((value, index, arr) => { assert(
arrayTwo.every((value, index, arr) => {
arr.push("serenity"); arr.push("serenity");
return value < 4; return value < 4;
}) === true); }) === true
);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -21,4 +21,3 @@ try {
} catch (e) { } catch (e) {
console.log("FAIL: " + e); console.log("FAIL: " + e);
} }

View file

@ -3,22 +3,30 @@ load("test-common.js");
try { try {
assert(Array.prototype.filter.length === 1); assert(Array.prototype.filter.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].filter(); [].filter();
}, { },
{
error: TypeError, error: TypeError,
message: "Array.prototype.filter() requires at least one argument" message: "Array.prototype.filter() requires at least one argument",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
[].filter(undefined); [].filter(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
assert([].filter(callback).length === 0); assert([].filter(callback).length === 0);
assert(callbackCalled === 0); assert(callbackCalled === 0);
@ -33,9 +41,20 @@ try {
assert(evenNumbers[2] === 4); assert(evenNumbers[2] === 4);
assert(evenNumbers[3] === 6); assert(evenNumbers[3] === 6);
var fruits = ["Apple", "Banana", "Blueberry", "Grape", "Mango", "Orange", "Peach", "Pineapple", "Raspberry", "Watermelon"]; var fruits = [
"Apple",
"Banana",
"Blueberry",
"Grape",
"Mango",
"Orange",
"Peach",
"Pineapple",
"Raspberry",
"Watermelon",
];
const filterItems = (arr, query) => { const filterItems = (arr, query) => {
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1) return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1);
}; };
var results; var results;

View file

@ -3,12 +3,15 @@ load("test-common.js");
try { try {
assert(Array.prototype.find.length === 1); assert(Array.prototype.find.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].find(undefined); [].find(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var array = ["hello", "friends", 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
@ -16,17 +19,19 @@ try {
assert(array.find((value, index, arr) => index === 1) === "friends"); assert(array.find((value, index, arr) => index === 1) === "friends");
assert(array.find(value => value == "1") === 1); assert(array.find(value => value == "1") === 1);
assert(array.find(value => value === 1) === 1); assert(array.find(value => value === 1) === 1);
assert(array.find(value => typeof(value) !== "string") === 1); assert(array.find(value => typeof value !== "string") === 1);
assert(array.find(value => typeof(value) === "boolean") === false); assert(array.find(value => typeof value === "boolean") === false);
assert(array.find(value => value > 1) === 2); assert(array.find(value => value > 1) === 2);
assert(array.find(value => value > 1 && value < 3) === 2); assert(array.find(value => value > 1 && value < 3) === 2);
assert(array.find(value => value > 100) === undefined); assert(array.find(value => value > 100) === undefined);
assert([].find(value => value === 1) === undefined); assert([].find(value => value === 1) === undefined);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
[].find(callback) [].find(callback);
assert(callbackCalled === 0); assert(callbackCalled === 0);
[1, 2, 3].find(callback); [1, 2, 3].find(callback);

View file

@ -3,12 +3,15 @@ load("test-common.js");
try { try {
assert(Array.prototype.findIndex.length === 1); assert(Array.prototype.findIndex.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].findIndex(undefined); [].findIndex(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var array = ["hello", "friends", 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
@ -16,17 +19,19 @@ try {
assert(array.findIndex((value, index, arr) => index === 1) === 1); assert(array.findIndex((value, index, arr) => index === 1) === 1);
assert(array.findIndex(value => value == "1") === 2); assert(array.findIndex(value => value == "1") === 2);
assert(array.findIndex(value => value === 1) === 2); assert(array.findIndex(value => value === 1) === 2);
assert(array.findIndex(value => typeof(value) !== "string") === 2); assert(array.findIndex(value => typeof value !== "string") === 2);
assert(array.findIndex(value => typeof(value) === "boolean") === 4); assert(array.findIndex(value => typeof value === "boolean") === 4);
assert(array.findIndex(value => value > 1) === 3); assert(array.findIndex(value => value > 1) === 3);
assert(array.findIndex(value => value > 1 && value < 3) === 3); assert(array.findIndex(value => value > 1 && value < 3) === 3);
assert(array.findIndex(value => value > 100) === -1); assert(array.findIndex(value => value > 100) === -1);
assert([].findIndex(value => value === 1) === -1); assert([].findIndex(value => value === 1) === -1);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
[].findIndex(callback) [].findIndex(callback);
assert(callbackCalled === 0); assert(callbackCalled === 0);
[1, 2, 3].findIndex(callback); [1, 2, 3].findIndex(callback);

View file

@ -3,24 +3,32 @@ load("test-common.js");
try { try {
assert(Array.prototype.forEach.length === 1); assert(Array.prototype.forEach.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].forEach(); [].forEach();
}, { },
{
error: TypeError, error: TypeError,
message: "Array.prototype.forEach() requires at least one argument" message: "Array.prototype.forEach() requires at least one argument",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
[].forEach(undefined); [].forEach(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var a = [1, 2, 3]; var a = [1, 2, 3];
var o = {}; var o = {};
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
assert([].forEach(callback) === undefined); assert([].forEach(callback) === undefined);
assert(callbackCalled === 0); assert(callbackCalled === 0);
@ -29,13 +37,13 @@ try {
assert(callbackCalled === 3); assert(callbackCalled === 3);
callbackCalled = 0; callbackCalled = 0;
a.forEach(function(value, index) { a.forEach(function (value, index) {
assert(value === a[index]); assert(value === a[index]);
assert(index === a[index] - 1); assert(index === a[index] - 1);
}); });
callbackCalled = 0; callbackCalled = 0;
a.forEach(function(_, _, array) { a.forEach(function (_, _, array) {
callbackCalled++; callbackCalled++;
assert(a.length === array.length); assert(a.length === array.length);
a.push("test"); a.push("test");
@ -44,7 +52,7 @@ try {
assert(a.length === 6); assert(a.length === 6);
callbackCalled = 0; callbackCalled = 0;
a.forEach(function(value, index) { a.forEach(function (value, index) {
callbackCalled++; callbackCalled++;
this[index] = value; this[index] = value;
}, o); }, o);

View file

@ -3,18 +3,18 @@ load("test-common.js");
try { try {
assert(Array.prototype.includes.length === 1); assert(Array.prototype.includes.length === 1);
var array = ['hello', 'friends', 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
assert([].includes() === false); assert([].includes() === false);
assert([undefined].includes() === true); assert([undefined].includes() === true);
assert(array.includes('hello') === true); assert(array.includes("hello") === true);
assert(array.includes(1) === true); assert(array.includes(1) === true);
assert(array.includes(1, -3) === true); assert(array.includes(1, -3) === true);
assert(array.includes('serenity') === false); assert(array.includes("serenity") === false);
assert(array.includes(false, -1) === true); assert(array.includes(false, -1) === true);
assert(array.includes(2, -1) === false); assert(array.includes(2, -1) === false);
assert(array.includes(2, -100) === true); assert(array.includes(2, -100) === true);
assert(array.includes('friends', 100) === false); assert(array.includes("friends", 100) === false);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -3,23 +3,23 @@ load("test-common.js");
try { try {
assert(Array.prototype.indexOf.length === 1); assert(Array.prototype.indexOf.length === 1);
var array = ['hello', 'friends', 1, 2, false]; var array = ["hello", "friends", 1, 2, false];
assert(array.indexOf('hello') === 0); assert(array.indexOf("hello") === 0);
assert(array.indexOf('friends') === 1); assert(array.indexOf("friends") === 1);
assert(array.indexOf(false) === 4); assert(array.indexOf(false) === 4);
assert(array.indexOf(false, 2) === 4); assert(array.indexOf(false, 2) === 4);
assert(array.indexOf(false, -2) === 4); assert(array.indexOf(false, -2) === 4);
assert(array.indexOf(1) === 2); assert(array.indexOf(1) === 2);
assert(array.indexOf(1, 1000) === -1); assert(array.indexOf(1, 1000) === -1);
assert(array.indexOf(1, -1000) === 2); assert(array.indexOf(1, -1000) === 2);
assert(array.indexOf('serenity') === -1); assert(array.indexOf("serenity") === -1);
assert(array.indexOf(false, -1) === 4); assert(array.indexOf(false, -1) === 4);
assert(array.indexOf(2, -1) === -1); assert(array.indexOf(2, -1) === -1);
assert(array.indexOf(2, -2) === 3); assert(array.indexOf(2, -2) === 3);
assert([].indexOf('serenity') === -1); assert([].indexOf("serenity") === -1);
assert([].indexOf('serenity', 10) === -1); assert([].indexOf("serenity", 10) === -1);
assert([].indexOf('serenity', -10) === -1); assert([].indexOf("serenity", -10) === -1);
assert([].indexOf() === -1); assert([].indexOf() === -1);
assert([undefined].indexOf() === 0); assert([undefined].indexOf() === 0);

View file

@ -13,9 +13,9 @@ try {
assert(array.lastIndexOf(2) === 1); assert(array.lastIndexOf(2) === 1);
assert(array.lastIndexOf(2, -3) === 1); assert(array.lastIndexOf(2, -3) === 1);
assert(array.lastIndexOf(2, -4) === 1); assert(array.lastIndexOf(2, -4) === 1);
assert([].lastIndexOf('hello') === -1); assert([].lastIndexOf("hello") === -1);
assert([].lastIndexOf('hello', 10) === -1); assert([].lastIndexOf("hello", 10) === -1);
assert([].lastIndexOf('hello', -10) === -1); assert([].lastIndexOf("hello", -10) === -1);
assert([].lastIndexOf() === -1); assert([].lastIndexOf() === -1);
assert([undefined].lastIndexOf() === 0); assert([undefined].lastIndexOf() === 0);
assert([undefined, undefined, undefined].lastIndexOf() === 2); assert([undefined, undefined, undefined].lastIndexOf() === 2);

View file

@ -3,22 +3,30 @@ load("test-common.js");
try { try {
assert(Array.prototype.map.length === 1); assert(Array.prototype.map.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].map(); [].map();
}, { },
{
error: TypeError, error: TypeError,
message: "Array.prototype.map() requires at least one argument" message: "Array.prototype.map() requires at least one argument",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
[].map(undefined); [].map(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; }; var callback = () => {
callbackCalled++;
};
assert([].map(callback).length === 0); assert([].map(callback).length === 0);
assert(callbackCalled === 0); assert(callbackCalled === 0);
@ -30,7 +38,9 @@ try {
assert([1, , , "foo", , undefined, , ,].map(callback).length === 8); assert([1, , , "foo", , undefined, , ,].map(callback).length === 8);
assert(callbackCalled === 3); assert(callbackCalled === 3);
var results = [undefined, null, true, "foo", 42, {}].map((value, index) => "" + index + " -> " + value); var results = [undefined, null, true, "foo", 42, {}].map(
(value, index) => "" + index + " -> " + value
);
assert(results.length === 6); assert(results.length === 6);
assert(results[0] === "0 -> undefined"); assert(results[0] === "0 -> undefined");
assert(results[1] === "1 -> null"); assert(results[1] === "1 -> null");

View file

@ -3,38 +3,55 @@ load("test-common.js");
try { try {
assert(Array.prototype.reduce.length === 1); assert(Array.prototype.reduce.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[1].reduce(); [1].reduce();
}, { },
{
error: TypeError, error: TypeError,
message: "Array.prototype.reduce() requires at least one argument" message: "Array.prototype.reduce() requires at least one argument",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
[1].reduce(undefined); [1].reduce(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
[].reduce((a, x) => x); [].reduce((a, x) => x);
}, { },
{
error: TypeError, error: TypeError,
message: "Reduce of empty array with no initial value" message: "Reduce of empty array with no initial value",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
[, ,].reduce((a, x) => x); [, ,].reduce((a, x) => x);
}, { },
{
error: TypeError, error: TypeError,
message: "Reduce of empty array with no initial value" message: "Reduce of empty array with no initial value",
}); }
);
[1, 2].reduce(function () { assert(this === undefined) }); [1, 2].reduce(function () {
assert(this === undefined);
});
var callbackCalled = 0; var callbackCalled = 0;
var callback = () => { callbackCalled++; return true }; var callback = () => {
callbackCalled++;
return true;
};
assert([1].reduce(callback) === 1); assert([1].reduce(callback) === 1);
assert(callbackCalled === 0); assert(callbackCalled === 0);
@ -70,18 +87,24 @@ try {
result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100); result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100);
assert(result === 121); assert(result === 121);
result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => { return accum + elem }, 100); result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => {
return accum + elem;
}, 100);
assert(result === 121); assert(result === 121);
var indexes = []; var indexes = [];
result = ["foo", 1, true].reduce((a, v, i) => { indexes.push(i) }); result = ["foo", 1, true].reduce((a, v, i) => {
indexes.push(i);
});
assert(result === undefined); assert(result === undefined);
assert(indexes.length === 2); assert(indexes.length === 2);
assert(indexes[0] === 1); assert(indexes[0] === 1);
assert(indexes[1] === 2); assert(indexes[1] === 2);
indexes = []; indexes = [];
result = ["foo", 1, true].reduce((a, v, i) => { indexes.push(i) }, "foo"); result = ["foo", 1, true].reduce((a, v, i) => {
indexes.push(i);
}, "foo");
assert(result === undefined); assert(result === undefined);
assert(indexes.length === 3); assert(indexes.length === 3);
assert(indexes[0] === 0); assert(indexes[0] === 0);
@ -89,13 +112,18 @@ try {
assert(indexes[2] === 2); assert(indexes[2] === 2);
var mutable = { prop: 0 }; var mutable = { prop: 0 };
result = ["foo", 1, true].reduce((a, v) => { a.prop = v; return a; }, mutable); result = ["foo", 1, true].reduce((a, v) => {
a.prop = v;
return a;
}, mutable);
assert(result === mutable); assert(result === mutable);
assert(result.prop === true); assert(result.prop === true);
var a1 = [1, 2]; var a1 = [1, 2];
var a2 = null; var a2 = null;
a1.reduce((a, v, i, t) => { a2 = t }); a1.reduce((a, v, i, t) => {
a2 = t;
});
assert(a1 === a2); assert(a1 === a2);
console.log("PASS"); console.log("PASS");

View file

@ -13,7 +13,7 @@ try {
assert(array_slice[2] === "serenity"); assert(array_slice[2] === "serenity");
assert(array_slice[3] === 1); assert(array_slice[3] === 1);
array_slice = array.slice(1) array_slice = array.slice(1);
assert(array_slice.length === 3); assert(array_slice.length === 3);
assert(array_slice[0] === "friends"); assert(array_slice[0] === "friends");
assert(array_slice[1] === "serenity"); assert(array_slice[1] === "serenity");

View file

@ -3,14 +3,17 @@ load("test-common.js");
try { try {
assert(Array.prototype.some.length === 1); assert(Array.prototype.some.length === 1);
assertThrowsError(() => { assertThrowsError(
() => {
[].some(undefined); [].some(undefined);
}, { },
{
error: TypeError, error: TypeError,
message: "undefined is not a function" message: "undefined is not a function",
}); }
);
var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos"}]; var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }];
assert(array.some(value => value === "hello") === true); assert(array.some(value => value === "hello") === true);
assert(array.some(value => value === "serenity") === false); assert(array.some(value => value === "serenity") === false);
@ -18,8 +21,8 @@ try {
assert(array.some(value => value == "1") === true); assert(array.some(value => value == "1") === true);
assert(array.some(value => value === 1) === true); assert(array.some(value => value === 1) === true);
assert(array.some(value => value === 13) === false); assert(array.some(value => value === 13) === false);
assert(array.some(value => typeof(value) !== "string") === true); assert(array.some(value => typeof value !== "string") === true);
assert(array.some(value => typeof(value) === "boolean") === true); assert(array.some(value => typeof value === "boolean") === true);
assert(array.some(value => value > 1) === true); assert(array.some(value => value > 1) === true);
assert(array.some(value => value > 1 && value < 3) === true); assert(array.some(value => value > 1 && value < 3) === true);
assert(array.some(value => value > 100) === false); assert(array.some(value => value > 100) === false);

View file

@ -13,7 +13,7 @@ try {
toString: () => { toString: () => {
toStringCalled++; toStringCalled++;
return "o"; return "o";
} },
}; };
assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o"); assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o");
assert(toStringCalled === 3); assert(toStringCalled === 3);

View file

@ -2,9 +2,9 @@ load("test-common.js");
try { try {
var a = [1, 2, 3]; var a = [1, 2, 3];
assert(a.toString() === '1,2,3'); assert(a.toString() === "1,2,3");
assert([].toString() === ''); assert([].toString() === "");
assert([5].toString() === '5'); assert([5].toString() === "5");
assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)"); assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)");

View file

@ -22,7 +22,7 @@ try {
assert(a.toString() === ""); assert(a.toString() === "");
assert(a[0] === undefined); assert(a[0] === undefined);
a = [,,,,]; a = [, , , ,];
assert(a.length === 4); assert(a.length === 4);
assert(a.toString() === ",,,"); assert(a.toString() === ",,,");
assert(a[0] === undefined); assert(a[0] === undefined);
@ -30,7 +30,7 @@ try {
assert(a[2] === undefined); assert(a[2] === undefined);
assert(a[3] === undefined); assert(a[3] === undefined);
a = [1,,2,,,3,]; a = [1, , 2, , , 3];
assert(a.length === 6); assert(a.length === 6);
assert(a.toString() === "1,,2,,,3"); assert(a.toString() === "1,,2,,,3");
assert(a[0] === 1); assert(a[0] === 1);
@ -40,7 +40,7 @@ try {
assert(a[4] === undefined); assert(a[4] === undefined);
assert(a[5] === 3); assert(a[5] === 3);
a = [1,,2,,,3,]; a = [1, , 2, , , 3];
Object.defineProperty(a, 1, { Object.defineProperty(a, 1, {
get() { get() {
return this.secret_prop; return this.secret_prop;

View file

@ -33,12 +33,15 @@ try {
assert(a.length === 1); assert(a.length === 1);
[undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => { [undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(() => { assertThrowsError(
() => {
a.length = value; a.length = value;
}, { },
{
error: RangeError, error: RangeError,
message: "Invalid array length" message: "Invalid array length",
}); }
);
assert(a.length === 1); assert(a.length === 1);
}); });

View file

@ -1,11 +1,7 @@
load("test-common.js"); load("test-common.js");
function testArray(arr) { function testArray(arr) {
return arr.length === 4 && return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3;
arr[0] === 0 &&
arr[1] === 1 &&
arr[2] === 2 &&
arr[3] === 3;
} }
try { try {
@ -23,20 +19,25 @@ try {
arr = [...[], ...[...[0, 1, 2]], 3]; arr = [...[], ...[...[0, 1, 2]], 3];
assert(testArray(arr)); assert(testArray(arr));
assertThrowsError(() => { assertThrowsError(
() => {
[...1]; [...1];
}, { },
{
error: TypeError, error: TypeError,
message: "1 is not iterable", message: "1 is not iterable",
}); }
);
assertThrowsError(
assertThrowsError(() => { () => {
[...{}]; [...{}];
}, { },
{
error: TypeError, error: TypeError,
message: "[object Object] is not iterable", message: "[object Object] is not iterable",
}); }
);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -18,42 +18,58 @@ try {
assert(BigInt("42") === 42n); assert(BigInt("42") === 42n);
assert(BigInt(" \n 00100 \n ") === 100n); assert(BigInt(" \n 00100 \n ") === 100n);
assert(BigInt(123n) === 123n); assert(BigInt(123n) === 123n);
assert(BigInt("3323214327642987348732109829832143298746432437532197321") === 3323214327642987348732109829832143298746432437532197321n); assert(
BigInt("3323214327642987348732109829832143298746432437532197321") ===
3323214327642987348732109829832143298746432437532197321n
);
assertThrowsError(() => { assertThrowsError(
() => {
new BigInt(); new BigInt();
}, { },
{
error: TypeError, error: TypeError,
message: "BigInt is not a constructor" message: "BigInt is not a constructor",
}); }
);
[null, undefined, Symbol()].forEach(value => { [null, undefined, Symbol()].forEach(value => {
assertThrowsError(() => { assertThrowsError(
() => {
BigInt(value); BigInt(value);
}, { },
{
error: TypeError, error: TypeError,
message: typeof value === "symbol" message:
typeof value === "symbol"
? "Cannot convert symbol to BigInt" ? "Cannot convert symbol to BigInt"
: `Cannot convert ${value} to BigInt` : `Cannot convert ${value} to BigInt`,
}); }
);
}); });
["foo", "123n", "1+1", {}, function () { }].forEach(value => { ["foo", "123n", "1+1", {}, function () {}].forEach(value => {
assertThrowsError(() => { assertThrowsError(
() => {
BigInt(value); BigInt(value);
}, { },
{
error: SyntaxError, error: SyntaxError,
message: `Invalid value for BigInt: ${value}` message: `Invalid value for BigInt: ${value}`,
}); }
);
}); });
[1.23, Infinity, -Infinity, NaN].forEach(value => { [1.23, Infinity, -Infinity, NaN].forEach(value => {
assertThrowsError(() => { assertThrowsError(
() => {
BigInt(value); BigInt(value);
}, { },
{
error: RangeError, error: RangeError,
message: "BigInt argument must be an integer" message: "BigInt argument must be an integer",
}); }
);
}); });
console.log("PASS"); console.log("PASS");

View file

@ -3,12 +3,15 @@ load("test-common.js");
try { try {
assert(BigInt.prototype.toLocaleString.length === 0); assert(BigInt.prototype.toLocaleString.length === 0);
assertThrowsError(() => { assertThrowsError(
() => {
BigInt.prototype.toLocaleString.call("foo"); BigInt.prototype.toLocaleString.call("foo");
}, { },
{
error: TypeError, error: TypeError,
message: "Not a BigInt object" message: "Not a BigInt object",
}); }
);
assert(BigInt(123).toLocaleString() === "123"); assert(BigInt(123).toLocaleString() === "123");

View file

@ -3,12 +3,15 @@ load("test-common.js");
try { try {
assert(BigInt.prototype.toString.length === 0); assert(BigInt.prototype.toString.length === 0);
assertThrowsError(() => { assertThrowsError(
() => {
BigInt.prototype.toString.call("foo"); BigInt.prototype.toString.call("foo");
}, { },
{
error: TypeError, error: TypeError,
message: "Not a BigInt object" message: "Not a BigInt object",
}); }
);
assert(BigInt(123).toString() === "123"); assert(BigInt(123).toString() === "123");

View file

@ -3,12 +3,15 @@ load("test-common.js");
try { try {
assert(BigInt.prototype.valueOf.length === 0); assert(BigInt.prototype.valueOf.length === 0);
assertThrowsError(() => { assertThrowsError(
() => {
BigInt.prototype.valueOf.call("foo"); BigInt.prototype.valueOf.call("foo");
}, { },
{
error: TypeError, error: TypeError,
message: "Not a BigInt object" message: "Not a BigInt object",
}); }
);
assert(typeof BigInt(123).valueOf() === "bigint"); assert(typeof BigInt(123).valueOf() === "bigint");
// FIXME: Uncomment once we support Object() with argument // FIXME: Uncomment once we support Object() with argument

View file

@ -5,14 +5,17 @@ try {
assert(typeof bigint === "bigint"); assert(typeof bigint === "bigint");
assert(-bigint === -123n); assert(-bigint === -123n);
assert("" + bigint === "123") assert("" + bigint === "123");
assertThrowsError(() => { assertThrowsError(
() => {
+bigint; +bigint;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot convert BigInt to number" message: "Cannot convert BigInt to number",
}); }
);
assert(12n + 34n === 46n); assert(12n + 34n === 46n);
assert(12n - 34n === -22n); assert(12n - 34n === -22n);
@ -20,7 +23,11 @@ try {
assert(123n / 10n === 12n); assert(123n / 10n === 12n);
assert(2n ** 3n === 8n); assert(2n ** 3n === 8n);
assert(5n % 3n === 2n); assert(5n % 3n === 2n);
assert(45977665298704210987n + 714320987142450987412098743217984576n / 4598741987421098765327980n * 987498743n === 199365500239020623962n); assert(
45977665298704210987n +
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n ===
199365500239020623962n
);
assert((12n & 5n) === 4n); assert((12n & 5n) === 4n);
assert((1n | 2n) === 3n); assert((1n | 2n) === 3n);
@ -37,7 +44,6 @@ try {
assert(--bigint === 1n); assert(--bigint === 1n);
assert(bigint === 1n); assert(bigint === 1n);
assert((1n == 1n) === true); assert((1n == 1n) === true);
assert((1n == 1) === true); assert((1n == 1) === true);
assert((1 == 1n) === true); assert((1 == 1n) === true);

View file

@ -2,78 +2,114 @@ load("test-common.js");
try { try {
[1, null, undefined].forEach(value => { [1, null, undefined].forEach(value => {
assertThrowsError(() => { assertThrowsError(
() => {
1n + value; 1n + value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use addition operator with BigInt and other type" message: "Cannot use addition operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n - value; 1n - value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use subtraction operator with BigInt and other type" message: "Cannot use subtraction operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n * value; 1n * value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use multiplication operator with BigInt and other type" message: "Cannot use multiplication operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n / value; 1n / value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use division operator with BigInt and other type" message: "Cannot use division operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n % value; 1n % value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use modulo operator with BigInt and other type" message: "Cannot use modulo operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n ** value; 1n ** value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use exponentiation operator with BigInt and other type" message: "Cannot use exponentiation operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n | value; 1n | value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use bitwise OR operator with BigInt and other type" message: "Cannot use bitwise OR operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n & value; 1n & value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use bitwise AND operator with BigInt and other type" message: "Cannot use bitwise AND operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n ^ value; 1n ^ value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use bitwise XOR operator with BigInt and other type" message: "Cannot use bitwise XOR operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n << value; 1n << value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use left-shift operator with BigInt and other type" message: "Cannot use left-shift operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n >> value; 1n >> value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use right-shift operator with BigInt and other type" message: "Cannot use right-shift operator with BigInt and other type",
}); }
assertThrowsError(() => { );
assertThrowsError(
() => {
1n >>> value; 1n >>> value;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot use unsigned right-shift operator with BigInt" message: "Cannot use unsigned right-shift operator with BigInt",
}); }
);
}); });
console.log("PASS"); console.log("PASS");

View file

@ -7,7 +7,7 @@ test("typeof", () => {
expect(typeof new Boolean()).toBe("object"); expect(typeof new Boolean()).toBe("object");
expect(typeof Boolean()).toBe("boolean"); expect(typeof Boolean()).toBe("boolean");
expect(typeof Boolean(true)).toBe("boolean"); expect(typeof Boolean(true)).toBe("boolean");
}) });
test("basic functionality", () => { test("basic functionality", () => {
var foo = new Boolean(true); var foo = new Boolean(true);

View file

@ -1,5 +1,5 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(typeof Boolean.prototype).toBe("object"); expect(typeof Boolean.prototype).toBe("object");
expect(Boolean.prototype.valueOf()).toBeFalse(); expect(Boolean.prototype.valueOf()).toBeFalse();
expect(Boolean.prototype.length).toBeUndefined(); expect(Boolean.prototype).not.toHaveProperty("length");
}); });

View file

@ -12,8 +12,8 @@ describe("correct behavior", () => {
}); });
test("basic functionality", () => { test("basic functionality", () => {
expect(Function()()).toBe(undefined); expect(Function()()).toBeUndefined();
expect(new Function()()).toBe(undefined); expect(new Function()()).toBeUndefined();
expect(Function("return 42")()).toBe(42); expect(Function("return 42")()).toBe(42);
expect(new Function("return 42")()).toBe(42); expect(new Function("return 42")()).toBe(42);
expect(new Function("foo", "return foo")(42)).toBe(42); expect(new Function("foo", "return foo")(42)).toBe(42);
@ -22,7 +22,9 @@ describe("correct behavior", () => {
expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42); expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe("bar"); expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe(
"bar"
);
expect(new Function("return typeof Function()")()).toBe("function"); expect(new Function("return typeof Function()")()).toBe("function");
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3); expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
@ -39,6 +41,9 @@ describe("errors", () => {
// This might be confusing at first but keep in mind it's actually parsing // This might be confusing at first but keep in mind it's actually parsing
// function anonymous() { [ } // function anonymous() { [ }
// This is in line with what other engines are reporting. // This is in line with what other engines are reporting.
.toThrowWithMessage(SyntaxError, "Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"); .toThrowWithMessage(
SyntaxError,
"Unexpected token CurlyClose. Expected BracketClose (line: 1, column: 26)"
);
}); });
}); });

View file

@ -42,7 +42,9 @@ test("basic functionality", () => {
var add = (x, y) => x + y; var add = (x, y) => x + y;
expect(add.apply(null, [1, 2])).toBe(3); expect(add.apply(null, [1, 2])).toBe(3);
var multiply = function (x, y) { return x * y; }; var multiply = function (x, y) {
return x * y;
};
expect(multiply.apply(null, [3, 4])).toBe(12); expect(multiply.apply(null, [3, 4])).toBe(12);
expect((() => this).apply("foo")).toBe(globalThis); expect((() => this).apply("foo")).toBe(globalThis);

View file

@ -1,6 +1,6 @@
describe("basic behavior", () => { describe("basic behavior", () => {
test("basic binding", () => { test("basic binding", () => {
expect(Function.prototype.bind.length).toBe(1); expect(Function.prototype.bind).toHaveLength(1);
var charAt = String.prototype.charAt.bind("bar"); var charAt = String.prototype.charAt.bind("bar");
expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar"); expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
@ -17,9 +17,21 @@ describe("basic behavior", () => {
var MakeTrue = Boolean.bind(null, true); var MakeTrue = Boolean.bind(null, true);
expect([1, 2, 3].filter(MakeTrue).length).toBe(3); expect([1, 2, 3].filter(MakeTrue)).toHaveLength(3);
expect([1, 2, 3].reduce((function (acc, x) { return acc + x }).bind(null, 4, 5))).toBe(9); expect(
expect([1, 2, 3].reduce((function (acc, x) { return acc + x + this; }).bind(3))).toBe(12); [1, 2, 3].reduce(
function (acc, x) {
return acc + x;
}.bind(null, 4, 5)
)
).toBe(9);
expect(
[1, 2, 3].reduce(
function (acc, x) {
return acc + x + this;
}.bind(3)
)
).toBe(12);
}); });
}); });
@ -51,7 +63,7 @@ describe("bound function arguments", () => {
expect(boundSum.bind(null, 5)).toHaveLength(0); expect(boundSum.bind(null, 5)).toHaveLength(0);
expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0); expect(boundSum.bind(null, 5, 6, 7, 8)).toHaveLength(0);
}); });
}) });
describe("bound function |this|", () => { describe("bound function |this|", () => {
function identity() { function identity() {
@ -98,9 +110,9 @@ describe("bound function |this|", () => {
}); });
test("arrow functions cannot be bound", () => { test("arrow functions cannot be bound", () => {
expect((() => this).bind("foo")()).toBe(globalThis) expect((() => this).bind("foo")()).toBe(globalThis);
}); });
}) });
describe("bound function constructors", () => { describe("bound function constructors", () => {
function Bar() { function Bar() {
@ -112,7 +124,6 @@ describe("bound function constructors", () => {
var BoundBar = Bar.bind({ u: 5, v: 6 }); var BoundBar = Bar.bind({ u: 5, v: 6 });
var bar = new BoundBar(); var bar = new BoundBar();
test("bound |this| value does not affect constructor", () => { test("bound |this| value does not affect constructor", () => {
expect(bar.x).toBe(3); expect(bar.x).toBe(3);
expect(bar.y).toBe(4); expect(bar.y).toBe(4);

View file

@ -44,7 +44,9 @@ test("basic functionality", () => {
var add = (x, y) => x + y; var add = (x, y) => x + y;
expect(add.call(null, 1, 2)).toBe(3); expect(add.call(null, 1, 2)).toBe(3);
var multiply = function (x, y) { return x * y; }; var multiply = function (x, y) {
return x * y;
};
expect(multiply.call(null, 3, 4)).toBe(12); expect(multiply.call(null, 3, 4)).toBe(12);
expect((() => this).call("foo")).toBe(globalThis); expect((() => this).call("foo")).toBe(globalThis);

View file

@ -1,15 +1,17 @@
test("basic functionality", () => { test("basic functionality", () => {
expect((function() {}).toString()).toBe("function () {\n ???\n}"); expect(function () {}.toString()).toBe("function () {\n ???\n}");
expect((function(foo) {}).toString()).toBe("function (foo) {\n ???\n}"); expect(function (foo) {}.toString()).toBe("function (foo) {\n ???\n}");
expect((function(foo, bar, baz) {}).toString()).toBe("function (foo, bar, baz) {\n ???\n}"); expect(function (foo, bar, baz) {}.toString()).toBe("function (foo, bar, baz) {\n ???\n}");
expect((function(foo, bar, baz) { expect(
function (foo, bar, baz) {
if (foo) { if (foo) {
return baz; return baz;
} else if (bar) { } else if (bar) {
return foo; return foo;
} }
return bar + 42; return bar + 42;
}).toString()).toBe("function (foo, bar, baz) {\n ???\n}"); }.toString()
).toBe("function (foo, bar, baz) {\n ???\n}");
expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}"); expect(console.debug.toString()).toBe("function debug() {\n [NativeFunction]\n}");
expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}"); expect(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}");
}); });

View file

@ -1,9 +1,9 @@
test("basic functionality", () => { test("basic functionality", () => {
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`; let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
let object = JSON.parse(string, (key, value) => typeof value === "number" ? value * 2 : value); let object = JSON.parse(string, (key, value) => (typeof value === "number" ? value * 2 : value));
expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } }); expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
object = JSON.parse(string, (key, value) => typeof value === "number" ? undefined : value); object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value));
expect(object).toEqual({ var2: "hello", var3: {} }); expect(object).toEqual({ var2: "hello", var3: {} });
}); });

View file

@ -24,5 +24,7 @@ test("basic functionality", () => {
o.key1 = "key1"; o.key1 = "key1";
expect(JSON.stringify(o)).toBe('{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'); expect(JSON.stringify(o)).toBe(
'{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'
);
}); });

View file

@ -1,8 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
let p = new Proxy([], { let p = new Proxy([], {
get(_, key) { get(_, key) {
if (key === "length") if (key === "length") return 3;
return 3;
return Number(key); return Number(key);
}, },
}); });

View file

@ -2,28 +2,33 @@ test("basic functionality", () => {
let o = { let o = {
var1: "foo", var1: "foo",
var2: 42, var2: 42,
arr: [1, 2, { arr: [
1,
2,
{
nested: { nested: {
hello: "world", hello: "world",
}, },
get x() { return 10; } get x() {
}], return 10;
},
},
],
obj: { obj: {
subarr: [3], subarr: [3],
}, },
}; };
let string = JSON.stringify(o, (key, value) => { let string = JSON.stringify(o, (key, value) => {
if (key === "hello") if (key === "hello") return undefined;
return undefined; if (value === 10) return 20;
if (value === 10) if (key === "subarr") return [3, 4, 5];
return 20;
if (key === "subarr")
return [3, 4, 5];
return value; return value;
}); });
expect(string).toBe('{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'); expect(string).toBe(
'{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'
);
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]); string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}'); expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');

View file

@ -3,15 +3,18 @@ test("basic functionality", () => {
foo: 1, foo: 1,
bar: "baz", bar: "baz",
qux: { qux: {
get x() { return 10; }, get x() {
y() { return 20; }, return 10;
},
y() {
return 20;
},
arr: [1, 2, 3], arr: [1, 2, 3],
} },
}; };
let string = JSON.stringify(o, null, 4); let string = JSON.stringify(o, null, 4);
let expected = let expected = `{
`{
"foo": 1, "foo": 1,
"bar": "baz", "bar": "baz",
"qux": { "qux": {
@ -27,8 +30,7 @@ test("basic functionality", () => {
expect(string).toBe(expected); expect(string).toBe(expected);
string = JSON.stringify(o, null, "abcd"); string = JSON.stringify(o, null, "abcd");
expected = expected = `{
`{
abcd"foo": 1, abcd"foo": 1,
abcd"bar": "baz", abcd"bar": "baz",
abcd"qux": { abcd"qux": {

View file

@ -29,7 +29,7 @@ describe("correct behavior", () => {
let o = this; let o = this;
o.var2 = 10; o.var2 = 10;
return o; return o;
} },
}, },
'{"var1":1,"var2":10}', '{"var1":1,"var2":10}',
], ],

View file

@ -1,14 +1,14 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.abs).toHaveLength(1); expect(Math.abs).toHaveLength(1);
expect(Math.abs('-1')).toBe(1); expect(Math.abs("-1")).toBe(1);
expect(Math.abs(-2)).toBe(2); expect(Math.abs(-2)).toBe(2);
expect(Math.abs(null)).toBe(0); expect(Math.abs(null)).toBe(0);
expect(Math.abs('')).toBe(0); expect(Math.abs("")).toBe(0);
expect(Math.abs([])).toBe(0); expect(Math.abs([])).toBe(0);
expect(Math.abs([2])).toBe(2); expect(Math.abs([2])).toBe(2);
expect(Math.abs([1, 2])).toBeNaN(); expect(Math.abs([1, 2])).toBeNaN();
expect(Math.abs({})).toBeNaN(); expect(Math.abs({})).toBeNaN();
expect(Math.abs('string')).toBeNaN(); expect(Math.abs("string")).toBeNaN();
expect(Math.abs()).toBeNaN(); expect(Math.abs()).toBeNaN();
}); });

View file

@ -5,7 +5,7 @@ test("basic functionality", () => {
expect(Math.ceil(4)).toBe(4); expect(Math.ceil(4)).toBe(4);
expect(Math.ceil(7.004)).toBe(8); expect(Math.ceil(7.004)).toBe(8);
expect(Math.ceil(-0.95)).toBe(-0); expect(Math.ceil(-0.95)).toBe(-0);
expect(Math.ceil(-4) ).toBe(-4); expect(Math.ceil(-4)).toBe(-4);
expect(Math.ceil(-7.004)).toBe(-7); expect(Math.ceil(-7.004)).toBe(-7);
expect(Math.ceil()).toBeNaN(); expect(Math.ceil()).toBeNaN();

View file

@ -3,7 +3,7 @@ test("basic functionality", () => {
expect(Math.cos(0)).toBe(1); expect(Math.cos(0)).toBe(1);
expect(Math.cos(null)).toBe(1); expect(Math.cos(null)).toBe(1);
expect(Math.cos('')).toBe(1); expect(Math.cos("")).toBe(1);
expect(Math.cos([])).toBe(1); expect(Math.cos([])).toBe(1);
expect(Math.cos(Math.PI)).toBe(-1); expect(Math.cos(Math.PI)).toBe(-1);
expect(Math.cos()).toBeNaN(); expect(Math.cos()).toBeNaN();

View file

@ -3,7 +3,7 @@ test("basic functionality", () => {
expect(Math.expm1(0)).toBe(0); expect(Math.expm1(0)).toBe(0);
expect(Math.expm1(-2)).toBeCloseTo(-0.864664); expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
expect(Math.expm1(-1)).toBeCloseTo(-0.632120); expect(Math.expm1(-1)).toBeCloseTo(-0.63212);
expect(Math.expm1(1)).toBeCloseTo(1.718281); expect(Math.expm1(1)).toBeCloseTo(1.718281);
expect(Math.expm1(2)).toBeCloseTo(6.389056); expect(Math.expm1(2)).toBeCloseTo(6.389056);

View file

@ -9,15 +9,13 @@ function isNegativeZero(value) {
test("basic functionality", () => { test("basic functionality", () => {
expect(Math.sign).toHaveLength(1); expect(Math.sign).toHaveLength(1);
expect(Math.sign.length).toBe(1);
expect(Math.sign(0.0001)).toBe(1); expect(Math.sign(0.0001)).toBe(1);
expect(Math.sign(1)).toBe(1); expect(Math.sign(1)).toBe(1);
expect(Math.sign(42)).toBe(1); expect(Math.sign(42)).toBe(1);
expect(Math.sign(Infinity)).toBe(1); expect(Math.sign(Infinity)).toBe(1);
expect(isPositiveZero(Math.sign(0))).toBeTrue(); expect(isPositiveZero(Math.sign(0))).toBeTrue();
expect(isPositiveZero(Math.sign(null))).toBeTrue(); expect(isPositiveZero(Math.sign(null))).toBeTrue();
expect(isPositiveZero(Math.sign(''))).toBeTrue(); expect(isPositiveZero(Math.sign(""))).toBeTrue();
expect(isPositiveZero(Math.sign([]))).toBeTrue(); expect(isPositiveZero(Math.sign([]))).toBeTrue();
expect(Math.sign(-0.0001)).toBe(-1); expect(Math.sign(-0.0001)).toBe(-1);
@ -26,7 +24,7 @@ test("basic functionality", () => {
expect(Math.sign(-Infinity)).toBe(-1); expect(Math.sign(-Infinity)).toBe(-1);
expect(isNegativeZero(Math.sign(-0))).toBeTrue(); expect(isNegativeZero(Math.sign(-0))).toBeTrue();
expect(isNegativeZero(Math.sign(-null))).toBeTrue(); expect(isNegativeZero(Math.sign(-null))).toBeTrue();
expect(isNegativeZero(Math.sign(-''))).toBeTrue(); expect(isNegativeZero(Math.sign(-""))).toBeTrue();
expect(isNegativeZero(Math.sign(-[]))).toBeTrue(); expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
expect(Math.sign()).toBeNaN(); expect(Math.sign()).toBeNaN();

View file

@ -3,9 +3,9 @@ test("basic functionality", () => {
expect(Math.sin(0)).toBe(0); expect(Math.sin(0)).toBe(0);
expect(Math.sin(null)).toBe(0); expect(Math.sin(null)).toBe(0);
expect(Math.sin('')).toBe(0); expect(Math.sin("")).toBe(0);
expect(Math.sin([])).toBe(0); expect(Math.sin([])).toBe(0);
expect(Math.sin(Math.PI * 3 / 2)).toBe(-1); expect(Math.sin((Math.PI * 3) / 2)).toBe(-1);
expect(Math.sin(Math.PI / 2)).toBe(1); expect(Math.sin(Math.PI / 2)).toBe(1);
expect(Math.sin()).toBeNaN(); expect(Math.sin()).toBeNaN();
expect(Math.sin(undefined)).toBeNaN(); expect(Math.sin(undefined)).toBeNaN();

View file

@ -3,7 +3,7 @@ test("basic functionality", () => {
expect(Math.tan(0)).toBe(0); expect(Math.tan(0)).toBe(0);
expect(Math.tan(null)).toBe(0); expect(Math.tan(null)).toBe(0);
expect(Math.tan('')).toBe(0); expect(Math.tan("")).toBe(0);
expect(Math.tan([])).toBe(0); expect(Math.tan([])).toBe(0);
expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1); expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
expect(Math.tan()).toBeNaN(); expect(Math.tan()).toBeNaN();

View file

@ -3,10 +3,10 @@ test("basic functionality", () => {
expect(Math.trunc(13.37)).toBe(13); expect(Math.trunc(13.37)).toBe(13);
expect(Math.trunc(42.84)).toBe(42); expect(Math.trunc(42.84)).toBe(42);
expect(Math.trunc(0.123)).toBe( 0); expect(Math.trunc(0.123)).toBe(0);
expect(Math.trunc(-0.123)).toBe(-0); expect(Math.trunc(-0.123)).toBe(-0);
expect(Math.trunc(NaN)).toBeNaN(); expect(Math.trunc(NaN)).toBeNaN();
expect(Math.trunc('foo')).toBeNaN(); expect(Math.trunc("foo")).toBeNaN();
expect(Math.trunc()).toBeNaN(); expect(Math.trunc()).toBeNaN();
}); });

View file

@ -6,13 +6,13 @@ test("basic functionality", () => {
expect(Number.isInteger(-10000)).toBeTrue(); expect(Number.isInteger(-10000)).toBeTrue();
expect(Number.isInteger(5)).toBeTrue(); expect(Number.isInteger(5)).toBeTrue();
expect(Number.isInteger(5.0)).toBeTrue(); expect(Number.isInteger(5.0)).toBeTrue();
expect(Number.isInteger(5 + 1/10000000000000000)).toBeTrue(); expect(Number.isInteger(5 + 1 / 10000000000000000)).toBeTrue();
// FIXME: values outside of i32's range should still return true // FIXME: values outside of i32's range should still return true
// expect(Number.isInteger(+2147483647 + 1)).toBeTrue(); // expect(Number.isInteger(+2147483647 + 1)).toBeTrue();
// expect(Number.isInteger(-2147483648 - 1)).toBeTrue(); // expect(Number.isInteger(-2147483648 - 1)).toBeTrue();
// expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue(); // expect(Number.isInteger(99999999999999999999999999999999999)).toBeTrue();
expect(Number.isInteger(5 + 1/1000000000000000)).toBeFalse(); expect(Number.isInteger(5 + 1 / 1000000000000000)).toBeFalse();
expect(Number.isInteger(1.23)).toBeFalse(); expect(Number.isInteger(1.23)).toBeFalse();
expect(Number.isInteger("")).toBeFalse(); expect(Number.isInteger("")).toBeFalse();
expect(Number.isInteger("0")).toBeFalse(); expect(Number.isInteger("0")).toBeFalse();

View file

@ -24,8 +24,8 @@ test("basic functionality", () => {
expect(new Number(undefined).valueOf()).toBeNaN(); expect(new Number(undefined).valueOf()).toBeNaN();
expect(Number({})).toBeNaN(); expect(Number({})).toBeNaN();
expect(new Number({}).valueOf()).toBeNaN(); expect(new Number({}).valueOf()).toBeNaN();
expect(Number({a: 1})).toBeNaN(); expect(Number({ a: 1 })).toBeNaN();
expect(new Number({a: 1}).valueOf()).toBeNaN(); expect(new Number({ a: 1 }).valueOf()).toBeNaN();
expect(Number([1, 2, 3])).toBeNaN(); expect(Number([1, 2, 3])).toBeNaN();
expect(new Number([1, 2, 3]).valueOf()).toBeNaN(); expect(new Number([1, 2, 3]).valueOf()).toBeNaN();
expect(Number("foo")).toBeNaN(); expect(Number("foo")).toBeNaN();

View file

@ -15,7 +15,11 @@ describe("normal functionality", () => {
test("array index getter", () => { test("array index getter", () => {
let o = {}; let o = {};
Object.defineProperty(o, 2, { get() { return 10; } }); Object.defineProperty(o, 2, {
get() {
return 10;
},
});
expect(o[2]).toBe(10); expect(o[2]).toBe(10);
}); });
@ -65,8 +69,8 @@ describe("normal functionality", () => {
Object.defineProperty(o, "foo", { configurable: true, value: 4 }); Object.defineProperty(o, "foo", { configurable: true, value: 4 });
expect(o.foo).toBe(4); expect(o.foo).toBe(4);
expect(o.foo = 5).toBe(5); expect((o.foo = 5)).toBe(5);
expect(o.foo = 4).toBe(4); expect((o.foo = 4)).toBe(4);
}); });
}); });
@ -88,7 +92,10 @@ describe("errors", () => {
get() {}, get() {},
value: 9, value: 9,
}); });
}).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key"); }).toThrowWithMessage(
TypeError,
"Accessor property descriptor cannot specify a value or writable key"
);
}); });
test("cannot define 'value' and 'set' in the same descriptor", () => { test("cannot define 'value' and 'set' in the same descriptor", () => {
@ -99,7 +106,10 @@ describe("errors", () => {
set() {}, set() {},
writable: true, writable: true,
}); });
}).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key"); }).toThrowWithMessage(
TypeError,
"Accessor property descriptor cannot specify a value or writable key"
);
}); });
test("redefine non-configurable accessor", () => { test("redefine non-configurable accessor", () => {

View file

@ -12,18 +12,28 @@ describe("basic functionality", () => {
test("entries with object", () => { test("entries with object", () => {
let entries = Object.entries({ foo: 1, bar: 2, baz: 3 }); let entries = Object.entries({ foo: 1, bar: 2, baz: 3 });
expect(entries).toEqual([["foo", 1], ["bar", 2], ["baz", 3]]); expect(entries).toEqual([
["foo", 1],
["bar", 2],
["baz", 3],
]);
}); });
test("entries with array", () => { test("entries with array", () => {
entries = Object.entries(["a", "b", "c"]); entries = Object.entries(["a", "b", "c"]);
expect(entries).toEqual([["0", "a"], ["1", "b"], ["2", "c"]]); expect(entries).toEqual([
["0", "a"],
["1", "b"],
["2", "c"],
]);
}); });
test("ignores non-enumerable properties", () => { test("ignores non-enumerable properties", () => {
let obj = { foo: 1 }; let obj = { foo: 1 };
Object.defineProperty(obj, "getFoo", { Object.defineProperty(obj, "getFoo", {
value: function() { return this.foo; }, value: function () {
return this.foo;
},
}); });
let entries = Object.entries(obj); let entries = Object.entries(obj);
expect(entries).toEqual([["foo", 1]]); expect(entries).toEqual([["foo", 1]]);
@ -41,5 +51,5 @@ describe("errors", () => {
expect(() => { expect(() => {
Object.entries(undefined); Object.entries(undefined);
}).toThrowWithMessage(TypeError, "ToObject on null or undefined"); }).toThrowWithMessage(TypeError, "ToObject on null or undefined");
}) });
}); });

View file

@ -3,7 +3,7 @@ test("basic functionality", () => {
let o2 = {}; let o2 = {};
expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2)); expect(Object.getPrototypeOf(o1)).toBe(Object.getPrototypeOf(o2));
expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBe(null); expect(Object.getPrototypeOf(Object.getPrototypeOf(o1))).toBeNull();
Object.setPrototypeOf(o1, o2); Object.setPrototypeOf(o1, o2);
expect(Object.getPrototypeOf(o1)).toBe(o2); expect(Object.getPrototypeOf(o1)).toBe(o2);

View file

@ -47,8 +47,8 @@ test("arguments that evaluate to false", () => {
expect(Object.is(a, [1, 2, 3])).toBeFalse(); expect(Object.is(a, [1, 2, 3])).toBeFalse();
expect(Object.is([1, 2, 3], a)).toBeFalse(); expect(Object.is([1, 2, 3], a)).toBeFalse();
expect(Object.is({}, {})).toBeFalse(); expect(Object.is({}, {})).toBeFalse();
expect(Object.is(o, {foo: "bar"})).toBeFalse(); expect(Object.is(o, { foo: "bar" })).toBeFalse();
expect(Object.is({foo: "bar"}, o)).toBeFalse(); expect(Object.is({ foo: "bar" }, o)).toBeFalse();
expect(Object.is(a, o)).toBeFalse(); expect(Object.is(a, o)).toBeFalse();
expect(Object.is(o, a)).toBeFalse(); expect(Object.is(o, a)).toBeFalse();
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(Object).toHaveLength(1); expect(Object).toHaveLength(1);
expect(Object.name).toBe("Object"); expect(Object.name).toBe("Object");
expect(Object.prototype.length).toBe(undefined); expect(Object.prototype).not.toHaveProperty("length");
expect(typeof Object()).toBe("object"); expect(typeof Object()).toBe("object");
expect(typeof new Object()).toBe("object"); expect(typeof new Object()).toBe("object");

View file

@ -22,7 +22,9 @@ describe("correct behavior", () => {
test("ignores non-enumerable properties", () => { test("ignores non-enumerable properties", () => {
let obj = { foo: 1 }; let obj = { foo: 1 };
Object.defineProperty(obj, "getFoo", { Object.defineProperty(obj, "getFoo", {
value: function() { return this.foo; }, value: function () {
return this.foo;
},
}); });
keys = Object.keys(obj); keys = Object.keys(obj);
expect(keys).toEqual(["foo"]); expect(keys).toEqual(["foo"]);

View file

@ -47,7 +47,7 @@ describe("errors", () => {
o.foo = "foo"; o.foo = "foo";
}).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object"); }).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object");
expect(o.foo = "foo").toBe("foo"); expect((o.foo = "foo")).toBe("foo");
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
}); });
}); });

View file

@ -1,7 +1,7 @@
describe("correct behavior", () => { describe("correct behavior", () => {
test("length", () => { test("length", () => {
expect(Object.prototype.toLocaleString).toHaveLength(0); expect(Object.prototype.toLocaleString).toHaveLength(0);
}) });
test("basic functionality", () => { test("basic functionality", () => {
let o; let o;
@ -16,7 +16,11 @@ describe("correct behavior", () => {
describe("errors", () => { describe("errors", () => {
test("toString that throws error", () => { test("toString that throws error", () => {
let o = { toString: () => { throw new Error(); } }; let o = {
toString: () => {
throw new Error();
},
};
expect(() => { expect(() => {
o.toLocaleString(); o.toLocaleString();
}).toThrow(Error); }).toThrow(Error);

View file

@ -21,8 +21,10 @@ describe("correct behavior", () => {
test("ignores non-enumerable properties", () => { test("ignores non-enumerable properties", () => {
let obj = { foo: 1 }; let obj = { foo: 1 };
Object.defineProperty(obj, 'getFoo', { Object.defineProperty(obj, "getFoo", {
value: function() { return this.foo; }, value: function () {
return this.foo;
},
}); });
let values = Object.values(obj); let values = Object.values(obj);
expect(values).toEqual([1]); expect(values).toEqual([1]);

View file

@ -14,8 +14,7 @@ describe("[[Call]] trap normal behavior", () => {
apply(target, this_, arguments) { apply(target, this_, arguments) {
expect(target).toBe(f); expect(target).toBe(f);
expect(this_).toBe(handler); expect(this_).toBe(handler);
if (arguments[2]) if (arguments[2]) return arguments[0] * arguments[1];
return arguments[0] * arguments[1];
return f(...arguments); return f(...arguments);
}, },
}; };

View file

@ -1,11 +1,23 @@
describe("[[Construct]] trap normal behavior", () => { describe("[[Construct]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => { test("forwarding when not defined in handler", () => {
let p = new Proxy(function() { this.x = 5; }, { construct: null }); let p = new Proxy(
expect((new p).x).toBe(5); function () {
p = new Proxy(function() { this.x = 5; }, { construct: undefined }); this.x = 5;
expect((new p).x).toBe(5); },
p = new Proxy(function() { this.x = 5; }, {}); { construct: null }
expect((new p).x).toBe(5); );
expect(new p().x).toBe(5);
p = new Proxy(
function () {
this.x = 5;
},
{ construct: undefined }
);
expect(new p().x).toBe(5);
p = new Proxy(function () {
this.x = 5;
}, {});
expect(new p().x).toBe(5);
}); });
test("trapping 'new'", () => { test("trapping 'new'", () => {
@ -18,8 +30,7 @@ describe("[[Construct]] trap normal behavior", () => {
construct(target, arguments, newTarget) { construct(target, arguments, newTarget) {
expect(target).toBe(f); expect(target).toBe(f);
expect(newTarget).toBe(p); expect(newTarget).toBe(p);
if (arguments[1]) if (arguments[1]) return Reflect.construct(target, [arguments[0] * 2], newTarget);
return Reflect.construct(target, [arguments[0] * 2], newTarget);
return Reflect.construct(target, arguments, newTarget); return Reflect.construct(target, arguments, newTarget);
}, },
}; };
@ -35,13 +46,12 @@ describe("[[Construct]] trap normal behavior", () => {
} }
let p; let p;
function theNewTarget() {}; function theNewTarget() {}
const handler = { const handler = {
construct(target, arguments, newTarget) { construct(target, arguments, newTarget) {
expect(target).toBe(f); expect(target).toBe(f);
expect(newTarget).toBe(theNewTarget); expect(newTarget).toBe(theNewTarget);
if (arguments[1]) if (arguments[1]) return Reflect.construct(target, [arguments[0] * 2], newTarget);
return Reflect.construct(target, [arguments[0] * 2], newTarget);
return Reflect.construct(target, arguments, newTarget); return Reflect.construct(target, arguments, newTarget);
}, },
}; };
@ -55,7 +65,7 @@ describe("[[Construct]] invariants", () => {
test("target must have a [[Construct]] slot", () => { test("target must have a [[Construct]] slot", () => {
[{}, [], new Proxy({}, {})].forEach(item => { [{}, [], new Proxy({}, {})].forEach(item => {
expect(() => { expect(() => {
new (new Proxy(item, {})); new new Proxy(item, {})();
}).toThrowWithMessage(TypeError, "[object ProxyObject] is not a constructor"); }).toThrowWithMessage(TypeError, "[object ProxyObject] is not a constructor");
}); });
}); });

View file

@ -31,13 +31,17 @@ describe("[[DefineProperty]] trap normal behavior", () => {
let o = {}; let o = {};
let p = new Proxy(o, { let p = new Proxy(o, {
defineProperty(target, name, descriptor) { defineProperty(target, name, descriptor) {
if (target[name] === undefined) if (target[name] === undefined) Object.defineProperty(target, name, descriptor);
Object.defineProperty(target, name, descriptor);
return true; return true;
}, },
}); });
Object.defineProperty(p, "foo", { value: 10, enumerable: true, configurable: false, writable: true }); Object.defineProperty(p, "foo", {
value: 10,
enumerable: true,
configurable: false,
writable: true,
});
expect(p).toHaveEnumerableProperty("foo"); expect(p).toHaveEnumerableProperty("foo");
expect(p).not.toHaveConfigurableProperty("foo"); expect(p).not.toHaveConfigurableProperty("foo");
expect(p).toHaveWritableProperty("foo"); expect(p).toHaveWritableProperty("foo");
@ -45,7 +49,12 @@ describe("[[DefineProperty]] trap normal behavior", () => {
expect(p).not.toHaveGetterProperty("foo"); expect(p).not.toHaveGetterProperty("foo");
expect(p).not.toHaveSetterProperty("foo"); expect(p).not.toHaveSetterProperty("foo");
Object.defineProperty(p, "foo", { value: 20, enumerable: true, configurable: false, writable: true }); Object.defineProperty(p, "foo", {
value: 20,
enumerable: true,
configurable: false,
writable: true,
});
expect(p).toHaveEnumerableProperty("foo"); expect(p).toHaveEnumerableProperty("foo");
expect(p).not.toHaveConfigurableProperty("foo"); expect(p).not.toHaveConfigurableProperty("foo");
expect(p).toHaveWritableProperty("foo"); expect(p).toHaveWritableProperty("foo");
@ -57,9 +66,14 @@ describe("[[DefineProperty]] trap normal behavior", () => {
describe("[[DefineProperty]] invariants", () => { describe("[[DefineProperty]] invariants", () => {
test("trap can't return false", () => { test("trap can't return false", () => {
let p = new Proxy({}, { let p = new Proxy(
defineProperty() { return false; } {},
}); {
defineProperty() {
return false;
},
}
);
expect(() => { expect(() => {
Object.defineProperty(p, "foo", {}); Object.defineProperty(p, "foo", {});
@ -72,12 +86,15 @@ describe("[[DefineProperty]] invariants", () => {
let p = new Proxy(o, { let p = new Proxy(o, {
defineProperty() { defineProperty() {
return true; return true;
} },
}); });
expect(() => { expect(() => {
Object.defineProperty(p, "foo", {}); Object.defineProperty(p, "foo", {});
}).toThrowWithMessage(TypeError, "Proxy handler's defineProperty trap violates invariant: a property cannot be reported as being defined if the property does not exist on the target and the target is non-extensible"); }).toThrowWithMessage(
TypeError,
"Proxy handler's defineProperty trap violates invariant: a property cannot be reported as being defined if the property does not exist on the target and the target is non-extensible"
);
}); });
test("trap cannot return true for a non-configurable property if it doesn't already exist on the target", () => { test("trap cannot return true for a non-configurable property if it doesn't already exist on the target", () => {
@ -91,7 +108,10 @@ describe("[[DefineProperty]] invariants", () => {
expect(() => { expect(() => {
Object.defineProperty(p, "bar", { value: 6, configurable: false }); Object.defineProperty(p, "bar", { value: 6, configurable: false });
}).toThrowWithMessage(TypeError, "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it does not already exist on the target object"); }).toThrowWithMessage(
TypeError,
"Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it does not already exist on the target object"
);
}); });
test("trap cannot return true for a non-configurable property if it already exists as a configurable property", () => { test("trap cannot return true for a non-configurable property if it already exists as a configurable property", () => {
@ -105,6 +125,9 @@ describe("[[DefineProperty]] invariants", () => {
expect(() => { expect(() => {
Object.defineProperty(p, "foo", { value: 6, configurable: false }); Object.defineProperty(p, "foo", { value: 6, configurable: false });
}).toThrowWithMessage(TypeError, "Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it already exists on the target object as a configurable property"); }).toThrowWithMessage(
}) TypeError,
"Proxy handler's defineProperty trap violates invariant: a property cannot be defined as non-configurable if it already exists on the target object as a configurable property"
);
});
}); });

View file

@ -1,8 +1,8 @@
describe("[[Delete]] trap normal behavior", () => { describe("[[Delete]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => { test("forwarding when not defined in handler", () => {
expect(delete (new Proxy({}, { deleteProperty: undefined })).foo).toBeTrue(); expect(delete new Proxy({}, { deleteProperty: undefined }).foo).toBeTrue();
expect(delete (new Proxy({}, { deleteProperty: null })).foo).toBeTrue(); expect(delete new Proxy({}, { deleteProperty: null }).foo).toBeTrue();
expect(delete (new Proxy({}, {})).foo).toBeTrue(); expect(delete new Proxy({}, {}).foo).toBeTrue();
}); });
test("correct arguments supplied to trap", () => { test("correct arguments supplied to trap", () => {
@ -12,7 +12,7 @@ describe("[[Delete]] trap normal behavior", () => {
expect(target).toBe(o); expect(target).toBe(o);
expect(property).toBe("foo"); expect(property).toBe("foo");
return true; return true;
} },
}); });
delete p.foo; delete p.foo;
@ -27,18 +27,17 @@ describe("[[Delete]] trap normal behavior", () => {
return true; return true;
} }
return false; return false;
} },
}); });
expect(delete p.foo).toBeTrue(); expect(delete p.foo).toBeTrue();
expect(delete p.bar).toBeFalse(); expect(delete p.bar).toBeFalse();
expect(o.foo).toBe(undefined); expect(o.foo).toBeUndefined();
expect(o.bar).toBe(2); expect(o.bar).toBe(2);
}); });
}); });
describe("[[Delete]] invariants", () => { describe("[[Delete]] invariants", () => {
test("cannot report a non-configurable own property as deleted", () => { test("cannot report a non-configurable own property as deleted", () => {
let o = {}; let o = {};
@ -51,6 +50,9 @@ describe("[[Delete]] invariants", () => {
expect(() => { expect(() => {
delete p.foo; delete p.foo;
}).toThrowWithMessage(TypeError, "Proxy handler's deleteProperty trap violates invariant: cannot report a non-configurable own property of the target as deleted"); }).toThrowWithMessage(
TypeError,
"Proxy handler's deleteProperty trap violates invariant: cannot report a non-configurable own property of the target as deleted"
);
}); });
}); });

View file

@ -1,8 +1,8 @@
describe("[[Get]] trap normal behavior", () => { describe("[[Get]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => { test("forwarding when not defined in handler", () => {
expect((new Proxy({}, { get: undefined })).foo).toBeUndefined(); expect(new Proxy({}, { get: undefined }).foo).toBeUndefined();
expect((new Proxy({}, { get: null })).foo).toBeUndefined(); expect(new Proxy({}, { get: null }).foo).toBeUndefined();
expect((new Proxy({}, {})).foo).toBeUndefined(); expect(new Proxy({}, {}).foo).toBeUndefined();
}); });
test("correct arguments supplied to trap", () => { test("correct arguments supplied to trap", () => {
@ -30,7 +30,7 @@ describe("[[Get]] trap normal behavior", () => {
return 3; return 3;
} }
return target[property]; return target[property];
} },
}); });
expect(p.foo).toBe(1); expect(p.foo).toBe(1);
@ -56,7 +56,10 @@ describe("[[Get]] invariants", () => {
expect(p.foo).toBe(8); expect(p.foo).toBe(8);
expect(() => { expect(() => {
p.bar; p.bar;
}).toThrowWithMessage(TypeError, "Proxy handler's get trap violates invariant: the returned value must match the value on the target if the property exists on the target as a non-writable, non-configurable own data property"); }).toThrowWithMessage(
TypeError,
"Proxy handler's get trap violates invariant: the returned value must match the value on the target if the property exists on the target as a non-writable, non-configurable own data property"
);
}); });
test("returned value must be undefined if the property is a non-configurable accessor with no getter", () => { test("returned value must be undefined if the property is a non-configurable accessor with no getter", () => {
@ -71,6 +74,9 @@ describe("[[Get]] invariants", () => {
expect(() => { expect(() => {
p.foo; p.foo;
}).toThrowWithMessage(TypeError, "Proxy handler's get trap violates invariant: the returned value must be undefined if the property exists on the target as a non-configurable accessor property with an undefined get attribute"); }).toThrowWithMessage(
}) TypeError,
"Proxy handler's get trap violates invariant: the returned value must be undefined if the property exists on the target as a non-configurable accessor property with an undefined get attribute"
);
});
}); });

View file

@ -1,7 +1,11 @@
describe("[Call][GetOwnProperty]] trap normal behavior", () => { describe("[Call][GetOwnProperty]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => { test("forwarding when not defined in handler", () => {
expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a")).toBeUndefined(); expect(
expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a")).toBeUndefined(); Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a")
).toBeUndefined();
expect(
Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a")
).toBeUndefined();
expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined(); expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined();
}); });
@ -11,7 +15,7 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
getOwnPropertyDescriptor(target, property) { getOwnPropertyDescriptor(target, property) {
expect(target).toBe(o); expect(target).toBe(o);
expect(property).toBe("foo"); expect(property).toBe("foo");
} },
}); });
Object.getOwnPropertyDescriptor(p, "foo"); Object.getOwnPropertyDescriptor(p, "foo");
@ -19,14 +23,18 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
test("conditional returned descriptor", () => { test("conditional returned descriptor", () => {
let o = { foo: "bar" }; let o = { foo: "bar" };
Object.defineProperty(o, "baz", { value: "qux", enumerable: false, configurable: true, writable: false }); Object.defineProperty(o, "baz", {
value: "qux",
enumerable: false,
configurable: true,
writable: false,
});
let p = new Proxy(o, { let p = new Proxy(o, {
getOwnPropertyDescriptor(target, property) { getOwnPropertyDescriptor(target, property) {
if (property === "baz") if (property === "baz") return Object.getOwnPropertyDescriptor(target, "baz");
return Object.getOwnPropertyDescriptor(target, "baz");
return { value: target[property], enumerable: false, configurable: true, writable: true }; return { value: target[property], enumerable: false, configurable: true, writable: true };
} },
}); });
expect(p).toHaveConfigurableProperty("baz"); expect(p).toHaveConfigurableProperty("baz");
@ -50,12 +58,20 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
describe("[[GetOwnProperty]] invariants", () => { describe("[[GetOwnProperty]] invariants", () => {
test("must return an object or undefined", () => { test("must return an object or undefined", () => {
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(new Proxy({}, { Object.getOwnPropertyDescriptor(
new Proxy(
{},
{
getOwnPropertyDescriptor() { getOwnPropertyDescriptor() {
return 1; return 1;
}, },
})); }
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: must return an object or undefined"); )
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: must return an object or undefined"
);
}); });
test("cannot return undefined for a non-configurable property", () => { test("cannot return undefined for a non-configurable property", () => {
@ -72,12 +88,20 @@ describe("[[GetOwnProperty]] invariants", () => {
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(p, "foo"); Object.getOwnPropertyDescriptor(p, "foo");
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot return undefined for a property on the target which is a non-configurable property"); }).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot return undefined for a property on the target which is a non-configurable property"
);
}); });
test("cannot return undefined for an existing property if the target is non-extensible", () => { test("cannot return undefined for an existing property if the target is non-extensible", () => {
let o = {}; let o = {};
Object.defineProperty(o, "baz", { value: 20, configurable: true, writable: true, enumerable: true }); Object.defineProperty(o, "baz", {
value: 20,
configurable: true,
writable: true,
enumerable: true,
});
Object.preventExtensions(o); Object.preventExtensions(o);
let p = new Proxy(o, { let p = new Proxy(o, {
@ -88,58 +112,101 @@ describe("[[GetOwnProperty]] invariants", () => {
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(p, "baz"); Object.getOwnPropertyDescriptor(p, "baz");
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report a property as being undefined if it exists as an own property of the target and the target is non-extensible"); }).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report a property as being undefined if it exists as an own property of the target and the target is non-extensible"
);
}); });
test("invalid property descriptors", () => { test("invalid property descriptors", () => {
let o = {}; let o = {};
Object.defineProperty(o, "v1", { value: 10, configurable: false }); Object.defineProperty(o, "v1", { value: 10, configurable: false });
Object.defineProperty(o, "v2", { value: 10, configurable: false, enumerable: true }); Object.defineProperty(o, "v2", { value: 10, configurable: false, enumerable: true });
Object.defineProperty(o, "v3", { configurable: false, get() { return 1; } }); Object.defineProperty(o, "v3", {
Object.defineProperty(o, "v4", { value: 10, configurable: false, writable: false, enumerable: true }); configurable: false,
get() {
return 1;
},
});
Object.defineProperty(o, "v4", {
value: 10,
configurable: false,
writable: false,
enumerable: true,
});
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(new Proxy(o, { Object.getOwnPropertyDescriptor(
new Proxy(o, {
getOwnPropertyDescriptor() { getOwnPropertyDescriptor() {
return { configurable: true }; return { configurable: true };
}, },
}), "v1"); }),
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); "v1"
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"
);
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(new Proxy(o, { Object.getOwnPropertyDescriptor(
new Proxy(o, {
getOwnPropertyDescriptor() { getOwnPropertyDescriptor() {
return { enumerable: false }; return { enumerable: false };
}, },
}), "v2"); }),
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); "v2"
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"
);
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(new Proxy(o, { Object.getOwnPropertyDescriptor(
new Proxy(o, {
getOwnPropertyDescriptor() { getOwnPropertyDescriptor() {
return { value: 10 }; return { value: 10 };
}, },
}), "v3"); }),
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); "v3"
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"
);
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(new Proxy(o, { Object.getOwnPropertyDescriptor(
new Proxy(o, {
getOwnPropertyDescriptor() { getOwnPropertyDescriptor() {
return { value: 10, writable: true }; return { value: 10, writable: true };
}, },
}), "v4"); }),
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"); "v4"
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: invalid property descriptor for existing property on the target"
);
}); });
test("cannot report a property as non-configurable if it does not exist or is non-configurable", () => { test("cannot report a property as non-configurable if it does not exist or is non-configurable", () => {
let o = {}; let o = {};
Object.defineProperty(o, "v", { configurable: true }); Object.defineProperty(o, "v", { configurable: true });
expect(() => { expect(() => {
Object.getOwnPropertyDescriptor(new Proxy(o, { Object.getOwnPropertyDescriptor(
new Proxy(o, {
getOwnPropertyDescriptor() { getOwnPropertyDescriptor() {
return { configurable: false }; return { configurable: false };
}, },
}), "v"); }),
}).toThrowWithMessage(TypeError, "Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report target's property as non-configurable if the property does not exist, or if it is configurable"); "v"
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getOwnPropertyDescriptor trap violates invariant: cannot report target's property as non-configurable if the property does not exist, or if it is configurable"
);
}); });
}); });

View file

@ -18,7 +18,7 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
getPrototypeOf(target) { getPrototypeOf(target) {
expect(target).toBe(o); expect(target).toBe(o);
return null; return null;
} },
}); });
Object.getPrototypeOf(p); Object.getPrototypeOf(p);
@ -28,14 +28,13 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
let o = {}; let o = {};
let p = new Proxy(o, { let p = new Proxy(o, {
getPrototypeOf(target) { getPrototypeOf(target) {
if (target.foo) if (target.foo) return { bar: 1 };
return { bar: 1 };
return { bar: 2 }; return { bar: 2 };
}, },
}); });
expect(Object.getPrototypeOf(p).bar).toBe(2); expect(Object.getPrototypeOf(p).bar).toBe(2);
o.foo = 20 o.foo = 20;
expect(Object.getPrototypeOf(p).bar).toBe(1); expect(Object.getPrototypeOf(p).bar).toBe(1);
}); });
@ -48,7 +47,7 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
p = new Proxy(o, { p = new Proxy(o, {
getPrototypeOf() { getPrototypeOf() {
return proto; return proto;
} },
}); });
expect(Object.getPrototypeOf(p).foo).toBe("bar"); expect(Object.getPrototypeOf(p).foo).toBe("bar");
@ -58,8 +57,20 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
describe("[[GetPrototypeOf]] invariants", () => { describe("[[GetPrototypeOf]] invariants", () => {
test("must return an object or null", () => { test("must return an object or null", () => {
expect(() => { expect(() => {
Object.getPrototypeOf(new Proxy({}, { getPrototypeOf() { return 1; } })); Object.getPrototypeOf(
}).toThrowWithMessage(TypeError, "Proxy handler's getPrototypeOf trap violates invariant: must return an object or null"); new Proxy(
{},
{
getPrototypeOf() {
return 1;
},
}
)
);
}).toThrowWithMessage(
TypeError,
"Proxy handler's getPrototypeOf trap violates invariant: must return an object or null"
);
}); });
test("different return object for non-extensible target", () => { test("different return object for non-extensible target", () => {
@ -71,11 +82,14 @@ describe("[[GetPrototypeOf]] invariants", () => {
let p = new Proxy(o, { let p = new Proxy(o, {
getPrototypeOf(target) { getPrototypeOf(target) {
return { baz: "qux" }; return { baz: "qux" };
} },
}); });
expect(() => { expect(() => {
Object.getPrototypeOf(p); Object.getPrototypeOf(p);
}).toThrowWithMessage(TypeError, "Proxy handler's getPrototypeOf trap violates invariant: cannot return a different prototype object for a non-extensible target"); }).toThrowWithMessage(
TypeError,
"Proxy handler's getPrototypeOf trap violates invariant: cannot return a different prototype object for a non-extensible target"
);
}); });
}); });

View file

@ -1,7 +1,7 @@
describe("[[Has]] trap normal behavior", () => { describe("[[Has]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => { test("forwarding when not defined in handler", () => {
expect("foo" in new Proxy({}, { has: null })).toBeFalse(); expect("foo" in new Proxy({}, { has: null })).toBeFalse();
expect("foo" in new Proxy({}, { has: undefined})).toBeFalse(); expect("foo" in new Proxy({}, { has: undefined })).toBeFalse();
expect("foo" in new Proxy({}, {})).toBeFalse(); expect("foo" in new Proxy({}, {})).toBeFalse();
}); });
@ -12,7 +12,7 @@ describe("[[Has]] trap normal behavior", () => {
expect(target).toBe(o); expect(target).toBe(o);
expect(prop).toBe("foo"); expect(prop).toBe("foo");
return true; return true;
} },
}); });
"foo" in p; "foo" in p;
@ -22,12 +22,10 @@ describe("[[Has]] trap normal behavior", () => {
let o = {}; let o = {};
let p = new Proxy(o, { let p = new Proxy(o, {
has(target, prop) { has(target, prop) {
if (target.checkedFoo) if (target.checkedFoo) return true;
return true; if (prop === "foo") target.checkedFoo = true;
if (prop === "foo")
target.checkedFoo = true;
return false; return false;
} },
}); });
expect("foo" in p).toBeFalse(); expect("foo" in p).toBeFalse();
@ -43,12 +41,15 @@ describe("[[Has]] invariants", () => {
p = new Proxy(o, { p = new Proxy(o, {
has() { has() {
return false; return false;
} },
}); });
expect(() => { expect(() => {
"foo" in p; "foo" in p;
}).toThrowWithMessage(TypeError, "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target as a non-configurable property"); }).toThrowWithMessage(
TypeError,
"Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target as a non-configurable property"
);
}); });
test("cannot return false if the property exists and the target is non-extensible", () => { test("cannot return false if the property exists and the target is non-extensible", () => {
@ -58,13 +59,16 @@ describe("[[Has]] invariants", () => {
let p = new Proxy(o, { let p = new Proxy(o, {
has() { has() {
return false; return false;
} },
}); });
Object.preventExtensions(o); Object.preventExtensions(o);
expect(() => { expect(() => {
"foo" in p; "foo" in p;
}).toThrowWithMessage(TypeError, "Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible"); }).toThrowWithMessage(
TypeError,
"Proxy handler's has trap violates invariant: a property cannot be reported as non-existent if it exists on the target and the target is non-extensible"
);
}); });
}); });

View file

@ -11,7 +11,7 @@ describe("[[IsExtensible]] trap normal behavior", () => {
isExtensible(target) { isExtensible(target) {
expect(target).toBe(o); expect(target).toBe(o);
return true; return true;
} },
}); });
expect(Object.isExtensible(p)).toBeTrue(); expect(Object.isExtensible(p)).toBeTrue();
@ -31,6 +31,9 @@ describe("[[Call]] invariants", () => {
expect(() => { expect(() => {
Object.isExtensible(p); Object.isExtensible(p);
}).toThrowWithMessage(TypeError, "Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility"); }).toThrowWithMessage(
TypeError,
"Proxy handler's isExtensible trap violates invariant: return value must match the target's extensibility"
);
}); });
}); });

View file

@ -14,7 +14,7 @@ describe("[[PreventExtension]] trap normal behavior", () => {
preventExtensions(target) { preventExtensions(target) {
expect(target).toBe(o); expect(target).toBe(o);
return true; return true;
} },
}); });
Object.preventExtensions(o); Object.preventExtensions(o);
@ -24,11 +24,14 @@ describe("[[PreventExtension]] trap normal behavior", () => {
describe("[[PreventExtensions]] invariants", () => { describe("[[PreventExtensions]] invariants", () => {
test("cannot return false", () => { test("cannot return false", () => {
let p = new Proxy({}, { let p = new Proxy(
{},
{
preventExtensions() { preventExtensions() {
return false; return false;
}, },
}); }
);
expect(() => { expect(() => {
Object.preventExtensions(p); Object.preventExtensions(p);
@ -45,7 +48,10 @@ describe("[[PreventExtensions]] invariants", () => {
expect(() => { expect(() => {
Object.preventExtensions(p); Object.preventExtensions(p);
}).toThrowWithMessage(TypeError, "Proxy handler's preventExtensions trap violates invariant: cannot return true if the target object is extensible"); }).toThrowWithMessage(
TypeError,
"Proxy handler's preventExtensions trap violates invariant: cannot return true if the target object is extensible"
);
Object.preventExtensions(o); Object.preventExtensions(o);
expect(Object.preventExtensions(p)).toBe(p); expect(Object.preventExtensions(p)).toBe(p);

View file

@ -21,7 +21,9 @@ describe("[[Set]] trap normal behavior", () => {
}); });
test("conditional return value", () => { test("conditional return value", () => {
let p = new Proxy({}, { let p = new Proxy(
{},
{
set(target, prop, value) { set(target, prop, value) {
if (target[prop] === value) { if (target[prop] === value) {
target[prop] *= 2; target[prop] *= 2;
@ -29,7 +31,8 @@ describe("[[Set]] trap normal behavior", () => {
target[prop] = value; target[prop] = value;
} }
}, },
}); }
);
p.foo = 10; p.foo = 10;
expect(p.foo).toBe(10); expect(p.foo).toBe(10);
@ -53,7 +56,10 @@ describe("[[Set]] invariants", () => {
expect(() => { expect(() => {
p.foo = 12; p.foo = 12;
}).toThrowWithMessage(TypeError, "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable, non-writable own data property"); }).toThrowWithMessage(
TypeError,
"Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable, non-writable own data property"
);
}); });
test("cannot return true for a non-configurable accessor property with no setter", () => { test("cannot return true for a non-configurable accessor property with no setter", () => {
@ -68,6 +74,9 @@ describe("[[Set]] invariants", () => {
expect(() => { expect(() => {
p.foo = 12; p.foo = 12;
}).toThrowWithMessage(TypeError, "Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable own accessor property with an undefined set attribute"); }).toThrowWithMessage(
TypeError,
"Proxy handler's set trap violates invariant: cannot return true for a property on the target which is a non-configurable own accessor property with an undefined set attribute"
);
}); });
}); });

View file

@ -21,7 +21,7 @@ describe("[[SetPrototypeOf]] trap normal behavior", () => {
expect(target).toBe(o); expect(target).toBe(o);
expect(newProto).toBe(theNewProto); expect(newProto).toBe(theNewProto);
return true; return true;
} },
}); });
Object.setPrototypeOf(p, theNewProto); Object.setPrototypeOf(p, theNewProto);
@ -32,8 +32,7 @@ describe("[[SetPrototypeOf]] trap normal behavior", () => {
let p = new Proxy(o, { let p = new Proxy(o, {
setPrototypeOf(target, newProto) { setPrototypeOf(target, newProto) {
if (target.shouldSet) if (target.shouldSet) Object.setPrototypeOf(target, newProto);
Object.setPrototypeOf(target, newProto);
return true; return true;
}, },
}); });
@ -84,11 +83,14 @@ describe("[[SetPrototypeOf]] invariants", () => {
let p = new Proxy(o, { let p = new Proxy(o, {
setPrototypeOf() { setPrototypeOf() {
return true; return true;
} },
}); });
expect(() => { expect(() => {
Object.setPrototypeOf(p, {}); Object.setPrototypeOf(p, {});
}).toThrowWithMessage(TypeError, "Proxy handler's setPrototypeOf trap violates invariant: the argument must match the prototype of the target if the target is non-extensible"); }).toThrowWithMessage(
TypeError,
"Proxy handler's setPrototypeOf trap violates invariant: the argument must match the prototype of the target if the target is non-extensible"
);
}); });
}); });

View file

@ -17,11 +17,17 @@ test("constructor argument count", () => {
test("constructor requires objects", () => { test("constructor requires objects", () => {
expect(() => { expect(() => {
new Proxy(1, {}); new Proxy(1, {});
}).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got 1"); }).toThrowWithMessage(
TypeError,
"Expected target argument of Proxy constructor to be object, got 1"
);
expect(() => { expect(() => {
new Proxy({}, 1); new Proxy({}, 1);
}).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got 1"); }).toThrowWithMessage(
TypeError,
"Expected handler argument of Proxy constructor to be object, got 1"
);
}); });
test("constructor must be invoked with 'new'", () => { test("constructor must be invoked with 'new'", () => {

View file

@ -23,7 +23,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => { expect(() => {
Reflect.construct(() => {}, [], value); Reflect.construct(() => {}, [], value);
}).toThrowWithMessage(TypeError, "Optional third argument of Reflect.construct() must be a constructor"); }).toThrowWithMessage(
TypeError,
"Optional third argument of Reflect.construct() must be a constructor"
);
}); });
}); });
}); });

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.defineProperty(value); Reflect.defineProperty(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.defineProperty() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.defineProperty() must be an object"
);
}); });
}); });
@ -20,7 +23,6 @@ describe("errors", () => {
}); });
}); });
describe("normal behavior", () => { describe("normal behavior", () => {
test("initial value and non-writable", () => { test("initial value and non-writable", () => {
var o = {}; var o = {};
@ -46,7 +48,9 @@ describe("normal behavior", () => {
var o = {}; var o = {};
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })).toBeTrue(); expect(
Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })
).toBeTrue();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2); expect(o.foo).toBe(2);
@ -56,7 +60,9 @@ describe("normal behavior", () => {
var o = {}; var o = {};
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })).toBeTrue(); expect(
Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })
).toBeTrue();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2); expect(o.foo).toBe(2);
@ -66,7 +72,9 @@ describe("normal behavior", () => {
var o = {}; var o = {};
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })).toBeTrue(); expect(
Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })
).toBeTrue();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse(); expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.deleteProperty(value); Reflect.deleteProperty(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.deleteProperty() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.deleteProperty() must be an object"
);
}); });
}); });
}); });

View file

@ -44,7 +44,7 @@ describe("normal behavior", () => {
const foo = { const foo = {
get prop() { get prop() {
this.getPropCalled = true; this.getPropCalled = true;
} },
}; };
const bar = {}; const bar = {};
Object.setPrototypeOf(bar, foo); Object.setPrototypeOf(bar, foo);

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.getOwnPropertyDescriptor(value); Reflect.getOwnPropertyDescriptor(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.getOwnPropertyDescriptor() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.getOwnPropertyDescriptor() must be an object"
);
}); });
}); });
}); });

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.getPrototypeOf(value); Reflect.getPrototypeOf(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.getPrototypeOf() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.getPrototypeOf() must be an object"
);
}); });
}); });
}); });

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.isExtensible(value); Reflect.isExtensible(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.isExtensible() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.isExtensible() must be an object"
);
}); });
}); });
}); });

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.preventExtensions(value); Reflect.preventExtensions(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.preventExtensions() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.preventExtensions() must be an object"
);
}); });
}); });
}); });

View file

@ -66,7 +66,7 @@ describe("normal behavior", () => {
const foo = { const foo = {
set prop(value) { set prop(value) {
this.setPropCalled = true; this.setPropCalled = true;
} },
}; };
expect(foo.setPropCalled).toBeUndefined(); expect(foo.setPropCalled).toBeUndefined();
Reflect.set(foo, "prop", 42); Reflect.set(foo, "prop", 42);
@ -77,7 +77,7 @@ describe("normal behavior", () => {
const foo = { const foo = {
set prop(value) { set prop(value) {
this.setPropCalled = true; this.setPropCalled = true;
} },
}; };
const bar = {}; const bar = {};
Object.setPrototypeOf(bar, foo); Object.setPrototypeOf(bar, foo);

View file

@ -7,7 +7,10 @@ describe("errors", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => { [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => { expect(() => {
Reflect.setPrototypeOf(value); Reflect.setPrototypeOf(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.setPrototypeOf() must be an object"); }).toThrowWithMessage(
TypeError,
"First argument of Reflect.setPrototypeOf() must be an object"
);
}); });
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(String.prototype.charAt).toHaveLength(1); expect(String.prototype.charAt).toHaveLength(1);
var s = "foobar" var s = "foobar";
expect(typeof s).toBe("string"); expect(typeof s).toBe("string");
expect(s).toHaveLength(6); expect(s).toHaveLength(6);

View file

@ -2,13 +2,13 @@ test("basic functionality", () => {
expect(String.prototype.concat).toHaveLength(1); expect(String.prototype.concat).toHaveLength(1);
expect("".concat(1)).toBe("1"); expect("".concat(1)).toBe("1");
expect("".concat(3,2,1)).toBe("321"); expect("".concat(3, 2, 1)).toBe("321");
expect("hello".concat(" ", "friends")).toBe("hello friends"); expect("hello".concat(" ", "friends")).toBe("hello friends");
expect("".concat(null)).toBe("null"); expect("".concat(null)).toBe("null");
expect("".concat(false)).toBe("false"); expect("".concat(false)).toBe("false");
expect("".concat(true)).toBe("true"); expect("".concat(true)).toBe("true");
expect("".concat([])).toBe(""); expect("".concat([])).toBe("");
expect("".concat([1, 2, 3, 'hello'])).toBe("1,2,3,hello"); expect("".concat([1, 2, 3, "hello"])).toBe("1,2,3,hello");
expect("".concat(true, [])).toBe("true"); expect("".concat(true, [])).toBe("true");
expect("".concat(true, false)).toBe("truefalse"); expect("".concat(true, false)).toBe("truefalse");
expect("".concat({})).toBe("[object Object]"); expect("".concat({})).toBe("[object Object]");

View file

@ -1,12 +1,12 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(String.prototype.includes).toHaveLength(1); expect(String.prototype.includes).toHaveLength(1);
expect("hello friends".includes("hello")).toBe(true); expect("hello friends".includes("hello")).toBeTrue();
expect("hello friends".includes("hello", 100)).toBe(false); expect("hello friends".includes("hello", 100)).toBeFalse();
expect("hello friends".includes("hello", -10)).toBe(true); expect("hello friends".includes("hello", -10)).toBeTrue();
expect("hello friends".includes("friends", 6)).toBe(true); expect("hello friends".includes("friends", 6)).toBeTrue();
expect("hello friends".includes("hello", 6)).toBe(false); expect("hello friends".includes("hello", 6)).toBeFalse();
expect("hello friends false".includes(false)).toBe(true); expect("hello friends false".includes(false)).toBeTrue();
expect("hello 10 friends".includes(10)).toBe(true); expect("hello 10 friends".includes(10)).toBeTrue();
expect("hello friends undefined".includes()).toBe(true); expect("hello friends undefined".includes()).toBeTrue();
}); });

View file

@ -1,7 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(String.prototype.indexOf).toHaveLength(1); expect(String.prototype.indexOf).toHaveLength(1);
var s = "hello friends" var s = "hello friends";
expect(s.indexOf("friends")).toBe(6); expect(s.indexOf("friends")).toBe(6);
expect(s.indexOf("enemies")).toBe(-1); expect(s.indexOf("enemies")).toBe(-1);

View file

@ -15,4 +15,3 @@ test("basic functionality", () => {
expect("hello friends".slice(1000)).toBe(""); expect("hello friends".slice(1000)).toBe("");
expect("hello friends".slice(-1000)).toBe("hello friends"); expect("hello friends".slice(-1000)).toBe("hello friends");
}); });

View file

@ -5,7 +5,7 @@ test("basic functionality", () => {
expect("hello friends".substring(1)).toBe("ello friends"); expect("hello friends".substring(1)).toBe("ello friends");
expect("hello friends".substring(0, 5)).toBe("hello"); expect("hello friends".substring(0, 5)).toBe("hello");
expect("hello friends".substring(13, 6)).toBe("friends"); expect("hello friends".substring(13, 6)).toBe("friends");
expect("hello friends".substring('', 5)).toBe("hello"); expect("hello friends".substring("", 5)).toBe("hello");
expect("hello friends".substring(3, 3)).toBe(""); expect("hello friends".substring(3, 3)).toBe("");
expect("hello friends".substring(-1, 13)).toBe("hello friends"); expect("hello friends".substring(-1, 13)).toBe("hello friends");
expect("hello friends".substring(0, 50)).toBe("hello friends"); expect("hello friends".substring(0, 50)).toBe("hello friends");

View file

@ -5,5 +5,5 @@ test("basic functionality", () => {
expect("Foo".toLowerCase()).toBe("foo"); expect("Foo".toLowerCase()).toBe("foo");
expect("FOO".toLowerCase()).toBe("foo"); expect("FOO".toLowerCase()).toBe("foo");
expect(('b' + 'a' + + 'a' + 'a').toLowerCase()).toBe("banana"); expect(("b" + "a" + +"a" + "a").toLowerCase()).toBe("banana");
}); });

View file

@ -1,5 +1,5 @@
test("basic functionality", () => { test("basic functionality", () => {
expect(String.prototype.toString).toHaveLength(0) expect(String.prototype.toString).toHaveLength(0);
expect("".toString()).toBe(""); expect("".toString()).toBe("");
expect("hello friends".toString()).toBe("hello friends"); expect("hello friends".toString()).toBe("hello friends");

View file

@ -5,5 +5,5 @@ test("basic functionality", () => {
expect("Foo".toUpperCase()).toBe("FOO"); expect("Foo".toUpperCase()).toBe("FOO");
expect("FOO".toUpperCase()).toBe("FOO"); expect("FOO".toUpperCase()).toBe("FOO");
expect(('b' + 'a' + + 'n' + 'a').toUpperCase()).toBe("BANANA"); expect(("b" + "a" + +"n" + "a").toUpperCase()).toBe("BANANA");
}); });

View file

@ -1,4 +1,4 @@
load("test-common.js") load("test-common.js");
try { try {
const localSym = Symbol("foo"); const localSym = Symbol("foo");
@ -17,12 +17,15 @@ try {
assert(Symbol.for().description === "undefined"); assert(Symbol.for().description === "undefined");
assert(Symbol.for(null).description === "null"); assert(Symbol.for(null).description === "null");
assertThrowsError(() => { assertThrowsError(
() => {
Symbol.for(Symbol()); Symbol.for(Symbol());
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot convert symbol to string", message: "Cannot convert symbol to string",
}); }
);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -1,4 +1,4 @@
load("test-common.js") load("test-common.js");
try { try {
const s1 = Symbol("foo"); const s1 = Symbol("foo");
@ -13,12 +13,15 @@ try {
assert(typeof s1 === "symbol"); assert(typeof s1 === "symbol");
assertThrowsError(() => { assertThrowsError(
Symbol(Symbol('foo')); () => {
}, { Symbol(Symbol("foo"));
},
{
error: TypeError, error: TypeError,
message: "Cannot convert symbol to string" message: "Cannot convert symbol to string",
}) }
);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -1,4 +1,4 @@
load("test-common.js") load("test-common.js");
try { try {
const localSym = Symbol("foo"); const localSym = Symbol("foo");
@ -8,12 +8,15 @@ try {
assert(Symbol.keyFor(globalSym) === "foo"); assert(Symbol.keyFor(globalSym) === "foo");
const testThrows = (value, str) => { const testThrows = (value, str) => {
assertThrowsError(() => { assertThrowsError(
() => {
Symbol.keyFor(value); Symbol.keyFor(value);
}, { },
{
error: TypeError, error: TypeError,
message: str + " is not a symbol", message: str + " is not a symbol",
}); }
);
}; };
testThrows(1, "1"); testThrows(1, "1");
@ -23,7 +26,7 @@ try {
testThrows({}, "[object Object]"); testThrows({}, "[object Object]");
testThrows(true, "true"); testThrows(true, "true");
testThrows("foobar", "foobar"); testThrows("foobar", "foobar");
testThrows(function(){}, "[object ScriptFunction]"); // FIXME: Better function stringification testThrows(function () {}, "[object ScriptFunction]"); // FIXME: Better function stringification
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -1,4 +1,4 @@
load("test-common.js") load("test-common.js");
try { try {
const s1 = Symbol("foo"); const s1 = Symbol("foo");
@ -7,19 +7,25 @@ try {
assert(s1.toString() === "Symbol(foo)"); assert(s1.toString() === "Symbol(foo)");
assert(s2.toString() === "Symbol(bar)"); assert(s2.toString() === "Symbol(bar)");
assertThrowsError(() => { assertThrowsError(
() => {
s1 + ""; s1 + "";
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot convert symbol to string", message: "Cannot convert symbol to string",
}); }
);
assertThrowsError(() => { assertThrowsError(
() => {
s1 + 1; s1 + 1;
}, { },
{
error: TypeError, error: TypeError,
message: "Cannot convert symbol to number", message: "Cannot convert symbol to number",
}); }
);
console.log("PASS"); console.log("PASS");
} catch (e) { } catch (e) {

View file

@ -1,20 +1,23 @@
load("test-common.js"); load("test-common.js");
try { try {
let local = Symbol('foo'); let local = Symbol("foo");
let global = Symbol.for('foo'); let global = Symbol.for("foo");
assert(local.valueOf() === local); assert(local.valueOf() === local);
assert(global.valueOf() === global); assert(global.valueOf() === global);
assert(Symbol.prototype.valueOf.call(local) === local); assert(Symbol.prototype.valueOf.call(local) === local);
assert(Symbol.prototype.valueOf.call(global) === global); assert(Symbol.prototype.valueOf.call(global) === global);
assertThrowsError(() => { assertThrowsError(
() => {
Symbol.prototype.valueOf.call("foo"); Symbol.prototype.valueOf.call("foo");
}, { },
{
error: TypeError, error: TypeError,
message: "Not a Symbol object", message: "Not a Symbol object",
}); }
);
console.log("PASS"); console.log("PASS");
} catch (err) { } catch (err) {

View file

@ -2,11 +2,11 @@ test("parsing numbers", () => {
[ [
[0, 0], [0, 0],
[1, 1], [1, 1],
[.23, 0.23], [0.23, 0.23],
[1.23, 1.23], [1.23, 1.23],
[0.0123E+2, 1.23], [0.0123e2, 1.23],
[1.23e4, 12300], [1.23e4, 12300],
[Infinity, Infinity] [Infinity, Infinity],
].forEach(test => { ].forEach(test => {
expect(parseFloat(test[0])).toBe(test[1]); expect(parseFloat(test[0])).toBe(test[1]);
expect(parseFloat(+test[0])).toBe(test[1]); expect(parseFloat(+test[0])).toBe(test[1]);
@ -22,7 +22,7 @@ test("parsing strings", () => {
["1.23", 1.23], ["1.23", 1.23],
["0.0123E+2", 1.23], ["0.0123E+2", 1.23],
["1.23e4", 12300], ["1.23e4", 12300],
["Infinity", Infinity] ["Infinity", Infinity],
].forEach(test => { ].forEach(test => {
expect(parseFloat(test[0])).toBe(test[1]); expect(parseFloat(test[0])).toBe(test[1]);
expect(parseFloat(`+${test[0]}`)).toBe(test[1]); expect(parseFloat(`+${test[0]}`)).toBe(test[1]);
@ -49,7 +49,7 @@ test("parsing NaN", () => {
"foo123", "foo123",
"foo+123", "foo+123",
"fooInfinity", "fooInfinity",
"foo+Infinity" "foo+Infinity",
].forEach(value => { ].forEach(value => {
expect(parseFloat(value)).toBeNaN(); expect(parseFloat(value)).toBeNaN();
}); });

Some files were not shown because too many files have changed in this diff Show more