js/src/tests/js1_2/Array/slice.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    Filename:     slice.js
     9    Description:  'This tests out some of the functionality on methods on the Array objects'
    11    Author:       Nick Lerissa
    12    Date:         Fri Feb 13 09:58:28 PST 1998
    13 */
    15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
    16 var VERSION = 'no version';
    17 startTest();
    18 var TITLE = 'String:slice';
    20 writeHeaderToLog('Executing script: slice.js');
    21 writeHeaderToLog( SECTION + " "+ TITLE);
    23 var a = ['a','test string',456,9.34,new String("string object"),[],['h','i','j','k']];
    24 var b = [1,2,3,4,5,6,7,8,9,0];
    26 exhaustiveSliceTest("exhaustive slice test 1", a);
    27 exhaustiveSliceTest("exhaustive slice test 2", b);
    29 test();
    31 function mySlice(a, from, to)
    32 {
    33   var from2       = from;
    34   var to2         = to;
    35   var returnArray = [];
    36   var i;
    38   if (from2 < 0) from2 = a.length + from;
    39   if (to2 < 0)   to2   = a.length + to;
    41   if ((to2 > from2)&&(to2 > 0)&&(from2 < a.length))
    42   {
    43     if (from2 < 0)        from2 = 0;
    44     if (to2 > a.length) to2 = a.length;
    46     for (i = from2; i < to2; ++i) returnArray.push(a[i]);
    47   }
    48   return returnArray;
    49 }
    51 // This function tests the slice command on an Array
    52 // passed in. The arguments passed into slice range in
    53 // value from -5 to the length of the array + 4. Every
    54 // combination of the two arguments is tested. The expected
    55 // result of the slice(...) method is calculated and
    56 // compared to the actual result from the slice(...) method.
    57 // If the Arrays are not similar false is returned.
    58 function exhaustiveSliceTest(testname, a)
    59 {
    60   var x = 0;
    61   var y = 0;
    62   var errorMessage;
    63   var reason = "";
    64   var passed = true;
    66   for (x = -(2 + a.length); x <= (2 + a.length); x++)
    67     for (y = (2 + a.length); y >= -(2 + a.length); y--)
    68     {
    69       var b  = a.slice(x,y);
    70       var c = mySlice(a,x,y);
    72       if (String(b) != String(c))
    73       {
    74 	errorMessage =
    75 	  "ERROR: 'TEST FAILED' ERROR: 'TEST FAILED' ERROR: 'TEST FAILED'\n" +
    76 	  "            test: " + "a.slice(" + x + "," + y + ")\n" +
    77 	  "               a: " + String(a) + "\n" +
    78 	  "   actual result: " + String(b) + "\n" +
    79 	  " expected result: " + String(c) + "\n";
    80 	writeHeaderToLog(errorMessage);
    81 	reason = reason + errorMessage;
    82 	passed = false;
    83       }
    84     }
    85   var testCase = new TestCase(SECTION, testname, true, passed);
    86   if (passed == false)
    87     testCase.reason = reason;
    88   return testCase;
    89 }

mercurial