js/src/jit-test/tests/basic/spread-array.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 load(libdir + "asserts.js");
michael@0 2 load(libdir + "iteration.js");
michael@0 3 load(libdir + "eqArrayHelper.js");
michael@0 4
michael@0 5 assertEqArray([...[1, 2, 3]], [1, 2, 3]);
michael@0 6 assertEqArray([1, ...[2, 3, 4], 5], [1, 2, 3, 4, 5]);
michael@0 7 assertEqArray([1, ...[], 2], [1, 2]);
michael@0 8 assertEqArray([1, ...[2, 3], 4, ...[5, 6]], [1, 2, 3, 4, 5, 6]);
michael@0 9 assertEqArray([1, ...[], 2], [1, 2]);
michael@0 10 assertEqArray([1,, ...[2]], [1,, 2]);
michael@0 11 assertEqArray([1,, ...[2],, 3,, 4,], [1,, 2,, 3,, 4,]);
michael@0 12 assertEqArray([...[1, 2, 3],,,,], [1, 2, 3,,,,]);
michael@0 13 assertEqArray([,,...[1, 2, 3],,,,], [,,1,2,3,,,,]);
michael@0 14
michael@0 15 assertEqArray([...[undefined]], [undefined]);
michael@0 16
michael@0 17 // other iterable objects
michael@0 18 assertEqArray([...new Int32Array([1, 2, 3])], [1, 2, 3]);
michael@0 19 assertEqArray([..."abc"], ["a", "b", "c"]);
michael@0 20 assertEqArray([...[1, 2, 3][std_iterator]()], [1, 2, 3]);
michael@0 21 assertEqArray([...Set([1, 2, 3])], [1, 2, 3]);
michael@0 22 assertEqArray([...Map([["a", "A"], ["b", "B"], ["c", "C"]])].map(([k, v]) => k + v), ["aA", "bB", "cC"]);
michael@0 23 let itr = {};
michael@0 24 itr[std_iterator] = function () {
michael@0 25 return {
michael@0 26 i: 1,
michael@0 27 next: function() {
michael@0 28 if (this.i < 4)
michael@0 29 return { value: this.i++, done: false };
michael@0 30 else
michael@0 31 return { value: undefined, done: true };
michael@0 32 }
michael@0 33 };
michael@0 34 }
michael@0 35 assertEqArray([...itr], [1, 2, 3]);
michael@0 36 function* gen() {
michael@0 37 for (let i = 1; i < 4; i ++)
michael@0 38 yield i;
michael@0 39 }
michael@0 40 assertEqArray([...gen()], [1, 2, 3]);
michael@0 41
michael@0 42 let a, b = [1, 2, 3];
michael@0 43 assertEqArray([...a=b], [1, 2, 3]);
michael@0 44
michael@0 45 // According to the draft spec, null and undefined are to be treated as empty
michael@0 46 // arrays. However, they are not iterable. If the spec is not changed to be in
michael@0 47 // terms of iterables, these tests should be fixed.
michael@0 48 //assertEqArray([1, ...null, 2], [1, 2]);
michael@0 49 //assertEqArray([1, ...undefined, 2], [1, 2]);
michael@0 50 assertThrowsInstanceOf(() => [...null], TypeError);
michael@0 51 assertThrowsInstanceOf(() => [...undefined], TypeError);
michael@0 52

mercurial