js/src/tests/js1_7/extensions/basic-for-each.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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 //-----------------------------------------------------------------------------
     7 var BUGNUMBER     = "346582";
     8 var summary = "Basic support for iterable objects and for-each";
     9 var actual, expect;
    11 printBugNumber(BUGNUMBER);
    12 printStatus(summary);
    14 /**************
    15  * BEGIN TEST *
    16  **************/
    18 var failed = false;
    20 var iterable = { persistedProp: 17 };
    22 function Array_equals(a, b)
    23 {
    24   if (!(a instanceof Array) || !(b instanceof Array))
    25     throw new Error("Arguments not both of type Array");
    26   if (a.length != b.length)
    27     return false;
    28   for (var i = 0, sz = a.length; i < sz; i++)
    29     if (a[i] !== b[i])
    30       return false;
    31   return true;
    32 }
    34 try
    35 {
    36   // nothing unusual so far -- verify basic properties
    37   for (var i in iterable)
    38   {
    39     if (i != "persistedProp")
    40       throw "no persistedProp!";
    41     if (iterable[i] != 17)
    42       throw "iterable[\"persistedProp\"] == 17";
    43   }
    45   var keys = ["foo", "bar", "baz"];
    46   var vals = [6, 5, 14];
    48   iterable.__iterator__ =
    49     function(keysOnly)
    50     {
    51       var gen =
    52       function()
    53       {
    54 	for (var i = 0; i < keys.length; i++)
    55 	{
    56 	  if (keysOnly)
    57 	    yield keys[i];
    58 	  else
    59 	    yield [keys[i], vals[i]];
    60 	}
    61       };
    62       return gen();
    63     };
    65   // for each sets keysOnly==false
    66   var index = 0;
    67   for each (var v in iterable)
    68   {
    69     if (!Array_equals(v, [keys[index], vals[index]]))
    70       throw "for-each iteration failed on index=" + index + "!";
    71     index++;
    72   }
    73   if (index != keys.length)
    74     throw "not everything iterated!  index=" + index +
    75       ", keys.length=" + keys.length;
    77   if (iterable.persistedProp != 17)
    78     throw "iterable.persistedProp not persisted!";
    79 }
    80 catch (e)
    81 {
    82   failed = e;
    83 }
    87 expect = false;
    88 actual = failed;
    90 reportCompare(expect, actual, summary);

mercurial