js/src/tests/js1_2/statements/switch2.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:     switch2.js
     9    Description:  'Tests the switch statement'
    11    http://scopus.mcom.com/bugsplat/show_bug.cgi?id=323696
    13    Author:       Norris Boyd
    14    Date:         July 31, 1998
    15 */
    17 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
    18 var VERSION = 'no version';
    19 var TITLE   = 'statements: switch';
    20 var BUGNUMBER="323626";
    22 startTest();
    23 writeHeaderToLog("Executing script: switch2.js");
    24 writeHeaderToLog( SECTION + " "+ TITLE);
    26 // test defaults not at the end; regression test for a bug that
    27 // nearly made it into 4.06
    28 function f0(i) {
    29   switch(i) {
    30   default:
    31   case "a":
    32   case "b":
    33     return "ab*"
    34       case "c":
    35     return "c";
    36   case "d":
    37     return "d";
    38   }
    39   return "";
    40 }
    41 new TestCase(SECTION, 'switch statement',
    42 	     f0("a"), "ab*");
    44 new TestCase(SECTION, 'switch statement',
    45 	     f0("b"), "ab*");
    47 new TestCase(SECTION, 'switch statement',
    48 	     f0("*"), "ab*");
    50 new TestCase(SECTION, 'switch statement',
    51 	     f0("c"), "c");
    53 new TestCase(SECTION, 'switch statement',
    54 	     f0("d"), "d");
    56 function f1(i) {
    57   switch(i) {
    58   case "a":
    59   case "b":
    60   default:
    61     return "ab*"
    62       case "c":
    63     return "c";
    64   case "d":
    65     return "d";
    66   }
    67   return "";
    68 }
    70 new TestCase(SECTION, 'switch statement',
    71 	     f1("a"), "ab*");
    73 new TestCase(SECTION, 'switch statement',
    74 	     f1("b"), "ab*");
    76 new TestCase(SECTION, 'switch statement',
    77 	     f1("*"), "ab*");
    79 new TestCase(SECTION, 'switch statement',
    80 	     f1("c"), "c");
    82 new TestCase(SECTION, 'switch statement',
    83 	     f1("d"), "d");
    85 // Switch on integer; will use TABLESWITCH opcode in C engine
    86 function f2(i) {
    87   switch (i) {
    88   case 0:
    89   case 1:
    90     return 1;
    91   case 2:
    92     return 2;
    93   }
    94   // with no default, control will fall through
    95   return 3;
    96 }
    98 new TestCase(SECTION, 'switch statement',
    99 	     f2(0), 1);
   101 new TestCase(SECTION, 'switch statement',
   102 	     f2(1), 1);
   104 new TestCase(SECTION, 'switch statement',
   105 	     f2(2), 2);
   107 new TestCase(SECTION, 'switch statement',
   108 	     f2(3), 3);
   110 // empty switch: make sure expression is evaluated
   111 var se = 0;
   112 switch (se = 1) {
   113 }
   114 new TestCase(SECTION, 'switch statement',
   115 	     se, 1);
   117 // only default
   118 se = 0;
   119 switch (se) {
   120 default:
   121   se = 1;
   122 }
   123 new TestCase(SECTION, 'switch statement',
   124 	     se, 1);
   126 // in loop, break should only break out of switch
   127 se = 0;
   128 for (var i=0; i < 2; i++) {
   129   switch (i) {
   130   case 0:
   131   case 1:
   132     break;
   133   }
   134   se = 1;
   135 }
   136 new TestCase(SECTION, 'switch statement',
   137 	     se, 1);
   139 // test "fall through"
   140 se = 0;
   141 i = 0;
   142 switch (i) {
   143 case 0:
   144   se++;
   145   /* fall through */
   146 case 1:
   147   se++;
   148   break;
   149 }
   150 new TestCase(SECTION, 'switch statement',
   151 	     se, 2);
   152 print("hi");
   154 test();
   156 // Needed: tests for evaluation time of case expressions.
   157 // This issue was under debate at ECMA, so postponing for now.

mercurial