js/src/tests/ecma_6/Array/for_of_2.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 // Test corner cases of for-of iteration over Arrays.
michael@0 2 // The current spidermonky JSOP_SPREAD implementation for function calls
michael@0 3 // with '...rest' arguments uses a ForOfIterator to extract values from
michael@0 4 // the array, so we use that mechanism to test ForOfIterator here.
michael@0 5
michael@0 6 //
michael@0 7 // Check case where ArrayIterator.prototype.next changes in the middle of iteration.
michael@0 8 //
michael@0 9 function TestChangeArrayIteratorNext() {
michael@0 10 function doIter(f, arr) {
michael@0 11 return f(...arr)
michael@0 12 }
michael@0 13
michael@0 14 function fun(a, b, c) {
michael@0 15 var result = 0;
michael@0 16 for (var i = 0; i < arguments.length; i++)
michael@0 17 result += arguments[i];
michael@0 18 return result;
michael@0 19 }
michael@0 20
michael@0 21 var GET_COUNT = 0;
michael@0 22 function getter() {
michael@0 23 GET_COUNT++;
michael@0 24 if (GET_COUNT == MID)
michael@0 25 iterProto.next = NewNext;
michael@0 26 return M2;
michael@0 27 }
michael@0 28
michael@0 29 var iter = ([])['@@iterator']();
michael@0 30 var iterProto = Object.getPrototypeOf(iter);
michael@0 31 var OldNext = iterProto.next;
michael@0 32 var NewNext = function () {
michael@0 33 return OldNext.apply(this, arguments);
michael@0 34 };
michael@0 35
michael@0 36 var TRUE_SUM = 0;
michael@0 37 var N = 100;
michael@0 38 var MID = N/2;
michael@0 39 var M = 3;
michael@0 40 var arr = new Array(M);
michael@0 41 var ARR_SUM = 0;
michael@0 42 for (var j = 0; j < M; j++) {
michael@0 43 arr[j] = j;
michael@0 44 ARR_SUM += j;
michael@0 45 }
michael@0 46 var M2 = (M/2)|0;
michael@0 47 Object.defineProperty(arr, M2, {'get':getter});
michael@0 48
michael@0 49 var sum = 0;
michael@0 50 for (var i = 0; i < N; i++) {
michael@0 51 sum += doIter(fun, arr);
michael@0 52 TRUE_SUM += ARR_SUM;
michael@0 53 }
michael@0 54 assertEq(sum, TRUE_SUM);
michael@0 55 }
michael@0 56 TestChangeArrayIteratorNext();
michael@0 57
michael@0 58 if (typeof reportCompare === "function")
michael@0 59 reportCompare(true, true);

mercurial