author | sundar |
Wed, 06 May 2015 20:04:42 +0530 | |
changeset 30394 | 72a59e4dffea |
parent 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
4 |
* |
16147 | 5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
8 |
* |
16147 | 9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
14 |
* |
16147 | 15 |
* You should have received a copy of the GNU General Public License version |
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
18 |
* |
16147 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* NASHORN-515 : Switch default handling was broken. |
|
26 |
* |
|
27 |
* @test |
|
28 |
* @run |
|
29 |
*/ |
|
30 |
||
31 |
function a() { |
|
32 |
var x = (3.14-2.14); |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
33 |
|
16147 | 34 |
switch (x) { |
35 |
case 1: |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
36 |
print("--1"); |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
37 |
break; |
16147 | 38 |
case 2: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
39 |
print("--2"); |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
40 |
break; |
16147 | 41 |
default: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
42 |
print("default"); |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
43 |
break; |
16147 | 44 |
} |
45 |
} |
|
46 |
||
47 |
//NASHORN-529 - original fix was incomplete for primitive types |
|
48 |
function b() { |
|
49 |
var index = 256.3; |
|
50 |
switch (index) { |
|
51 |
case 0x00: |
|
52 |
case 0x01: |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
53 |
print("one zero"); |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
54 |
break; |
16147 | 55 |
default: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
56 |
print("default"); |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
57 |
break; |
16147 | 58 |
} |
59 |
} |
|
60 |
||
61 |
//NASHORN-529 - original fix was incomplete for primitive types |
|
62 |
function c() { |
|
63 |
var index = 0x1fffffffff; |
|
64 |
switch (index) { |
|
65 |
case 0x00: |
|
66 |
case 0x01: |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
67 |
print("one zero"); |
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
68 |
break; |
16147 | 69 |
default: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
70 |
print("default"); |
16147 | 71 |
} |
72 |
--index; |
|
73 |
} |
|
74 |
||
75 |
function d() { |
|
76 |
var x = (3.14-1.14); |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
77 |
|
16147 | 78 |
switch(x) { |
79 |
case 1: |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
80 |
print("--1"); break; |
16147 | 81 |
case 2: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
82 |
print("--2"); break; |
16147 | 83 |
case 3: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
84 |
print("--3"); break; |
16147 | 85 |
case 4: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
86 |
print("--4"); break; |
16147 | 87 |
default: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
88 |
print("default"); |
16147 | 89 |
} |
90 |
} |
|
91 |
||
92 |
function e() { |
|
93 |
var y = 2147483647; |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
94 |
|
16147 | 95 |
switch(y) { |
96 |
case -2147483648: |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
97 |
print("MIN_INT"); break; |
16147 | 98 |
case -2147483647: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
99 |
print("MIN_INT+1"); break; |
16147 | 100 |
case 2147483647: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
101 |
print("MAX_INT"); break; |
16147 | 102 |
case 1: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
103 |
print("--1"); break; |
16147 | 104 |
case 2: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
105 |
print("--2"); break; |
16147 | 106 |
case 3: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
107 |
print("--3"); break; |
16147 | 108 |
case 4: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
109 |
print("--4"); break; |
16147 | 110 |
default: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
111 |
print("default"); |
16147 | 112 |
} |
113 |
} |
|
114 |
||
115 |
function f() { |
|
116 |
var z = 2; |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
117 |
|
16147 | 118 |
switch(z) { |
119 |
case -2147483648: |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
120 |
print("MIN_INT"); break; |
16147 | 121 |
case -2147483647: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
122 |
print("MIN_INT+1"); break; |
16147 | 123 |
case 2147483647: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
124 |
print("MAX_INT"); break; |
16147 | 125 |
case 1: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
126 |
print("--1"); break; |
16147 | 127 |
case 2: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
128 |
print("--2 first"); break; |
16147 | 129 |
case 2: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
130 |
print("--2 second"); break; |
16147 | 131 |
case 3: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
132 |
print("--3"); break; |
16147 | 133 |
case 4: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
134 |
print("--4"); break; |
16147 | 135 |
default: |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
16151
diff
changeset
|
136 |
print("default"); |
16147 | 137 |
} |
138 |
} |
|
139 |
||
140 |
a(); |
|
141 |
b(); |
|
142 |
c(); |
|
143 |
d(); |
|
144 |
e(); |
|
145 |
f(); |