mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:28:11 +00:00
test-js: Use prettier and format all files
This commit is contained in:
parent
e532888242
commit
6d58c48c2f
248 changed files with 8291 additions and 7725 deletions
13
Libraries/LibJS/Tests/.prettierrc
Normal file
13
Libraries/LibJS/Tests/.prettierrc
Normal 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
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
test("Issue #1829, if-else without braces or semicolons", () => {
|
||||
const source =
|
||||
`if (1)
|
||||
const source = `if (1)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
@ -19,8 +18,7 @@ else
|
|||
});
|
||||
|
||||
test("break/continue, variable declaration, do-while, and return asi", () => {
|
||||
const source =
|
||||
`function foo() {
|
||||
const source = `function foo() {
|
||||
label:
|
||||
for (var i = 0; i < 4; i++) {
|
||||
break // semicolon inserted here
|
||||
|
@ -45,8 +43,7 @@ return foo();`;
|
|||
});
|
||||
|
||||
test("more break and continue asi", () => {
|
||||
const source =
|
||||
`let counter = 0;
|
||||
const source = `let counter = 0;
|
||||
let outer;
|
||||
|
||||
outer:
|
||||
|
|
|
@ -30,16 +30,23 @@ try {
|
|||
assert(a[0][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");
|
||||
|
||||
[-1, -100, -0.1, 0.1, 1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new Array(value);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Invalid array length"
|
||||
});
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -32,7 +32,11 @@ try {
|
|||
assert(a[0][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);
|
||||
assert(a.length === 4);
|
||||
assert(a[0] === 1);
|
||||
|
|
|
@ -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", 2: "baz" }) === "foo,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" };
|
||||
|
||||
{
|
||||
assertVisitsAll(visit => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.every.call(o, function (value) {
|
||||
visit(value);
|
||||
return true;
|
||||
});
|
||||
}, ["foo", "bar", "baz"]);
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
}
|
||||
|
||||
["find", "findIndex"].forEach(name => {
|
||||
assertVisitsAll(visit => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype[name].call(o, function (value) {
|
||||
visit(value);
|
||||
return false;
|
||||
});
|
||||
}, ["foo", "bar", undefined, "baz", undefined]);
|
||||
},
|
||||
["foo", "bar", undefined, "baz", undefined]
|
||||
);
|
||||
});
|
||||
|
||||
["filter", "forEach", "map", "some"].forEach(name => {
|
||||
assertVisitsAll(visit => {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype[name].call(o, function (value) {
|
||||
visit(value);
|
||||
return false;
|
||||
});
|
||||
}, ["foo", "bar", "baz"]);
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
});
|
||||
{
|
||||
assertVisitsAll(visit => {
|
||||
Array.prototype.reduce.call(o, function (_, value) {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.reduce.call(
|
||||
o,
|
||||
function (_, value) {
|
||||
visit(value);
|
||||
return false;
|
||||
}, "initial");
|
||||
}, ["foo", "bar", "baz"]);
|
||||
},
|
||||
"initial"
|
||||
);
|
||||
},
|
||||
["foo", "bar", "baz"]
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
assertVisitsAll(visit => {
|
||||
Array.prototype.reduceRight.call(o, function (_, value) {
|
||||
assertVisitsAll(
|
||||
visit => {
|
||||
Array.prototype.reduceRight.call(
|
||||
o,
|
||||
function (_, value) {
|
||||
visit(value);
|
||||
return false;
|
||||
}, "initial");
|
||||
}, ["baz", "bar", "foo"]);
|
||||
},
|
||||
"initial"
|
||||
);
|
||||
},
|
||||
["baz", "bar", "foo"]
|
||||
);
|
||||
}
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -8,11 +8,11 @@ try {
|
|||
var array_concat = array.concat();
|
||||
assert(array_concat.length === array.length);
|
||||
|
||||
array_concat = array.concat(1)
|
||||
array_concat = array.concat(1);
|
||||
assert(array_concat.length === 3);
|
||||
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[2] === 1);
|
||||
assert(array_concat[3] === 2);
|
||||
|
@ -30,7 +30,6 @@ try {
|
|||
assert(array_concat[4][0] === 2);
|
||||
assert(array_concat[4][1] === 3);
|
||||
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.every.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].every(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var arrayOne = ["serenity", { test: "serenity" }];
|
||||
var arrayTwo = [true, false, 1, 2, 3, "3"];
|
||||
|
@ -16,13 +19,13 @@ try {
|
|||
assert(arrayOne.every(value => value === "hello") === false);
|
||||
assert(arrayOne.every(value => value === "serenity") === false);
|
||||
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(arrayTwo.every((value, index, arr) => index > 0) === false);
|
||||
assert(arrayTwo.every((value, index, arr) => index >= 0) === true);
|
||||
assert(arrayTwo.every(value => typeof(value) !== "string") === false);
|
||||
assert(arrayTwo.every(value => typeof(value) === "number") === false);
|
||||
assert(arrayTwo.every(value => typeof value !== "string") === false);
|
||||
assert(arrayTwo.every(value => typeof value === "number") === false);
|
||||
assert(arrayTwo.every(value => value > 0) === false);
|
||||
assert(arrayTwo.every(value => value >= 0 && value < 4) === true);
|
||||
assert(arrayTwo.every(value => arrayTwo.pop()) === true);
|
||||
|
@ -33,10 +36,12 @@ try {
|
|||
arrayTwo = [true, false, 1, 2, 3, "3"];
|
||||
|
||||
// Every only goes up to the original length.
|
||||
assert(arrayTwo.every((value, index, arr) => {
|
||||
assert(
|
||||
arrayTwo.every((value, index, arr) => {
|
||||
arr.push("serenity");
|
||||
return value < 4;
|
||||
}) === true);
|
||||
}) === true
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -21,4 +21,3 @@ try {
|
|||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,22 +3,30 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.filter.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].filter();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.filter() requires at least one argument"
|
||||
});
|
||||
message: "Array.prototype.filter() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].filter(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => { callbackCalled++; };
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
assert([].filter(callback).length === 0);
|
||||
assert(callbackCalled === 0);
|
||||
|
@ -33,9 +41,20 @@ try {
|
|||
assert(evenNumbers[2] === 4);
|
||||
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) => {
|
||||
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1)
|
||||
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1);
|
||||
};
|
||||
|
||||
var results;
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.find.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].find(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
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 => value == "1") === 1);
|
||||
assert(array.find(value => value === 1) === 1);
|
||||
assert(array.find(value => typeof(value) !== "string") === 1);
|
||||
assert(array.find(value => typeof(value) === "boolean") === false);
|
||||
assert(array.find(value => typeof value !== "string") === 1);
|
||||
assert(array.find(value => typeof value === "boolean") === false);
|
||||
assert(array.find(value => value > 1) === 2);
|
||||
assert(array.find(value => value > 1 && value < 3) === 2);
|
||||
assert(array.find(value => value > 100) === undefined);
|
||||
assert([].find(value => value === 1) === undefined);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => { callbackCalled++; };
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
[].find(callback)
|
||||
[].find(callback);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
[1, 2, 3].find(callback);
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.findIndex.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].findIndex(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
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 => value == "1") === 2);
|
||||
assert(array.findIndex(value => value === 1) === 2);
|
||||
assert(array.findIndex(value => typeof(value) !== "string") === 2);
|
||||
assert(array.findIndex(value => typeof(value) === "boolean") === 4);
|
||||
assert(array.findIndex(value => typeof value !== "string") === 2);
|
||||
assert(array.findIndex(value => typeof value === "boolean") === 4);
|
||||
assert(array.findIndex(value => value > 1) === 3);
|
||||
assert(array.findIndex(value => value > 1 && value < 3) === 3);
|
||||
assert(array.findIndex(value => value > 100) === -1);
|
||||
assert([].findIndex(value => value === 1) === -1);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => { callbackCalled++; };
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
[].findIndex(callback)
|
||||
[].findIndex(callback);
|
||||
assert(callbackCalled === 0);
|
||||
|
||||
[1, 2, 3].findIndex(callback);
|
||||
|
|
|
@ -3,24 +3,32 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.forEach.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].forEach();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.forEach() requires at least one argument"
|
||||
});
|
||||
message: "Array.prototype.forEach() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].forEach(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var a = [1, 2, 3];
|
||||
var o = {};
|
||||
var callbackCalled = 0;
|
||||
var callback = () => { callbackCalled++; };
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
assert([].forEach(callback) === undefined);
|
||||
assert(callbackCalled === 0);
|
||||
|
|
|
@ -3,18 +3,18 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.includes.length === 1);
|
||||
|
||||
var array = ['hello', 'friends', 1, 2, false];
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
|
||||
assert([].includes() === false);
|
||||
assert([undefined].includes() === true);
|
||||
assert(array.includes('hello') === true);
|
||||
assert(array.includes("hello") === true);
|
||||
assert(array.includes(1) === 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(2, -1) === false);
|
||||
assert(array.includes(2, -100) === true);
|
||||
assert(array.includes('friends', 100) === false);
|
||||
assert(array.includes("friends", 100) === false);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -3,23 +3,23 @@ load("test-common.js");
|
|||
try {
|
||||
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('friends') === 1);
|
||||
assert(array.indexOf("hello") === 0);
|
||||
assert(array.indexOf("friends") === 1);
|
||||
assert(array.indexOf(false) === 4);
|
||||
assert(array.indexOf(false, 2) === 4);
|
||||
assert(array.indexOf(false, -2) === 4);
|
||||
assert(array.indexOf(1) === 2);
|
||||
assert(array.indexOf(1, 1000) === -1);
|
||||
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(2, -1) === -1);
|
||||
assert(array.indexOf(2, -2) === 3);
|
||||
assert([].indexOf('serenity') === -1);
|
||||
assert([].indexOf('serenity', 10) === -1);
|
||||
assert([].indexOf('serenity', -10) === -1);
|
||||
assert([].indexOf("serenity") === -1);
|
||||
assert([].indexOf("serenity", 10) === -1);
|
||||
assert([].indexOf("serenity", -10) === -1);
|
||||
assert([].indexOf() === -1);
|
||||
assert([undefined].indexOf() === 0);
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ try {
|
|||
assert(array.lastIndexOf(2) === 1);
|
||||
assert(array.lastIndexOf(2, -3) === 1);
|
||||
assert(array.lastIndexOf(2, -4) === 1);
|
||||
assert([].lastIndexOf('hello') === -1);
|
||||
assert([].lastIndexOf('hello', 10) === -1);
|
||||
assert([].lastIndexOf('hello', -10) === -1);
|
||||
assert([].lastIndexOf("hello") === -1);
|
||||
assert([].lastIndexOf("hello", 10) === -1);
|
||||
assert([].lastIndexOf("hello", -10) === -1);
|
||||
assert([].lastIndexOf() === -1);
|
||||
assert([undefined].lastIndexOf() === 0);
|
||||
assert([undefined, undefined, undefined].lastIndexOf() === 2);
|
||||
|
|
|
@ -3,22 +3,30 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.map.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].map();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Array.prototype.map() requires at least one argument"
|
||||
});
|
||||
message: "Array.prototype.map() requires at least one argument",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].map(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var callbackCalled = 0;
|
||||
var callback = () => { callbackCalled++; };
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
};
|
||||
|
||||
assert([].map(callback).length === 0);
|
||||
assert(callbackCalled === 0);
|
||||
|
@ -30,7 +38,9 @@ try {
|
|||
assert([1, , , "foo", , undefined, , ,].map(callback).length === 8);
|
||||
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[0] === "0 -> undefined");
|
||||
assert(results[1] === "1 -> null");
|
||||
|
|
|
@ -3,38 +3,55 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.reduce.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[1].reduce();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
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);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].reduce((a, x) => x);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
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);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
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 callback = () => { callbackCalled++; return true };
|
||||
var callback = () => {
|
||||
callbackCalled++;
|
||||
return true;
|
||||
};
|
||||
|
||||
assert([1].reduce(callback) === 1);
|
||||
assert(callbackCalled === 0);
|
||||
|
@ -70,18 +87,24 @@ try {
|
|||
result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100);
|
||||
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);
|
||||
|
||||
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(indexes.length === 2);
|
||||
assert(indexes[0] === 1);
|
||||
assert(indexes[1] === 2);
|
||||
|
||||
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(indexes.length === 3);
|
||||
assert(indexes[0] === 0);
|
||||
|
@ -89,13 +112,18 @@ try {
|
|||
assert(indexes[2] === 2);
|
||||
|
||||
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.prop === true);
|
||||
|
||||
var a1 = [1, 2];
|
||||
var a2 = null;
|
||||
a1.reduce((a, v, i, t) => { a2 = t });
|
||||
a1.reduce((a, v, i, t) => {
|
||||
a2 = t;
|
||||
});
|
||||
assert(a1 === a2);
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -13,7 +13,7 @@ try {
|
|||
assert(array_slice[2] === "serenity");
|
||||
assert(array_slice[3] === 1);
|
||||
|
||||
array_slice = array.slice(1)
|
||||
array_slice = array.slice(1);
|
||||
assert(array_slice.length === 3);
|
||||
assert(array_slice[0] === "friends");
|
||||
assert(array_slice[1] === "serenity");
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(Array.prototype.some.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[].some(undefined);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
message: "undefined is not a function",
|
||||
}
|
||||
);
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false, -42, { name: "serenityos" }];
|
||||
|
||||
|
@ -18,8 +21,8 @@ try {
|
|||
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 => typeof(value) !== "string") === true);
|
||||
assert(array.some(value => typeof(value) === "boolean") === true);
|
||||
assert(array.some(value => typeof value !== "string") === true);
|
||||
assert(array.some(value => typeof value === "boolean") === true);
|
||||
assert(array.some(value => value > 1) === true);
|
||||
assert(array.some(value => value > 1 && value < 3) === true);
|
||||
assert(array.some(value => value > 100) === false);
|
||||
|
|
|
@ -13,7 +13,7 @@ try {
|
|||
toString: () => {
|
||||
toStringCalled++;
|
||||
return "o";
|
||||
}
|
||||
},
|
||||
};
|
||||
assert([o, undefined, o, null, o].toLocaleString() === "o,,o,,o");
|
||||
assert(toStringCalled === 3);
|
||||
|
|
|
@ -2,9 +2,9 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
var a = [1, 2, 3];
|
||||
assert(a.toString() === '1,2,3');
|
||||
assert([].toString() === '');
|
||||
assert([5].toString() === '5');
|
||||
assert(a.toString() === "1,2,3");
|
||||
assert([].toString() === "");
|
||||
assert([5].toString() === "5");
|
||||
|
||||
assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)");
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ try {
|
|||
assert(a[2] === undefined);
|
||||
assert(a[3] === undefined);
|
||||
|
||||
a = [1,,2,,,3,];
|
||||
a = [1, , 2, , , 3];
|
||||
assert(a.length === 6);
|
||||
assert(a.toString() === "1,,2,,,3");
|
||||
assert(a[0] === 1);
|
||||
|
@ -40,7 +40,7 @@ try {
|
|||
assert(a[4] === undefined);
|
||||
assert(a[5] === 3);
|
||||
|
||||
a = [1,,2,,,3,];
|
||||
a = [1, , 2, , , 3];
|
||||
Object.defineProperty(a, 1, {
|
||||
get() {
|
||||
return this.secret_prop;
|
||||
|
|
|
@ -33,12 +33,15 @@ try {
|
|||
assert(a.length === 1);
|
||||
|
||||
[undefined, "foo", -1, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
a.length = value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: RangeError,
|
||||
message: "Invalid array length"
|
||||
});
|
||||
message: "Invalid array length",
|
||||
}
|
||||
);
|
||||
assert(a.length === 1);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
load("test-common.js");
|
||||
|
||||
function testArray(arr) {
|
||||
return arr.length === 4 &&
|
||||
arr[0] === 0 &&
|
||||
arr[1] === 1 &&
|
||||
arr[2] === 2 &&
|
||||
arr[3] === 3;
|
||||
return arr.length === 4 && arr[0] === 0 && arr[1] === 1 && arr[2] === 2 && arr[3] === 3;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -23,20 +19,25 @@ try {
|
|||
arr = [...[], ...[...[0, 1, 2]], 3];
|
||||
assert(testArray(arr));
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...1];
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "1 is not iterable",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
[...{}];
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "[object Object] is not iterable",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -18,42 +18,58 @@ try {
|
|||
assert(BigInt("42") === 42n);
|
||||
assert(BigInt(" \n 00100 \n ") === 100n);
|
||||
assert(BigInt(123n) === 123n);
|
||||
assert(BigInt("3323214327642987348732109829832143298746432437532197321") === 3323214327642987348732109829832143298746432437532197321n);
|
||||
assert(
|
||||
BigInt("3323214327642987348732109829832143298746432437532197321") ===
|
||||
3323214327642987348732109829832143298746432437532197321n
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new BigInt();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "BigInt is not a constructor"
|
||||
});
|
||||
message: "BigInt is not a constructor",
|
||||
}
|
||||
);
|
||||
|
||||
[null, undefined, Symbol()].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
BigInt(value);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: typeof value === "symbol"
|
||||
message:
|
||||
typeof value === "symbol"
|
||||
? "Cannot convert symbol to BigInt"
|
||||
: `Cannot convert ${value} to BigInt`
|
||||
});
|
||||
: `Cannot convert ${value} to BigInt`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
["foo", "123n", "1+1", {}, function () {}].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
BigInt(value);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: SyntaxError,
|
||||
message: `Invalid value for BigInt: ${value}`
|
||||
});
|
||||
message: `Invalid value for BigInt: ${value}`,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
[1.23, Infinity, -Infinity, NaN].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
BigInt(value);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: RangeError,
|
||||
message: "BigInt argument must be an integer"
|
||||
});
|
||||
message: "BigInt argument must be an integer",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(BigInt.prototype.toLocaleString.length === 0);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
BigInt.prototype.toLocaleString.call("foo");
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Not a BigInt object"
|
||||
});
|
||||
message: "Not a BigInt object",
|
||||
}
|
||||
);
|
||||
|
||||
assert(BigInt(123).toLocaleString() === "123");
|
||||
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(BigInt.prototype.toString.length === 0);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
BigInt.prototype.toString.call("foo");
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Not a BigInt object"
|
||||
});
|
||||
message: "Not a BigInt object",
|
||||
}
|
||||
);
|
||||
|
||||
assert(BigInt(123).toString() === "123");
|
||||
|
||||
|
|
|
@ -3,12 +3,15 @@ load("test-common.js");
|
|||
try {
|
||||
assert(BigInt.prototype.valueOf.length === 0);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
BigInt.prototype.valueOf.call("foo");
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Not a BigInt object"
|
||||
});
|
||||
message: "Not a BigInt object",
|
||||
}
|
||||
);
|
||||
|
||||
assert(typeof BigInt(123).valueOf() === "bigint");
|
||||
// FIXME: Uncomment once we support Object() with argument
|
||||
|
|
|
@ -5,14 +5,17 @@ try {
|
|||
|
||||
assert(typeof bigint === "bigint");
|
||||
assert(-bigint === -123n);
|
||||
assert("" + bigint === "123")
|
||||
assert("" + bigint === "123");
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
+bigint;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert BigInt to number"
|
||||
});
|
||||
message: "Cannot convert BigInt to number",
|
||||
}
|
||||
);
|
||||
|
||||
assert(12n + 34n === 46n);
|
||||
assert(12n - 34n === -22n);
|
||||
|
@ -20,7 +23,11 @@ try {
|
|||
assert(123n / 10n === 12n);
|
||||
assert(2n ** 3n === 8n);
|
||||
assert(5n % 3n === 2n);
|
||||
assert(45977665298704210987n + 714320987142450987412098743217984576n / 4598741987421098765327980n * 987498743n === 199365500239020623962n);
|
||||
assert(
|
||||
45977665298704210987n +
|
||||
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n ===
|
||||
199365500239020623962n
|
||||
);
|
||||
|
||||
assert((12n & 5n) === 4n);
|
||||
assert((1n | 2n) === 3n);
|
||||
|
@ -37,7 +44,6 @@ try {
|
|||
assert(--bigint === 1n);
|
||||
assert(bigint === 1n);
|
||||
|
||||
|
||||
assert((1n == 1n) === true);
|
||||
assert((1n == 1) === true);
|
||||
assert((1 == 1n) === true);
|
||||
|
|
|
@ -2,78 +2,114 @@ load("test-common.js");
|
|||
|
||||
try {
|
||||
[1, null, undefined].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n + value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use addition operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use addition operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n - value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use subtraction operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use subtraction operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n * value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use multiplication operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use multiplication operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n / value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use division operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use division operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n % value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use modulo operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use modulo operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n ** value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use exponentiation operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use exponentiation operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n | value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use bitwise OR operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use bitwise OR operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n & value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use bitwise AND operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use bitwise AND operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n ^ value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use bitwise XOR operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use bitwise XOR operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n << value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use left-shift operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use left-shift operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n >> value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use right-shift operator with BigInt and other type"
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
message: "Cannot use right-shift operator with BigInt and other type",
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
1n >>> value;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot use unsigned right-shift operator with BigInt"
|
||||
});
|
||||
message: "Cannot use unsigned right-shift operator with BigInt",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
|
|
|
@ -7,7 +7,7 @@ test("typeof", () => {
|
|||
expect(typeof new Boolean()).toBe("object");
|
||||
expect(typeof Boolean()).toBe("boolean");
|
||||
expect(typeof Boolean(true)).toBe("boolean");
|
||||
})
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
var foo = new Boolean(true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
test("basic functionality", () => {
|
||||
expect(typeof Boolean.prototype).toBe("object");
|
||||
expect(Boolean.prototype.valueOf()).toBeFalse();
|
||||
expect(Boolean.prototype.length).toBeUndefined();
|
||||
expect(Boolean.prototype).not.toHaveProperty("length");
|
||||
});
|
||||
|
|
|
@ -12,8 +12,8 @@ describe("correct behavior", () => {
|
|||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect(Function()()).toBe(undefined);
|
||||
expect(new Function()()).toBe(undefined);
|
||||
expect(Function()()).toBeUndefined();
|
||||
expect(new Function()()).toBeUndefined();
|
||||
expect(Function("return 42")()).toBe(42);
|
||||
expect(new Function("return 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", "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("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
|
||||
// function anonymous() { [ }
|
||||
// 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)"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -42,7 +42,9 @@ test("basic functionality", () => {
|
|||
var add = (x, y) => x + y;
|
||||
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((() => this).apply("foo")).toBe(globalThis);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe("basic behavior", () => {
|
||||
test("basic binding", () => {
|
||||
expect(Function.prototype.bind.length).toBe(1);
|
||||
expect(Function.prototype.bind).toHaveLength(1);
|
||||
|
||||
var charAt = String.prototype.charAt.bind("bar");
|
||||
expect(charAt(0) + charAt(1) + charAt(2)).toBe("bar");
|
||||
|
@ -17,9 +17,21 @@ describe("basic behavior", () => {
|
|||
|
||||
var MakeTrue = Boolean.bind(null, true);
|
||||
|
||||
expect([1, 2, 3].filter(MakeTrue).length).toBe(3);
|
||||
expect([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);
|
||||
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(
|
||||
[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, 6, 7, 8)).toHaveLength(0);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe("bound function |this|", () => {
|
||||
function identity() {
|
||||
|
@ -98,9 +110,9 @@ describe("bound function |this|", () => {
|
|||
});
|
||||
|
||||
test("arrow functions cannot be bound", () => {
|
||||
expect((() => this).bind("foo")()).toBe(globalThis)
|
||||
expect((() => this).bind("foo")()).toBe(globalThis);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
describe("bound function constructors", () => {
|
||||
function Bar() {
|
||||
|
@ -112,7 +124,6 @@ describe("bound function constructors", () => {
|
|||
var BoundBar = Bar.bind({ u: 5, v: 6 });
|
||||
var bar = new BoundBar();
|
||||
|
||||
|
||||
test("bound |this| value does not affect constructor", () => {
|
||||
expect(bar.x).toBe(3);
|
||||
expect(bar.y).toBe(4);
|
||||
|
|
|
@ -44,7 +44,9 @@ test("basic functionality", () => {
|
|||
var add = (x, y) => x + y;
|
||||
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((() => this).call("foo")).toBe(globalThis);
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
test("basic functionality", () => {
|
||||
expect((function() {}).toString()).toBe("function () {\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) {
|
||||
expect(function () {}.toString()).toBe("function () {\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) {
|
||||
if (foo) {
|
||||
return baz;
|
||||
} else if (bar) {
|
||||
return foo;
|
||||
}
|
||||
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(Function.toString()).toBe("function Function() {\n [FunctionConstructor]\n}");
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
test("basic functionality", () => {
|
||||
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 } });
|
||||
|
||||
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: {} });
|
||||
});
|
||||
|
|
|
@ -24,5 +24,7 @@ test("basic functionality", () => {
|
|||
|
||||
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"}'
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
let p = new Proxy([], {
|
||||
get(_, key) {
|
||||
if (key === "length")
|
||||
return 3;
|
||||
if (key === "length") return 3;
|
||||
return Number(key);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -2,28 +2,33 @@ test("basic functionality", () => {
|
|||
let o = {
|
||||
var1: "foo",
|
||||
var2: 42,
|
||||
arr: [1, 2, {
|
||||
arr: [
|
||||
1,
|
||||
2,
|
||||
{
|
||||
nested: {
|
||||
hello: "world",
|
||||
},
|
||||
get x() { return 10; }
|
||||
}],
|
||||
get x() {
|
||||
return 10;
|
||||
},
|
||||
},
|
||||
],
|
||||
obj: {
|
||||
subarr: [3],
|
||||
},
|
||||
};
|
||||
|
||||
let string = JSON.stringify(o, (key, value) => {
|
||||
if (key === "hello")
|
||||
return undefined;
|
||||
if (value === 10)
|
||||
return 20;
|
||||
if (key === "subarr")
|
||||
return [3, 4, 5];
|
||||
if (key === "hello") return undefined;
|
||||
if (value === 10) return 20;
|
||||
if (key === "subarr") return [3, 4, 5];
|
||||
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"]);
|
||||
expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');
|
||||
|
|
|
@ -3,15 +3,18 @@ test("basic functionality", () => {
|
|||
foo: 1,
|
||||
bar: "baz",
|
||||
qux: {
|
||||
get x() { return 10; },
|
||||
y() { return 20; },
|
||||
get x() {
|
||||
return 10;
|
||||
},
|
||||
y() {
|
||||
return 20;
|
||||
},
|
||||
arr: [1, 2, 3],
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let string = JSON.stringify(o, null, 4);
|
||||
let expected =
|
||||
`{
|
||||
let expected = `{
|
||||
"foo": 1,
|
||||
"bar": "baz",
|
||||
"qux": {
|
||||
|
@ -27,8 +30,7 @@ test("basic functionality", () => {
|
|||
expect(string).toBe(expected);
|
||||
|
||||
string = JSON.stringify(o, null, "abcd");
|
||||
expected =
|
||||
`{
|
||||
expected = `{
|
||||
abcd"foo": 1,
|
||||
abcd"bar": "baz",
|
||||
abcd"qux": {
|
||||
|
|
|
@ -29,7 +29,7 @@ describe("correct behavior", () => {
|
|||
let o = this;
|
||||
o.var2 = 10;
|
||||
return o;
|
||||
}
|
||||
},
|
||||
},
|
||||
'{"var1":1,"var2":10}',
|
||||
],
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
test("basic functionality", () => {
|
||||
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(null)).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([1, 2])).toBeNaN();
|
||||
expect(Math.abs({})).toBeNaN();
|
||||
expect(Math.abs('string')).toBeNaN();
|
||||
expect(Math.abs("string")).toBeNaN();
|
||||
expect(Math.abs()).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ test("basic functionality", () => {
|
|||
|
||||
expect(Math.cos(0)).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(Math.PI)).toBe(-1);
|
||||
expect(Math.cos()).toBeNaN();
|
||||
|
|
|
@ -3,7 +3,7 @@ test("basic functionality", () => {
|
|||
|
||||
expect(Math.expm1(0)).toBe(0);
|
||||
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(2)).toBeCloseTo(6.389056);
|
||||
|
||||
|
|
|
@ -9,15 +9,13 @@ function isNegativeZero(value) {
|
|||
test("basic functionality", () => {
|
||||
expect(Math.sign).toHaveLength(1);
|
||||
|
||||
expect(Math.sign.length).toBe(1);
|
||||
|
||||
expect(Math.sign(0.0001)).toBe(1);
|
||||
expect(Math.sign(1)).toBe(1);
|
||||
expect(Math.sign(42)).toBe(1);
|
||||
expect(Math.sign(Infinity)).toBe(1);
|
||||
expect(isPositiveZero(Math.sign(0))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(null))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(''))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign(""))).toBeTrue();
|
||||
expect(isPositiveZero(Math.sign([]))).toBeTrue();
|
||||
|
||||
expect(Math.sign(-0.0001)).toBe(-1);
|
||||
|
@ -26,7 +24,7 @@ test("basic functionality", () => {
|
|||
expect(Math.sign(-Infinity)).toBe(-1);
|
||||
expect(isNegativeZero(Math.sign(-0))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-null))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-''))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-""))).toBeTrue();
|
||||
expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
|
||||
|
||||
expect(Math.sign()).toBeNaN();
|
||||
|
|
|
@ -3,9 +3,9 @@ test("basic functionality", () => {
|
|||
|
||||
expect(Math.sin(0)).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(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()).toBeNaN();
|
||||
expect(Math.sin(undefined)).toBeNaN();
|
||||
|
|
|
@ -3,7 +3,7 @@ test("basic functionality", () => {
|
|||
|
||||
expect(Math.tan(0)).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.ceil(Math.tan(Math.PI / 4))).toBe(1);
|
||||
expect(Math.tan()).toBeNaN();
|
||||
|
|
|
@ -7,6 +7,6 @@ test("basic functionality", () => {
|
|||
expect(Math.trunc(-0.123)).toBe(-0);
|
||||
|
||||
expect(Math.trunc(NaN)).toBeNaN();
|
||||
expect(Math.trunc('foo')).toBeNaN();
|
||||
expect(Math.trunc("foo")).toBeNaN();
|
||||
expect(Math.trunc()).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -15,7 +15,11 @@ describe("normal functionality", () => {
|
|||
|
||||
test("array index getter", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, 2, { get() { return 10; } });
|
||||
Object.defineProperty(o, 2, {
|
||||
get() {
|
||||
return 10;
|
||||
},
|
||||
});
|
||||
expect(o[2]).toBe(10);
|
||||
});
|
||||
|
||||
|
@ -65,8 +69,8 @@ describe("normal functionality", () => {
|
|||
Object.defineProperty(o, "foo", { configurable: true, value: 4 });
|
||||
|
||||
expect(o.foo).toBe(4);
|
||||
expect(o.foo = 5).toBe(5);
|
||||
expect(o.foo = 4).toBe(4);
|
||||
expect((o.foo = 5)).toBe(5);
|
||||
expect((o.foo = 4)).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -88,7 +92,10 @@ describe("errors", () => {
|
|||
get() {},
|
||||
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", () => {
|
||||
|
@ -99,7 +106,10 @@ describe("errors", () => {
|
|||
set() {},
|
||||
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", () => {
|
||||
|
|
|
@ -12,18 +12,28 @@ describe("basic functionality", () => {
|
|||
test("entries with object", () => {
|
||||
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", () => {
|
||||
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", () => {
|
||||
let obj = { foo: 1 };
|
||||
Object.defineProperty(obj, "getFoo", {
|
||||
value: function() { return this.foo; },
|
||||
value: function () {
|
||||
return this.foo;
|
||||
},
|
||||
});
|
||||
let entries = Object.entries(obj);
|
||||
expect(entries).toEqual([["foo", 1]]);
|
||||
|
@ -41,5 +51,5 @@ describe("errors", () => {
|
|||
expect(() => {
|
||||
Object.entries(undefined);
|
||||
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ test("basic functionality", () => {
|
|||
let 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);
|
||||
expect(Object.getPrototypeOf(o1)).toBe(o2);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Object).toHaveLength(1);
|
||||
expect(Object.name).toBe("Object");
|
||||
expect(Object.prototype.length).toBe(undefined);
|
||||
expect(Object.prototype).not.toHaveProperty("length");
|
||||
|
||||
expect(typeof Object()).toBe("object");
|
||||
expect(typeof new Object()).toBe("object");
|
||||
|
|
|
@ -22,7 +22,9 @@ describe("correct behavior", () => {
|
|||
test("ignores non-enumerable properties", () => {
|
||||
let obj = { foo: 1 };
|
||||
Object.defineProperty(obj, "getFoo", {
|
||||
value: function() { return this.foo; },
|
||||
value: function () {
|
||||
return this.foo;
|
||||
},
|
||||
});
|
||||
keys = Object.keys(obj);
|
||||
expect(keys).toEqual(["foo"]);
|
||||
|
|
|
@ -47,7 +47,7 @@ describe("errors", () => {
|
|||
o.foo = "foo";
|
||||
}).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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length", () => {
|
||||
expect(Object.prototype.toLocaleString).toHaveLength(0);
|
||||
})
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
let o;
|
||||
|
@ -16,7 +16,11 @@ describe("correct behavior", () => {
|
|||
|
||||
describe("errors", () => {
|
||||
test("toString that throws error", () => {
|
||||
let o = { toString: () => { throw new Error(); } };
|
||||
let o = {
|
||||
toString: () => {
|
||||
throw new Error();
|
||||
},
|
||||
};
|
||||
expect(() => {
|
||||
o.toLocaleString();
|
||||
}).toThrow(Error);
|
||||
|
|
|
@ -21,8 +21,10 @@ describe("correct behavior", () => {
|
|||
|
||||
test("ignores non-enumerable properties", () => {
|
||||
let obj = { foo: 1 };
|
||||
Object.defineProperty(obj, 'getFoo', {
|
||||
value: function() { return this.foo; },
|
||||
Object.defineProperty(obj, "getFoo", {
|
||||
value: function () {
|
||||
return this.foo;
|
||||
},
|
||||
});
|
||||
let values = Object.values(obj);
|
||||
expect(values).toEqual([1]);
|
||||
|
|
|
@ -14,8 +14,7 @@ describe("[[Call]] trap normal behavior", () => {
|
|||
apply(target, this_, arguments) {
|
||||
expect(target).toBe(f);
|
||||
expect(this_).toBe(handler);
|
||||
if (arguments[2])
|
||||
return arguments[0] * arguments[1];
|
||||
if (arguments[2]) return arguments[0] * arguments[1];
|
||||
return f(...arguments);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
describe("[[Construct]] trap normal behavior", () => {
|
||||
test("forwarding when not defined in handler", () => {
|
||||
let p = new Proxy(function() { this.x = 5; }, { construct: null });
|
||||
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);
|
||||
let p = new Proxy(
|
||||
function () {
|
||||
this.x = 5;
|
||||
},
|
||||
{ construct: null }
|
||||
);
|
||||
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'", () => {
|
||||
|
@ -18,8 +30,7 @@ describe("[[Construct]] trap normal behavior", () => {
|
|||
construct(target, arguments, newTarget) {
|
||||
expect(target).toBe(f);
|
||||
expect(newTarget).toBe(p);
|
||||
if (arguments[1])
|
||||
return Reflect.construct(target, [arguments[0] * 2], newTarget);
|
||||
if (arguments[1]) return Reflect.construct(target, [arguments[0] * 2], newTarget);
|
||||
return Reflect.construct(target, arguments, newTarget);
|
||||
},
|
||||
};
|
||||
|
@ -35,13 +46,12 @@ describe("[[Construct]] trap normal behavior", () => {
|
|||
}
|
||||
|
||||
let p;
|
||||
function theNewTarget() {};
|
||||
function theNewTarget() {}
|
||||
const handler = {
|
||||
construct(target, arguments, newTarget) {
|
||||
expect(target).toBe(f);
|
||||
expect(newTarget).toBe(theNewTarget);
|
||||
if (arguments[1])
|
||||
return Reflect.construct(target, [arguments[0] * 2], newTarget);
|
||||
if (arguments[1]) return Reflect.construct(target, [arguments[0] * 2], newTarget);
|
||||
return Reflect.construct(target, arguments, newTarget);
|
||||
},
|
||||
};
|
||||
|
@ -55,7 +65,7 @@ describe("[[Construct]] invariants", () => {
|
|||
test("target must have a [[Construct]] slot", () => {
|
||||
[{}, [], new Proxy({}, {})].forEach(item => {
|
||||
expect(() => {
|
||||
new (new Proxy(item, {}));
|
||||
new new Proxy(item, {})();
|
||||
}).toThrowWithMessage(TypeError, "[object ProxyObject] is not a constructor");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,13 +31,17 @@ describe("[[DefineProperty]] trap normal behavior", () => {
|
|||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
defineProperty(target, name, descriptor) {
|
||||
if (target[name] === undefined)
|
||||
Object.defineProperty(target, name, descriptor);
|
||||
if (target[name] === undefined) Object.defineProperty(target, name, descriptor);
|
||||
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).not.toHaveConfigurableProperty("foo");
|
||||
expect(p).toHaveWritableProperty("foo");
|
||||
|
@ -45,7 +49,12 @@ describe("[[DefineProperty]] trap normal behavior", () => {
|
|||
expect(p).not.toHaveGetterProperty("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).not.toHaveConfigurableProperty("foo");
|
||||
expect(p).toHaveWritableProperty("foo");
|
||||
|
@ -57,9 +66,14 @@ describe("[[DefineProperty]] trap normal behavior", () => {
|
|||
|
||||
describe("[[DefineProperty]] invariants", () => {
|
||||
test("trap can't return false", () => {
|
||||
let p = new Proxy({}, {
|
||||
defineProperty() { return false; }
|
||||
});
|
||||
let p = new Proxy(
|
||||
{},
|
||||
{
|
||||
defineProperty() {
|
||||
return false;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
Object.defineProperty(p, "foo", {});
|
||||
|
@ -72,12 +86,15 @@ describe("[[DefineProperty]] invariants", () => {
|
|||
let p = new Proxy(o, {
|
||||
defineProperty() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
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", () => {
|
||||
|
@ -91,7 +108,10 @@ describe("[[DefineProperty]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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", () => {
|
||||
|
@ -105,6 +125,9 @@ describe("[[DefineProperty]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
describe("[[Delete]] trap normal behavior", () => {
|
||||
test("forwarding when not defined in handler", () => {
|
||||
expect(delete (new Proxy({}, { deleteProperty: undefined })).foo).toBeTrue();
|
||||
expect(delete (new Proxy({}, { deleteProperty: null })).foo).toBeTrue();
|
||||
expect(delete (new Proxy({}, {})).foo).toBeTrue();
|
||||
expect(delete new Proxy({}, { deleteProperty: undefined }).foo).toBeTrue();
|
||||
expect(delete new Proxy({}, { deleteProperty: null }).foo).toBeTrue();
|
||||
expect(delete new Proxy({}, {}).foo).toBeTrue();
|
||||
});
|
||||
|
||||
test("correct arguments supplied to trap", () => {
|
||||
|
@ -12,7 +12,7 @@ describe("[[Delete]] trap normal behavior", () => {
|
|||
expect(target).toBe(o);
|
||||
expect(property).toBe("foo");
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
delete p.foo;
|
||||
|
@ -27,18 +27,17 @@ describe("[[Delete]] trap normal behavior", () => {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(delete p.foo).toBeTrue();
|
||||
expect(delete p.bar).toBeFalse();
|
||||
|
||||
expect(o.foo).toBe(undefined);
|
||||
expect(o.foo).toBeUndefined();
|
||||
expect(o.bar).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("[[Delete]] invariants", () => {
|
||||
test("cannot report a non-configurable own property as deleted", () => {
|
||||
let o = {};
|
||||
|
@ -51,6 +50,9 @@ describe("[[Delete]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
describe("[[Get]] trap normal behavior", () => {
|
||||
test("forwarding when not defined in handler", () => {
|
||||
expect((new Proxy({}, { get: undefined })).foo).toBeUndefined();
|
||||
expect((new Proxy({}, { get: null })).foo).toBeUndefined();
|
||||
expect((new Proxy({}, {})).foo).toBeUndefined();
|
||||
expect(new Proxy({}, { get: undefined }).foo).toBeUndefined();
|
||||
expect(new Proxy({}, { get: null }).foo).toBeUndefined();
|
||||
expect(new Proxy({}, {}).foo).toBeUndefined();
|
||||
});
|
||||
|
||||
test("correct arguments supplied to trap", () => {
|
||||
|
@ -30,7 +30,7 @@ describe("[[Get]] trap normal behavior", () => {
|
|||
return 3;
|
||||
}
|
||||
return target[property];
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(p.foo).toBe(1);
|
||||
|
@ -56,7 +56,10 @@ describe("[[Get]] invariants", () => {
|
|||
expect(p.foo).toBe(8);
|
||||
expect(() => {
|
||||
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", () => {
|
||||
|
@ -71,6 +74,9 @@ describe("[[Get]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
describe("[Call][GetOwnProperty]] trap normal behavior", () => {
|
||||
test("forwarding when not defined in handler", () => {
|
||||
expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a")).toBeUndefined();
|
||||
expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a")).toBeUndefined();
|
||||
expect(
|
||||
Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a")
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a")
|
||||
).toBeUndefined();
|
||||
expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -11,7 +15,7 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
|
|||
getOwnPropertyDescriptor(target, property) {
|
||||
expect(target).toBe(o);
|
||||
expect(property).toBe("foo");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.getOwnPropertyDescriptor(p, "foo");
|
||||
|
@ -19,14 +23,18 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
|
|||
|
||||
test("conditional returned descriptor", () => {
|
||||
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, {
|
||||
getOwnPropertyDescriptor(target, property) {
|
||||
if (property === "baz")
|
||||
return Object.getOwnPropertyDescriptor(target, "baz");
|
||||
if (property === "baz") return Object.getOwnPropertyDescriptor(target, "baz");
|
||||
return { value: target[property], enumerable: false, configurable: true, writable: true };
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(p).toHaveConfigurableProperty("baz");
|
||||
|
@ -50,12 +58,20 @@ describe("[Call][GetOwnProperty]] trap normal behavior", () => {
|
|||
describe("[[GetOwnProperty]] invariants", () => {
|
||||
test("must return an object or undefined", () => {
|
||||
expect(() => {
|
||||
Object.getOwnPropertyDescriptor(new Proxy({}, {
|
||||
Object.getOwnPropertyDescriptor(
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
getOwnPropertyDescriptor() {
|
||||
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", () => {
|
||||
|
@ -72,12 +88,20 @@ describe("[[GetOwnProperty]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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", () => {
|
||||
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);
|
||||
|
||||
let p = new Proxy(o, {
|
||||
|
@ -88,58 +112,101 @@ describe("[[GetOwnProperty]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, "v1", { value: 10, configurable: false });
|
||||
Object.defineProperty(o, "v2", { value: 10, configurable: false, enumerable: true });
|
||||
Object.defineProperty(o, "v3", { configurable: false, get() { return 1; } });
|
||||
Object.defineProperty(o, "v4", { value: 10, configurable: false, writable: false, enumerable: true });
|
||||
Object.defineProperty(o, "v3", {
|
||||
configurable: false,
|
||||
get() {
|
||||
return 1;
|
||||
},
|
||||
});
|
||||
Object.defineProperty(o, "v4", {
|
||||
value: 10,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
Object.getOwnPropertyDescriptor(new Proxy(o, {
|
||||
Object.getOwnPropertyDescriptor(
|
||||
new Proxy(o, {
|
||||
getOwnPropertyDescriptor() {
|
||||
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(() => {
|
||||
Object.getOwnPropertyDescriptor(new Proxy(o, {
|
||||
Object.getOwnPropertyDescriptor(
|
||||
new Proxy(o, {
|
||||
getOwnPropertyDescriptor() {
|
||||
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(() => {
|
||||
Object.getOwnPropertyDescriptor(new Proxy(o, {
|
||||
Object.getOwnPropertyDescriptor(
|
||||
new Proxy(o, {
|
||||
getOwnPropertyDescriptor() {
|
||||
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(() => {
|
||||
Object.getOwnPropertyDescriptor(new Proxy(o, {
|
||||
Object.getOwnPropertyDescriptor(
|
||||
new Proxy(o, {
|
||||
getOwnPropertyDescriptor() {
|
||||
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", () => {
|
||||
let o = {};
|
||||
Object.defineProperty(o, "v", { configurable: true });
|
||||
expect(() => {
|
||||
Object.getOwnPropertyDescriptor(new Proxy(o, {
|
||||
Object.getOwnPropertyDescriptor(
|
||||
new Proxy(o, {
|
||||
getOwnPropertyDescriptor() {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
|
|||
getPrototypeOf(target) {
|
||||
expect(target).toBe(o);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.getPrototypeOf(p);
|
||||
|
@ -28,14 +28,13 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
|
|||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
getPrototypeOf(target) {
|
||||
if (target.foo)
|
||||
return { bar: 1 };
|
||||
if (target.foo) return { bar: 1 };
|
||||
return { bar: 2 };
|
||||
},
|
||||
});
|
||||
|
||||
expect(Object.getPrototypeOf(p).bar).toBe(2);
|
||||
o.foo = 20
|
||||
o.foo = 20;
|
||||
expect(Object.getPrototypeOf(p).bar).toBe(1);
|
||||
});
|
||||
|
||||
|
@ -48,7 +47,7 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
|
|||
p = new Proxy(o, {
|
||||
getPrototypeOf() {
|
||||
return proto;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(Object.getPrototypeOf(p).foo).toBe("bar");
|
||||
|
@ -58,8 +57,20 @@ describe("[[GetPrototypeOf]] trap normal behavior", () => {
|
|||
describe("[[GetPrototypeOf]] invariants", () => {
|
||||
test("must return an object or null", () => {
|
||||
expect(() => {
|
||||
Object.getPrototypeOf(new Proxy({}, { getPrototypeOf() { return 1; } }));
|
||||
}).toThrowWithMessage(TypeError, "Proxy handler's getPrototypeOf trap violates invariant: must return an object or null");
|
||||
Object.getPrototypeOf(
|
||||
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", () => {
|
||||
|
@ -71,11 +82,14 @@ describe("[[GetPrototypeOf]] invariants", () => {
|
|||
let p = new Proxy(o, {
|
||||
getPrototypeOf(target) {
|
||||
return { baz: "qux" };
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ describe("[[Has]] trap normal behavior", () => {
|
|||
expect(target).toBe(o);
|
||||
expect(prop).toBe("foo");
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
"foo" in p;
|
||||
|
@ -22,12 +22,10 @@ describe("[[Has]] trap normal behavior", () => {
|
|||
let o = {};
|
||||
let p = new Proxy(o, {
|
||||
has(target, prop) {
|
||||
if (target.checkedFoo)
|
||||
return true;
|
||||
if (prop === "foo")
|
||||
target.checkedFoo = true;
|
||||
if (target.checkedFoo) return true;
|
||||
if (prop === "foo") target.checkedFoo = true;
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect("foo" in p).toBeFalse();
|
||||
|
@ -43,12 +41,15 @@ describe("[[Has]] invariants", () => {
|
|||
p = new Proxy(o, {
|
||||
has() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
"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", () => {
|
||||
|
@ -58,13 +59,16 @@ describe("[[Has]] invariants", () => {
|
|||
let p = new Proxy(o, {
|
||||
has() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.preventExtensions(o);
|
||||
|
||||
expect(() => {
|
||||
"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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ describe("[[IsExtensible]] trap normal behavior", () => {
|
|||
isExtensible(target) {
|
||||
expect(target).toBe(o);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(Object.isExtensible(p)).toBeTrue();
|
||||
|
@ -31,6 +31,9 @@ describe("[[Call]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ describe("[[PreventExtension]] trap normal behavior", () => {
|
|||
preventExtensions(target) {
|
||||
expect(target).toBe(o);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.preventExtensions(o);
|
||||
|
@ -24,11 +24,14 @@ describe("[[PreventExtension]] trap normal behavior", () => {
|
|||
|
||||
describe("[[PreventExtensions]] invariants", () => {
|
||||
test("cannot return false", () => {
|
||||
let p = new Proxy({}, {
|
||||
let p = new Proxy(
|
||||
{},
|
||||
{
|
||||
preventExtensions() {
|
||||
return false;
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
Object.preventExtensions(p);
|
||||
|
@ -45,7 +48,10 @@ describe("[[PreventExtensions]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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);
|
||||
expect(Object.preventExtensions(p)).toBe(p);
|
||||
|
|
|
@ -21,7 +21,9 @@ describe("[[Set]] trap normal behavior", () => {
|
|||
});
|
||||
|
||||
test("conditional return value", () => {
|
||||
let p = new Proxy({}, {
|
||||
let p = new Proxy(
|
||||
{},
|
||||
{
|
||||
set(target, prop, value) {
|
||||
if (target[prop] === value) {
|
||||
target[prop] *= 2;
|
||||
|
@ -29,7 +31,8 @@ describe("[[Set]] trap normal behavior", () => {
|
|||
target[prop] = value;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
p.foo = 10;
|
||||
expect(p.foo).toBe(10);
|
||||
|
@ -53,7 +56,10 @@ describe("[[Set]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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", () => {
|
||||
|
@ -68,6 +74,9 @@ describe("[[Set]] invariants", () => {
|
|||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ describe("[[SetPrototypeOf]] trap normal behavior", () => {
|
|||
expect(target).toBe(o);
|
||||
expect(newProto).toBe(theNewProto);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.setPrototypeOf(p, theNewProto);
|
||||
|
@ -32,8 +32,7 @@ describe("[[SetPrototypeOf]] trap normal behavior", () => {
|
|||
|
||||
let p = new Proxy(o, {
|
||||
setPrototypeOf(target, newProto) {
|
||||
if (target.shouldSet)
|
||||
Object.setPrototypeOf(target, newProto);
|
||||
if (target.shouldSet) Object.setPrototypeOf(target, newProto);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
@ -84,11 +83,14 @@ describe("[[SetPrototypeOf]] invariants", () => {
|
|||
let p = new Proxy(o, {
|
||||
setPrototypeOf() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,11 +17,17 @@ test("constructor argument count", () => {
|
|||
test("constructor requires objects", () => {
|
||||
expect(() => {
|
||||
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(() => {
|
||||
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'", () => {
|
||||
|
|
|
@ -23,7 +23,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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", () => {
|
||||
test("initial value and non-writable", () => {
|
||||
var o = {};
|
||||
|
@ -46,7 +48,9 @@ describe("normal behavior", () => {
|
|||
var o = {};
|
||||
|
||||
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(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
|
||||
expect(o.foo).toBe(2);
|
||||
|
@ -56,7 +60,9 @@ describe("normal behavior", () => {
|
|||
var o = {};
|
||||
|
||||
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(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
|
||||
expect(o.foo).toBe(2);
|
||||
|
@ -66,7 +72,9 @@ describe("normal behavior", () => {
|
|||
var o = {};
|
||||
|
||||
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(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse();
|
||||
expect(o.foo).toBe(1);
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -44,7 +44,7 @@ describe("normal behavior", () => {
|
|||
const foo = {
|
||||
get prop() {
|
||||
this.getPropCalled = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
const bar = {};
|
||||
Object.setPrototypeOf(bar, foo);
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -66,7 +66,7 @@ describe("normal behavior", () => {
|
|||
const foo = {
|
||||
set prop(value) {
|
||||
this.setPropCalled = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
expect(foo.setPropCalled).toBeUndefined();
|
||||
Reflect.set(foo, "prop", 42);
|
||||
|
@ -77,7 +77,7 @@ describe("normal behavior", () => {
|
|||
const foo = {
|
||||
set prop(value) {
|
||||
this.setPropCalled = true;
|
||||
}
|
||||
},
|
||||
};
|
||||
const bar = {};
|
||||
Object.setPrototypeOf(bar, foo);
|
||||
|
|
|
@ -7,7 +7,10 @@ describe("errors", () => {
|
|||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.charAt).toHaveLength(1);
|
||||
|
||||
var s = "foobar"
|
||||
var s = "foobar";
|
||||
expect(typeof s).toBe("string");
|
||||
expect(s).toHaveLength(6);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ test("basic functionality", () => {
|
|||
expect("".concat(false)).toBe("false");
|
||||
expect("".concat(true)).toBe("true");
|
||||
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, false)).toBe("truefalse");
|
||||
expect("".concat({})).toBe("[object Object]");
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.includes).toHaveLength(1);
|
||||
|
||||
expect("hello friends".includes("hello")).toBe(true);
|
||||
expect("hello friends".includes("hello", 100)).toBe(false);
|
||||
expect("hello friends".includes("hello", -10)).toBe(true);
|
||||
expect("hello friends".includes("friends", 6)).toBe(true);
|
||||
expect("hello friends".includes("hello", 6)).toBe(false);
|
||||
expect("hello friends false".includes(false)).toBe(true);
|
||||
expect("hello 10 friends".includes(10)).toBe(true);
|
||||
expect("hello friends undefined".includes()).toBe(true);
|
||||
expect("hello friends".includes("hello")).toBeTrue();
|
||||
expect("hello friends".includes("hello", 100)).toBeFalse();
|
||||
expect("hello friends".includes("hello", -10)).toBeTrue();
|
||||
expect("hello friends".includes("friends", 6)).toBeTrue();
|
||||
expect("hello friends".includes("hello", 6)).toBeFalse();
|
||||
expect("hello friends false".includes(false)).toBeTrue();
|
||||
expect("hello 10 friends".includes(10)).toBeTrue();
|
||||
expect("hello friends undefined".includes()).toBeTrue();
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.indexOf).toHaveLength(1);
|
||||
|
||||
var s = "hello friends"
|
||||
var s = "hello friends";
|
||||
|
||||
expect(s.indexOf("friends")).toBe(6);
|
||||
expect(s.indexOf("enemies")).toBe(-1);
|
||||
|
|
|
@ -15,4 +15,3 @@ test("basic functionality", () => {
|
|||
expect("hello friends".slice(1000)).toBe("");
|
||||
expect("hello friends".slice(-1000)).toBe("hello friends");
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ test("basic functionality", () => {
|
|||
expect("hello friends".substring(1)).toBe("ello friends");
|
||||
expect("hello friends".substring(0, 5)).toBe("hello");
|
||||
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(-1, 13)).toBe("hello friends");
|
||||
expect("hello friends".substring(0, 50)).toBe("hello friends");
|
||||
|
|
|
@ -5,5 +5,5 @@ test("basic functionality", () => {
|
|||
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");
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
test("basic functionality", () => {
|
||||
expect(String.prototype.toString).toHaveLength(0)
|
||||
expect(String.prototype.toString).toHaveLength(0);
|
||||
|
||||
expect("".toString()).toBe("");
|
||||
expect("hello friends".toString()).toBe("hello friends");
|
||||
|
|
|
@ -5,5 +5,5 @@ test("basic functionality", () => {
|
|||
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");
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
load("test-common.js")
|
||||
load("test-common.js");
|
||||
|
||||
try {
|
||||
const localSym = Symbol("foo");
|
||||
|
@ -17,12 +17,15 @@ try {
|
|||
assert(Symbol.for().description === "undefined");
|
||||
assert(Symbol.for(null).description === "null");
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol.for(Symbol());
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to string",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
load("test-common.js")
|
||||
load("test-common.js");
|
||||
|
||||
try {
|
||||
const s1 = Symbol("foo");
|
||||
|
@ -13,12 +13,15 @@ try {
|
|||
|
||||
assert(typeof s1 === "symbol");
|
||||
|
||||
assertThrowsError(() => {
|
||||
Symbol(Symbol('foo'));
|
||||
}, {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol(Symbol("foo"));
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to string"
|
||||
})
|
||||
message: "Cannot convert symbol to string",
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
load("test-common.js")
|
||||
load("test-common.js");
|
||||
|
||||
try {
|
||||
const localSym = Symbol("foo");
|
||||
|
@ -8,12 +8,15 @@ try {
|
|||
assert(Symbol.keyFor(globalSym) === "foo");
|
||||
|
||||
const testThrows = (value, str) => {
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol.keyFor(value);
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: str + " is not a symbol",
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
testThrows(1, "1");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
load("test-common.js")
|
||||
load("test-common.js");
|
||||
|
||||
try {
|
||||
const s1 = Symbol("foo");
|
||||
|
@ -7,19 +7,25 @@ try {
|
|||
assert(s1.toString() === "Symbol(foo)");
|
||||
assert(s2.toString() === "Symbol(bar)");
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
s1 + "";
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to string",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
s1 + 1;
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Cannot convert symbol to number",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
let local = Symbol('foo');
|
||||
let global = Symbol.for('foo');
|
||||
let local = Symbol("foo");
|
||||
let global = Symbol.for("foo");
|
||||
assert(local.valueOf() === local);
|
||||
assert(global.valueOf() === global);
|
||||
|
||||
assert(Symbol.prototype.valueOf.call(local) === local);
|
||||
assert(Symbol.prototype.valueOf.call(global) === global);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
Symbol.prototype.valueOf.call("foo");
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Not a Symbol object",
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (err) {
|
||||
|
|
|
@ -2,11 +2,11 @@ test("parsing numbers", () => {
|
|||
[
|
||||
[0, 0],
|
||||
[1, 1],
|
||||
[.23, 0.23],
|
||||
[0.23, 0.23],
|
||||
[1.23, 1.23],
|
||||
[0.0123E+2, 1.23],
|
||||
[0.0123e2, 1.23],
|
||||
[1.23e4, 12300],
|
||||
[Infinity, Infinity]
|
||||
[Infinity, Infinity],
|
||||
].forEach(test => {
|
||||
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],
|
||||
["0.0123E+2", 1.23],
|
||||
["1.23e4", 12300],
|
||||
["Infinity", Infinity]
|
||||
["Infinity", Infinity],
|
||||
].forEach(test => {
|
||||
expect(parseFloat(test[0])).toBe(test[1]);
|
||||
expect(parseFloat(`+${test[0]}`)).toBe(test[1]);
|
||||
|
@ -49,7 +49,7 @@ test("parsing NaN", () => {
|
|||
"foo123",
|
||||
"foo+123",
|
||||
"fooInfinity",
|
||||
"foo+Infinity"
|
||||
"foo+Infinity",
|
||||
].forEach(value => {
|
||||
expect(parseFloat(value)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@ try {
|
|||
}
|
||||
|
||||
class Baz {
|
||||
"constructor"() {
|
||||
constructor() {
|
||||
this.foo = 55;
|
||||
this._bar = 33;
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ try {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
let barPropertyDescriptor = Object.getOwnPropertyDescriptor(Baz.prototype, "bar");
|
||||
assert(barPropertyDescriptor.get.name === "get bar");
|
||||
assert(barPropertyDescriptor.set.name === "set bar");
|
||||
|
@ -91,7 +90,9 @@ try {
|
|||
|
||||
assert(new Bar().x === 5);
|
||||
|
||||
class ExtendsFunction extends function () { this.foo = 22; } { }
|
||||
class ExtendsFunction extends function () {
|
||||
this.foo = 22;
|
||||
} {}
|
||||
assert(new ExtendsFunction().foo === 22);
|
||||
|
||||
class ExtendsString extends String {}
|
||||
|
@ -104,18 +105,25 @@ try {
|
|||
return "#" + super.charAt(i);
|
||||
}
|
||||
}
|
||||
assert(new MyWeirdString("abc").charAt(1) === "#b")
|
||||
assert(new MyWeirdString("abc").charAt(1) === "#b");
|
||||
|
||||
class ExtendsNull extends null {}
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new ExtendsNull();
|
||||
}, {
|
||||
error: ReferenceError
|
||||
});
|
||||
},
|
||||
{
|
||||
error: ReferenceError,
|
||||
}
|
||||
);
|
||||
assert(Object.getPrototypeOf(ExtendsNull.prototype) === null);
|
||||
|
||||
class ExtendsClassExpression extends class { constructor(x) { this.x = x; } } {
|
||||
class ExtendsClassExpression extends class {
|
||||
constructor(x) {
|
||||
this.x = x;
|
||||
}
|
||||
} {
|
||||
constructor(y) {
|
||||
super(5);
|
||||
this.y = 6;
|
||||
|
@ -191,22 +199,29 @@ try {
|
|||
}
|
||||
`);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class BadExtends extends 3 {}
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
}
|
||||
);
|
||||
|
||||
}, {
|
||||
error: TypeError
|
||||
});
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class BadExtends extends undefined {}
|
||||
}, {
|
||||
error: TypeError
|
||||
});
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
}
|
||||
);
|
||||
|
||||
class SuperNotASyntaxError {
|
||||
bar() {
|
||||
() => { super.baz };
|
||||
() => {
|
||||
super.baz;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +231,8 @@ try {
|
|||
}
|
||||
}
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class Base {}
|
||||
class DerivedDoesntCallSuper extends Base {
|
||||
constructor() {
|
||||
|
@ -225,10 +241,13 @@ try {
|
|||
}
|
||||
|
||||
new DerivedDoesntCallSuper();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: ReferenceError,
|
||||
});
|
||||
assertThrowsError(() => {
|
||||
}
|
||||
);
|
||||
assertThrowsError(
|
||||
() => {
|
||||
class Base {}
|
||||
class CallsSuperTwice extends Base {
|
||||
constructor() {
|
||||
|
@ -238,9 +257,11 @@ try {
|
|||
}
|
||||
|
||||
new CallsSuperTwice();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: ReferenceError,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
test("regular comments", () => {
|
||||
const source =
|
||||
`var i = 0;
|
||||
const source = `var i = 0;
|
||||
|
||||
// i++;
|
||||
/* i++; */
|
||||
|
@ -13,13 +12,12 @@ return i;`;
|
|||
});
|
||||
|
||||
test("html comments", () => {
|
||||
const source =
|
||||
`var i = 0;
|
||||
const source = `var i = 0;
|
||||
<!-- i++; --> i++;
|
||||
<!-- i++;
|
||||
i++;
|
||||
--> i++;
|
||||
return i;`
|
||||
return i;`;
|
||||
|
||||
expect(source).toEvalTo(1);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ test("regular exponentiation", () => {
|
|||
expect(2 ** 3).toBe(8);
|
||||
expect(3 ** 2).toBe(9);
|
||||
expect(0 ** 0).toBe(1);
|
||||
expect(2 ** 3 ** 2).toBe(512);
|
||||
expect(2 ** (3 ** 2)).toBe(512);
|
||||
expect(2 ** (3 ** 2)).toBe(512);
|
||||
expect((2 ** 3) ** 2).toBe(64);
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ test("exponentation with non-numeric primitives", () => {
|
|||
expect([] ** null).toBe(1);
|
||||
expect(null ** null).toBe(1);
|
||||
expect(undefined ** null).toBe(1);
|
||||
})
|
||||
});
|
||||
|
||||
test("exponentation that produces NaN", () => {
|
||||
expect(NaN ** 2).toBeNaN();
|
||||
|
|
|
@ -16,7 +16,7 @@ try {
|
|||
};
|
||||
assert(addBlock(5, 4) === 9);
|
||||
|
||||
let chompy = [(x) => x, 2];
|
||||
let chompy = [x => x, 2];
|
||||
assert(chompy.length === 2);
|
||||
assert(chompy[0](1) === 1);
|
||||
|
||||
|
@ -60,7 +60,7 @@ try {
|
|||
assert(half === 5);
|
||||
|
||||
var foo, bar;
|
||||
foo = bar, baz => {};
|
||||
(foo = bar), baz => {};
|
||||
assert(foo === undefined);
|
||||
assert(bar === undefined);
|
||||
|
||||
|
@ -69,7 +69,7 @@ try {
|
|||
y: () => this,
|
||||
z: function () {
|
||||
return (() => this)();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -81,12 +81,15 @@ try {
|
|||
|
||||
assert(Baz.prototype === undefined);
|
||||
|
||||
assertThrowsError(() => {
|
||||
assertThrowsError(
|
||||
() => {
|
||||
new Baz();
|
||||
}, {
|
||||
},
|
||||
{
|
||||
error: TypeError,
|
||||
message: "Baz is not a constructor"
|
||||
});
|
||||
message: "Baz is not a constructor",
|
||||
}
|
||||
);
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
|
@ -98,7 +101,7 @@ try {
|
|||
})();
|
||||
|
||||
(() => {
|
||||
'use strict';
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
})();
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue