js/src/tests/ecma_2/Statements/forin-001.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/. */
     7 /**
     8  *  File Name:          forin-001.js
     9  *  ECMA Section:
    10  *  Description:        The forin-001 statement
    11  *
    12  *  Verify that the property name is assigned to the property on the left
    13  *  hand side of the for...in expression.
    14  *
    15  *  Author:             christine@netscape.com
    16  *  Date:               28 August 1998
    17  */
    18 var SECTION = "forin-001";
    19 var VERSION = "ECMA_2";
    20 var TITLE   = "The for...in  statement";
    21 var BUGNUMBER="330890";
    22 var BUGNUMBER="http://scopus.mcom.com/bugsplat/show_bug.cgi?id=344855";
    24 startTest();
    25 writeHeaderToLog( SECTION + " "+ TITLE);
    27 ForIn_1( { length:4, company:"netscape", year:2000, 0:"zero" } );
    28 ForIn_2( { length:4, company:"netscape", year:2000, 0:"zero" } );
    29 ForIn_3( { length:4, company:"netscape", year:2000, 0:"zero" } );
    31 //    ForIn_6({ length:4, company:"netscape", year:2000, 0:"zero" });
    32 //    ForIn_7({ length:4, company:"netscape", year:2000, 0:"zero" });
    33 ForIn_8({ length:4, company:"netscape", year:2000, 0:"zero" });
    35 test();
    37 /**
    38  *  Verify that the left side argument is evaluated with every iteration.
    39  *  Verify that the name of each property of the object is assigned to a
    40  *  a property.
    41  *
    42  */
    43 function ForIn_1( object ) {
    44   PropertyArray = new Array();
    45   ValueArray = new Array();
    47   for ( PropertyArray[PropertyArray.length] in object ) {
    48     ValueArray[ValueArray.length] =
    49       object[PropertyArray[PropertyArray.length-1]];
    50   }
    52   for ( var i = 0; i < PropertyArray.length; i++ ) {
    53     new TestCase(
    54       SECTION,
    55       "object[" + PropertyArray[i] +"]",
    56       object[PropertyArray[i]],
    57       ValueArray[i]
    58       );
    59   }
    61   new TestCase(
    62     SECTION,
    63     "object.length",
    64     PropertyArray.length,
    65     object.length );
    66 }
    68 /**
    69  *  Similar to ForIn_1, except it should increment the counter variable
    70  *  every time the left hand expression is evaluated.
    71  */
    72 function ForIn_2( object ) {
    73   PropertyArray = new Array();
    74   ValueArray = new Array();
    75   var i = 0;
    77   for ( PropertyArray[i++] in object ) {
    78     ValueArray[ValueArray.length] =
    79       object[PropertyArray[PropertyArray.length-1]];
    80   }
    82   for ( i = 0; i < PropertyArray.length; i++ ) {
    83     new TestCase(
    84       SECTION,
    85       "object[" + PropertyArray[i] +"]",
    86       object[PropertyArray[i]],
    87       ValueArray[i]
    88       );
    89   }
    91   new TestCase(
    92     SECTION,
    93     "object.length",
    94     PropertyArray.length,
    95     object.length );
    96 }
    98 /**
    99  *  Break out of a for...in loop
   100  *
   101  *
   102  */
   103 function ForIn_3( object ) {
   104   var checkBreak = "pass";
   105   var properties = new Array();
   106   var values = new Array();
   108   for ( properties[properties.length] in object ) {
   109     values[values.length] = object[properties[properties.length-1]];
   110     break;
   111     checkBreak = "fail";
   112   }
   114   new TestCase(
   115     SECTION,
   116     "check break out of for...in",
   117     "pass",
   118     checkBreak );
   120   new TestCase(
   121     SECTION,
   122     "properties.length",
   123     1,
   124     properties.length );
   126   new TestCase(
   127     SECTION,
   128     "object["+properties[0]+"]",
   129     values[0],
   130     object[properties[0]] );
   131 }
   133 /**
   134  *  Break out of a labeled for...in loop.
   135  */
   136 function ForIn_4( object ) {
   137   var result1 = 0;
   138   var result2 = 0;
   139   var result3 = 0;
   140   var result4 = 0;
   141   var i = 0;
   142   var property = new Array();
   144 butterbean: {
   145     result1++;
   147     for ( property[i++] in object ) {
   148       result2++;
   149       break;
   150       result4++;
   151     }
   152     result3++;
   153   }
   155   new TestCase(
   156     SECTION,
   157     "verify labeled statement is only executed once",
   158     true,
   159     result1 == 1 );
   161   new TestCase(
   162     SECTION,
   163     "verify statements in for loop are evaluated",
   164     true,
   165     result2 == i );
   167   new TestCase(
   168     SECTION,
   169     "verify break out of labeled for...in loop",
   170     true,
   171     result4 == 0 );
   173   new TestCase(
   174     SECTION,
   175     "verify break out of labeled block",
   176     true,
   177     result3 == 0 );
   178 }
   180 /**
   181  *  Labeled break out of a labeled for...in loop.
   182  */
   183 function ForIn_5 (object) {
   184   var result1 = 0;
   185   var result2 = 0;
   186   var result3 = 0;
   187   var result4 = 0;
   188   var i = 0;
   189   var property = new Array();
   191 bigredbird: {
   192     result1++;
   193     for ( property[i++] in object ) {
   194       result2++;
   195       break bigredbird;
   196       result4++;
   197     }
   198     result3++;
   199   }
   201   new TestCase(
   202     SECTION,
   203     "verify labeled statement is only executed once",
   204     true,
   205     result1 == 1 );
   207   new TestCase(
   208     SECTION,
   209     "verify statements in for loop are evaluated",
   210     true,
   211     result2 == i );
   213   new TestCase(
   214     SECTION,
   215     "verify break out of labeled for...in loop",
   216     true,
   217     result4 == 0 );
   219   new TestCase(
   220     SECTION,
   221     "verify break out of labeled block",
   222     true,
   223     result3 == 0 );
   224 }
   226 /**
   227  *  Labeled continue from a labeled for...in loop
   228  */
   229 function ForIn_7( object ) {
   230   var result1 = 0;
   231   var result2 = 0;
   232   var result3 = 0;
   233   var result4 = 0;
   234   var i = 0;
   235   var property = new Array();
   237 bigredbird:
   238   for ( property[i++] in object ) {
   239     result2++;
   240     continue bigredbird;
   241     result4++;
   242   }
   244   new TestCase(
   245     SECTION,
   246     "verify statements in for loop are evaluated",
   247     true,
   248     result2 == i );
   250   new TestCase(
   251     SECTION,
   252     "verify break out of labeled for...in loop",
   253     true,
   254     result4 == 0 );
   256   new TestCase(
   257     SECTION,
   258     "verify break out of labeled block",
   259     true,
   260     result3 == 1 );
   261 }
   264 /**
   265  *  continue in a for...in loop
   266  *
   267  */
   268 function ForIn_8( object ) {
   269   var checkBreak = "pass";
   270   var properties = new Array();
   271   var values = new Array();
   273   for ( properties[properties.length] in object ) {
   274     values[values.length] = object[properties[properties.length-1]];
   275     break;
   276     checkBreak = "fail";
   277   }
   279   new TestCase(
   280     SECTION,
   281     "check break out of for...in",
   282     "pass",
   283     checkBreak );
   285   new TestCase(
   286     SECTION,
   287     "properties.length",
   288     1,
   289     properties.length );
   291   new TestCase(
   292     SECTION,
   293     "object["+properties[0]+"]",
   294     values[0],
   295     object[properties[0]] );
   296 }

mercurial