On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / js / tests / js1_2 / statements / switch2.js
blobf08ecadcbf80ffae9daf4abf511a76944e1989a7
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile = 'switch2.js';
41 /**
42 Filename: switch2.js
43 Description: 'Tests the switch statement'
45 http://scopus.mcom.com/bugsplat/show_bug.cgi?id=323696
47 Author: Norris Boyd
48 Date: July 31, 1998
51 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
52 var VERSION = 'no version';
53 var TITLE = 'statements: switch';
54 var BUGNUMBER="323626";
56 startTest();
57 writeHeaderToLog("Executing script: switch2.js");
58 writeHeaderToLog( SECTION + " "+ TITLE);
60 // test defaults not at the end; regression test for a bug that
61 // nearly made it into 4.06
62 function f0(i) {
63 switch(i) {
64 default:
65 case "a":
66 case "b":
67 return "ab*"
68 case "c":
69 return "c";
70 case "d":
71 return "d";
73 return "";
75 new TestCase(SECTION, 'switch statement',
76 f0("a"), "ab*");
78 new TestCase(SECTION, 'switch statement',
79 f0("b"), "ab*");
81 new TestCase(SECTION, 'switch statement',
82 f0("*"), "ab*");
84 new TestCase(SECTION, 'switch statement',
85 f0("c"), "c");
87 new TestCase(SECTION, 'switch statement',
88 f0("d"), "d");
90 function f1(i) {
91 switch(i) {
92 case "a":
93 case "b":
94 default:
95 return "ab*"
96 case "c":
97 return "c";
98 case "d":
99 return "d";
101 return "";
104 new TestCase(SECTION, 'switch statement',
105 f1("a"), "ab*");
107 new TestCase(SECTION, 'switch statement',
108 f1("b"), "ab*");
110 new TestCase(SECTION, 'switch statement',
111 f1("*"), "ab*");
113 new TestCase(SECTION, 'switch statement',
114 f1("c"), "c");
116 new TestCase(SECTION, 'switch statement',
117 f1("d"), "d");
119 // Switch on integer; will use TABLESWITCH opcode in C engine
120 function f2(i) {
121 switch (i) {
122 case 0:
123 case 1:
124 return 1;
125 case 2:
126 return 2;
128 // with no default, control will fall through
129 return 3;
132 new TestCase(SECTION, 'switch statement',
133 f2(0), 1);
135 new TestCase(SECTION, 'switch statement',
136 f2(1), 1);
138 new TestCase(SECTION, 'switch statement',
139 f2(2), 2);
141 new TestCase(SECTION, 'switch statement',
142 f2(3), 3);
144 // empty switch: make sure expression is evaluated
145 var se = 0;
146 switch (se = 1) {
148 new TestCase(SECTION, 'switch statement',
149 se, 1);
151 // only default
152 se = 0;
153 switch (se) {
154 default:
155 se = 1;
157 new TestCase(SECTION, 'switch statement',
158 se, 1);
160 // in loop, break should only break out of switch
161 se = 0;
162 for (var i=0; i < 2; i++) {
163 switch (i) {
164 case 0:
165 case 1:
166 break;
168 se = 1;
170 new TestCase(SECTION, 'switch statement',
171 se, 1);
173 // test "fall through"
174 se = 0;
175 i = 0;
176 switch (i) {
177 case 0:
178 se++;
179 /* fall through */
180 case 1:
181 se++;
182 break;
184 new TestCase(SECTION, 'switch statement',
185 se, 2);
186 print("hi");
188 test();
190 // Needed: tests for evaluation time of case expressions.
191 // This issue was under debate at ECMA, so postponing for now.