js/src/jit-test/tests/basic/spread-call.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 + "eqArrayHelper.js");
michael@0 3 load(libdir + "iteration.js");
michael@0 4
michael@0 5 let makeCall = farg => Function("f", "arg", "return f(" + farg + ");");
michael@0 6 let makeFunCall = farg => Function("f", "arg", "return f.call(null, " + farg + ");");
michael@0 7 let makeNew = farg => Function("f", "arg", "return new f(" + farg + ").value;");
michael@0 8
michael@0 9 function checkCommon(f, makeFn) {
michael@0 10 assertEqArray(makeFn("...[1, 2, 3]")(f), [1, 2, 3]);
michael@0 11 assertEqArray(makeFn("1, ...[2], 3")(f), [1, 2, 3]);
michael@0 12 assertEqArray(makeFn("1, ...[2], ...[3]")(f), [1, 2, 3]);
michael@0 13 assertEqArray(makeFn("1, ...[2, 3]")(f), [1, 2, 3]);
michael@0 14 assertEqArray(makeFn("1, ...[], 2, 3")(f), [1, 2, 3]);
michael@0 15
michael@0 16 // other iterable objects
michael@0 17 assertEqArray(makeFn("...arg")(f, new Int32Array([1, 2, 3])), [1, 2, 3]);
michael@0 18 assertEqArray(makeFn("...arg")(f, "abc"), ["a", "b", "c"]);
michael@0 19 assertEqArray(makeFn("...arg")(f, [1, 2, 3][std_iterator]()), [1, 2, 3]);
michael@0 20 assertEqArray(makeFn("...arg")(f, Set([1, 2, 3])), [1, 2, 3]);
michael@0 21 assertEqArray(makeFn("...arg")(f, Map([["a", "A"], ["b", "B"], ["c", "C"]])).map(([k, v]) => k + v), ["aA", "bB", "cC"]);
michael@0 22 let itr = {};
michael@0 23 itr[std_iterator] = function() {
michael@0 24 return {
michael@0 25 i: 1,
michael@0 26 next: function() {
michael@0 27 if (this.i < 4)
michael@0 28 return { value: this.i++, done: false };
michael@0 29 else
michael@0 30 return { value: undefined, done: true };
michael@0 31 }
michael@0 32 };
michael@0 33 };
michael@0 34 assertEqArray(makeFn("...arg")(f, itr), [1, 2, 3]);
michael@0 35 function gen() {
michael@0 36 for (let i = 1; i < 4; i ++)
michael@0 37 yield i;
michael@0 38 }
michael@0 39 assertEqArray(makeFn("...arg")(f, gen()), [1, 2, 3]);
michael@0 40
michael@0 41 assertEqArray(makeFn("...arg=[1, 2, 3]")(f), [1, 2, 3]);
michael@0 42
michael@0 43 // According to the draft spec, null and undefined are to be treated as empty
michael@0 44 // arrays. However, they are not iterable. If the spec is not changed to be in
michael@0 45 // terms of iterables, these tests should be fixed.
michael@0 46 //assertEqArray(makeFn(1, ...null, 2, 3)(f), [1, 2, 3]);
michael@0 47 //assertEqArray(makeFn(1, ...undefined, 2, 3)(f), [1, 2, 3]);
michael@0 48 assertThrowsInstanceOf(makeFn("1, ...null, 2, 3"), TypeError);
michael@0 49 assertThrowsInstanceOf(makeFn("1, ...undefined, 2, 3"), TypeError);
michael@0 50 }
michael@0 51
michael@0 52 function checkNormal(f, makeFn) {
michael@0 53 checkCommon(f, makeFn);
michael@0 54
michael@0 55 assertEqArray(makeFn("...[]")(f), [undefined, undefined, undefined]);
michael@0 56 assertEqArray(makeFn("...[1]")(f), [1, undefined, undefined]);
michael@0 57 assertEqArray(makeFn("...[1, 2]")(f), [1, 2, undefined]);
michael@0 58 assertEqArray(makeFn("...[1, 2, 3, 4]")(f), [1, 2, 3]);
michael@0 59
michael@0 60 assertEqArray(makeFn("...[undefined]")(f), [undefined, undefined, undefined]);
michael@0 61 }
michael@0 62
michael@0 63 checkNormal(function(a, b, c) [a, b, c], makeCall);
michael@0 64 checkNormal(function(a, b, c) [a, b, c], makeFunCall);
michael@0 65 checkNormal((a, b, c) => [a, b, c], makeCall);
michael@0 66 checkNormal((a, b, c) => [a, b, c], makeFunCall);
michael@0 67 function normalClass(a, b, c) {
michael@0 68 this.value = [a, b, c];
michael@0 69 assertEq(Object.getPrototypeOf(this), normalClass.prototype);
michael@0 70 }
michael@0 71 checkNormal(normalClass, makeNew);
michael@0 72
michael@0 73 function checkDefault(f, makeFn) {
michael@0 74 checkCommon(f, makeFn);
michael@0 75
michael@0 76 assertEqArray(makeFn("...[]")(f), [-1, -2, -3]);
michael@0 77 assertEqArray(makeFn("...[1]")(f), [1, -2, -3]);
michael@0 78 assertEqArray(makeFn("...[1, 2]")(f), [1, 2, -3]);
michael@0 79 assertEqArray(makeFn("...[1, 2, 3, 4]")(f), [1, 2, 3]);
michael@0 80
michael@0 81 assertEqArray(makeFn("...[undefined]")(f), [-1, -2, -3]);
michael@0 82 }
michael@0 83
michael@0 84 checkDefault(function(a = -1, b = -2, c = -3) [a, b, c], makeCall);
michael@0 85 checkDefault(function(a = -1, b = -2, c = -3) [a, b, c], makeFunCall);
michael@0 86 checkDefault((a = -1, b = -2, c = -3) => [a, b, c], makeCall);
michael@0 87 checkDefault((a = -1, b = -2, c = -3) => [a, b, c], makeFunCall);
michael@0 88 function defaultClass(a = -1, b = -2, c = -3) {
michael@0 89 this.value = [a, b, c];
michael@0 90 assertEq(Object.getPrototypeOf(this), defaultClass.prototype);
michael@0 91 }
michael@0 92 checkDefault(defaultClass, makeNew);
michael@0 93
michael@0 94 function checkRest(f, makeFn) {
michael@0 95 checkCommon(f, makeFn);
michael@0 96
michael@0 97 assertEqArray(makeFn("...[]")(f), []);
michael@0 98 assertEqArray(makeFn("1, ...[2, 3, 4], 5")(f), [1, 2, 3, 4, 5]);
michael@0 99 assertEqArray(makeFn("1, ...[], 2")(f), [1, 2]);
michael@0 100 assertEqArray(makeFn("1, ...[2, 3], 4, ...[5, 6]")(f), [1, 2, 3, 4, 5, 6]);
michael@0 101
michael@0 102 assertEqArray(makeFn("...[undefined]")(f), [undefined]);
michael@0 103 }
michael@0 104
michael@0 105 checkRest(function(...x) x, makeCall);
michael@0 106 checkRest(function(...x) x, makeFunCall);
michael@0 107 checkRest((...x) => x, makeCall);
michael@0 108 checkRest((...x) => x, makeFunCall);
michael@0 109 function restClass(...x) {
michael@0 110 this.value = x;
michael@0 111 assertEq(Object.getPrototypeOf(this), restClass.prototype);
michael@0 112 }
michael@0 113 checkRest(restClass, makeNew);

mercurial