js/src/tests/ecma/Array/15.4.1.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.

     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:          15.4.1.2.js
     9    ECMA Section:       15.4.1.2 Array(len)
    11    Description:        When Array is called as a function rather than as a
    12    constructor, it creates and initializes a new array
    13    object.  Thus, the function call Array(...) is
    14    equivalent to the object creationi new Array(...) with
    15    the same arguments.
    17    An array is created and returned as if by the
    18    expression new Array(len).
    20    Author:             christine@netscape.com
    21    Date:               7 october 1997
    22 */
    23 var SECTION = "15.4.1.2";
    24 var VERSION = "ECMA_1";
    25 startTest();
    26 var TITLE   = "Array Constructor Called as a Function:  Array(len)";
    28 writeHeaderToLog( SECTION + " "+ TITLE);
    30 new TestCase( SECTION, 
    31 	      "(Array()).length",            
    32 	      0,                             
    33 	      (Array()).length );
    35 new TestCase( SECTION,
    36 	      "(Array(0)).length",           
    37 	      0,                             
    38 	      (Array(0)).length );
    40 new TestCase( SECTION,
    41 	      "(Array(1)).length",           
    42 	      1,                             
    43 	      (Array(1)).length );
    45 new TestCase( SECTION,
    46 	      "(Array(10)).length",          
    47 	      10,                            
    48 	      (Array(10)).length );
    50 new TestCase( SECTION,
    51 	      "(Array('1')).length",         
    52 	      1,                             
    53 	      (Array('1')).length );
    55 new TestCase( SECTION,
    56 	      "(Array(1000)).length",        
    57 	      1000,                          
    58 	      (Array(1000)).length );
    60 new TestCase( SECTION,
    61 	      "(Array('1000')).length",      
    62 	      1,                             
    63 	      (Array('1000')).length );
    65 new TestCase( SECTION,
    66 	      "(Array(4294967295)).length",  
    67 	      ToUint32(4294967295),          
    68 	      (Array(4294967295)).length );
    70 new TestCase( SECTION,
    71 	      "(Array(Math.pow(2,31)-1)).length",    
    72 	      ToUint32(Math.pow(2,31)-1),    
    73 	      (Array(Math.pow(2,31)-1)).length );
    75 new TestCase( SECTION,
    76 	      "(Array(Math.pow(2,31))).length",      
    77 	      ToUint32(Math.pow(2,31)),      
    78 	      (Array(Math.pow(2,31))).length );
    80 new TestCase( SECTION,
    81 	      "(Array(Math.pow(2,31)+1)).length",    
    82 	      ToUint32(Math.pow(2,31)+1),    
    83 	      (Array(Math.pow(2,31)+1)).length );
    85 new TestCase( SECTION,
    86 	      "(Array('8589934592')).length",
    87 	      1,                             
    88 	      (Array("8589934592")).length );
    90 new TestCase( SECTION,
    91 	      "(Array('4294967296')).length",
    92 	      1,                             
    93 	      (Array("4294967296")).length );
    95 new TestCase( SECTION,
    96 	      "(Array(1073741823)).length",  
    97 	      ToUint32(1073741823),          
    98 	      (Array(1073741823)).length );
   100 new TestCase( SECTION,
   101 	      "(Array(1073741824)).length",  
   102 	      ToUint32(1073741824),	       
   103 	      (Array(1073741824)).length );
   105 new TestCase( SECTION,
   106 	      "(Array('a string')).length",  
   107 	      1,                             
   108 	      (Array("a string")).length );
   110 test();
   112 function ToUint32( n ) {
   113   n = Number( n );
   114   var sign = ( n < 0 ) ? -1 : 1;
   116   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
   117     return 0;
   118   }
   119   n = sign * Math.floor( Math.abs(n) )
   121     n = n % Math.pow(2,32);
   123   if ( n < 0 ){
   124     n += Math.pow(2,32);
   125   }
   127   return ( n );
   128 }

mercurial