1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibJS: Support spreading of strings and string objects

This commit is contained in:
Linus Groh 2020-04-27 14:01:04 +01:00 committed by Andreas Kling
parent bcd5e97286
commit 30fe1b5d58
3 changed files with 60 additions and 19 deletions

View file

@ -0,0 +1,31 @@
load("test-common.js");
function testArray(arr) {
return arr.length === 4 &&
arr[0] === "a" &&
arr[1] === "b" &&
arr[2] === "c" &&
arr[3] === "d";
}
try {
var arr;
arr = ["a", ..."bc", "d"];
assert(testArray(arr));
let s = "bc";
arr = ["a", ...s, "d"];
assert(testArray(arr));
let obj = { a: "bc" };
arr = ["a", ...obj.a, "d"];
assert(testArray(arr));
arr = [..."", ...[...new String("abc")], "d"];
assert(testArray(arr));
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}