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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 Filename: switch2.js
michael@0 9 Description: 'Tests the switch statement'
michael@0 10
michael@0 11 http://scopus.mcom.com/bugsplat/show_bug.cgi?id=323696
michael@0 12
michael@0 13 Author: Norris Boyd
michael@0 14 Date: July 31, 1998
michael@0 15 */
michael@0 16
michael@0 17 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
michael@0 18 var VERSION = 'no version';
michael@0 19 var TITLE = 'statements: switch';
michael@0 20 var BUGNUMBER="323626";
michael@0 21
michael@0 22 startTest();
michael@0 23 writeHeaderToLog("Executing script: switch2.js");
michael@0 24 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 25
michael@0 26 // test defaults not at the end; regression test for a bug that
michael@0 27 // nearly made it into 4.06
michael@0 28 function f0(i) {
michael@0 29 switch(i) {
michael@0 30 default:
michael@0 31 case "a":
michael@0 32 case "b":
michael@0 33 return "ab*"
michael@0 34 case "c":
michael@0 35 return "c";
michael@0 36 case "d":
michael@0 37 return "d";
michael@0 38 }
michael@0 39 return "";
michael@0 40 }
michael@0 41 new TestCase(SECTION, 'switch statement',
michael@0 42 f0("a"), "ab*");
michael@0 43
michael@0 44 new TestCase(SECTION, 'switch statement',
michael@0 45 f0("b"), "ab*");
michael@0 46
michael@0 47 new TestCase(SECTION, 'switch statement',
michael@0 48 f0("*"), "ab*");
michael@0 49
michael@0 50 new TestCase(SECTION, 'switch statement',
michael@0 51 f0("c"), "c");
michael@0 52
michael@0 53 new TestCase(SECTION, 'switch statement',
michael@0 54 f0("d"), "d");
michael@0 55
michael@0 56 function f1(i) {
michael@0 57 switch(i) {
michael@0 58 case "a":
michael@0 59 case "b":
michael@0 60 default:
michael@0 61 return "ab*"
michael@0 62 case "c":
michael@0 63 return "c";
michael@0 64 case "d":
michael@0 65 return "d";
michael@0 66 }
michael@0 67 return "";
michael@0 68 }
michael@0 69
michael@0 70 new TestCase(SECTION, 'switch statement',
michael@0 71 f1("a"), "ab*");
michael@0 72
michael@0 73 new TestCase(SECTION, 'switch statement',
michael@0 74 f1("b"), "ab*");
michael@0 75
michael@0 76 new TestCase(SECTION, 'switch statement',
michael@0 77 f1("*"), "ab*");
michael@0 78
michael@0 79 new TestCase(SECTION, 'switch statement',
michael@0 80 f1("c"), "c");
michael@0 81
michael@0 82 new TestCase(SECTION, 'switch statement',
michael@0 83 f1("d"), "d");
michael@0 84
michael@0 85 // Switch on integer; will use TABLESWITCH opcode in C engine
michael@0 86 function f2(i) {
michael@0 87 switch (i) {
michael@0 88 case 0:
michael@0 89 case 1:
michael@0 90 return 1;
michael@0 91 case 2:
michael@0 92 return 2;
michael@0 93 }
michael@0 94 // with no default, control will fall through
michael@0 95 return 3;
michael@0 96 }
michael@0 97
michael@0 98 new TestCase(SECTION, 'switch statement',
michael@0 99 f2(0), 1);
michael@0 100
michael@0 101 new TestCase(SECTION, 'switch statement',
michael@0 102 f2(1), 1);
michael@0 103
michael@0 104 new TestCase(SECTION, 'switch statement',
michael@0 105 f2(2), 2);
michael@0 106
michael@0 107 new TestCase(SECTION, 'switch statement',
michael@0 108 f2(3), 3);
michael@0 109
michael@0 110 // empty switch: make sure expression is evaluated
michael@0 111 var se = 0;
michael@0 112 switch (se = 1) {
michael@0 113 }
michael@0 114 new TestCase(SECTION, 'switch statement',
michael@0 115 se, 1);
michael@0 116
michael@0 117 // only default
michael@0 118 se = 0;
michael@0 119 switch (se) {
michael@0 120 default:
michael@0 121 se = 1;
michael@0 122 }
michael@0 123 new TestCase(SECTION, 'switch statement',
michael@0 124 se, 1);
michael@0 125
michael@0 126 // in loop, break should only break out of switch
michael@0 127 se = 0;
michael@0 128 for (var i=0; i < 2; i++) {
michael@0 129 switch (i) {
michael@0 130 case 0:
michael@0 131 case 1:
michael@0 132 break;
michael@0 133 }
michael@0 134 se = 1;
michael@0 135 }
michael@0 136 new TestCase(SECTION, 'switch statement',
michael@0 137 se, 1);
michael@0 138
michael@0 139 // test "fall through"
michael@0 140 se = 0;
michael@0 141 i = 0;
michael@0 142 switch (i) {
michael@0 143 case 0:
michael@0 144 se++;
michael@0 145 /* fall through */
michael@0 146 case 1:
michael@0 147 se++;
michael@0 148 break;
michael@0 149 }
michael@0 150 new TestCase(SECTION, 'switch statement',
michael@0 151 se, 2);
michael@0 152 print("hi");
michael@0 153
michael@0 154 test();
michael@0 155
michael@0 156 // Needed: tests for evaluation time of case expressions.
michael@0 157 // This issue was under debate at ECMA, so postponing for now.
michael@0 158

mercurial