OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --strong-mode | |
6 | |
7 "use strict"; | |
8 | |
9 function CheckSwitch() { | |
rossberg
2015/04/16 12:01:16
I like this much better now.
| |
10 let jumpStatements = [ | |
11 "break; ", | |
12 "continue; ", | |
rossberg
2015/04/16 12:01:16
Add break and continue to label.
conradw
2015/04/16 12:34:20
Done.
| |
13 "return; ", | |
14 "throw new TypeError(); ", | |
15 "if(1) break; else continue; ", | |
16 "if(1) {1+1; {break;}} else continue; " | |
17 ] | |
18 | |
19 let otherStatements = [ | |
20 "null; ", | |
21 "1+1; ", | |
22 "for(;false;) {break;} ", | |
23 "for(;false;) {1+1; {throw new TypeError();}} ", | |
24 "(function(){return});", | |
25 "(function(){throw new TypeError();});", | |
26 "{break; 1+1;} ", | |
27 "if(1) break; ", | |
28 "if(1) break; else 1+1; ", | |
rossberg
2015/04/16 12:01:16
Also add the symmetric "if (1) 1+1 else break"
conradw
2015/04/16 12:34:20
Done.
| |
29 ] | |
30 | |
31 let successContexts = [ | |
32 ["switch(1) {case 1: ", "case 2: }"], | |
33 ["switch(1) {case 1: case 2: ", "default: }"], | |
34 ["switch(1) {case 1: case 2: ", "default: {}}"], | |
35 ["switch(1) {case 1: case 2: ", "default: 1+1}"], | |
36 ["switch(1) {case 1: break; case 2: ", "default: }"], | |
37 ["switch(1) {case 1: case 2: break; case 3: ", "case 4: default: }"], | |
38 ["switch(1) {case 1: if(1) break; else {", "} default: break;}"] | |
39 ] | |
40 | |
41 let strongThrowContexts = [ | |
42 ["switch(1) {case 1: 1+1; case 2: ", "}"], | |
43 ["switch(1) {case 1: foo: break foo; case 2: ", "}"], | |
44 ["switch(1) {case 1: foo:", " case 2: }"], | |
45 ["switch(1) {case 1: foo:{ ", "} case 2: }"], | |
46 ["switch(1) {case 1: foo:{ ", "} default: break;}"], | |
47 ["switch(1) {case 1: { foo:{ { ", "} } } default: break;}"], | |
48 ["switch(1) {case 1: { { { ", "} 1+1;} } default: break;}"], | |
49 ["switch(1) {case 1: if(1) {", "} default: break;}"], | |
50 ["switch(1) {case 1: foo:if(1) break; else {", "} default: break;}"] | |
51 ] | |
52 | |
53 let sloppy_wrap = ["function f() { for(;;) {", "}}"]; | |
54 let strong_wrap = ["function f() { 'use strong'; for(;;) {", "}}"]; | |
55 | |
56 for (let context of successContexts) { | |
57 let sloppy_prefix = sloppy_wrap[0] + context[0]; | |
58 let sloppy_suffix = context[1] + sloppy_wrap[1]; | |
59 let strong_prefix = strong_wrap[0] + context[0]; | |
60 let strong_suffix = context[1] + strong_wrap[1]; | |
61 | |
62 for (let code of jumpStatements) { | |
63 assertDoesNotThrow(strong_wrap[0] + "switch(1) {case 1: " + code + "}}}"); | |
rossberg
2015/04/16 12:01:16
Why not move this case to the successContexts?
conradw
2015/04/16 12:34:21
The successContexts are intended to not work if co
| |
64 assertDoesNotThrow(strong_prefix + code + strong_suffix); | |
65 assertDoesNotThrow(strong_prefix + "{ 1+1; " + code + "}" + | |
66 strong_suffix); | |
67 assertDoesNotThrow(strong_prefix + "{ 1+1; { 1+1; " + code + "}}" + | |
68 strong_suffix); | |
69 assertDoesNotThrow(strong_prefix + "if(1) " + code + "else break;" + | |
70 strong_suffix); | |
71 assertDoesNotThrow(strong_prefix + "if(1) " + code + | |
72 "else if (1) break; else " + code + strong_suffix); | |
73 } | |
74 for (let code of otherStatements) { | |
75 assertDoesNotThrow(sloppy_prefix + code + sloppy_suffix); | |
76 assertThrows(strong_prefix + code + strong_suffix, SyntaxError); | |
77 } | |
78 } | |
79 | |
80 for (let context of strongThrowContexts) { | |
81 let sloppy_prefix = sloppy_wrap[0] + context[0]; | |
82 let sloppy_suffix = context[1] + sloppy_wrap[1]; | |
83 let strong_prefix = strong_wrap[0] + context[0]; | |
84 let strong_suffix = context[1] + strong_wrap[1]; | |
85 | |
86 for (let code of jumpStatements.concat(otherStatements)) { | |
87 assertDoesNotThrow(sloppy_prefix + code + sloppy_suffix); | |
88 assertThrows(strong_prefix + code + strong_suffix, SyntaxError); | |
89 } | |
90 } | |
91 | |
92 for (let code of otherStatements) { | |
93 assertDoesNotThrow("switch(1) {default: " + code + "}"); | |
rossberg
2015/04/16 12:01:16
Same here?
conradw
2015/04/16 12:34:21
Similar reasoning. This for block is a specific (o
| |
94 assertDoesNotThrow("switch(1) {case 1: " + code + "}"); | |
95 assertDoesNotThrow("switch(1) {case 1: break; default: " + code + "}"); | |
96 assertDoesNotThrow("switch(1) {case 1: " + code + "break; default: }"); | |
97 } | |
98 } | |
99 | |
100 CheckSwitch(); | |
101 | |
102 assertDoesNotThrow("'use strong'; switch(1) {}"); | |
rossberg
2015/04/16 12:01:16
Can't you cover all these by adding "" to the othe
conradw
2015/04/16 12:34:21
It's currently assumed that when one of the otherS
| |
103 assertDoesNotThrow("'use strong'; switch(1) {case 1:}"); | |
104 assertDoesNotThrow("'use strong'; switch(1) {case 1: case 2: default: }"); | |
105 assertDoesNotThrow("'use strong'; switch (1) { default: null; }"); | |
106 assertDoesNotThrow("'use strong'; switch (1) { case 0: case 1: null; }"); | |
107 assertDoesNotThrow("'use strong'; switch (1) { default: {} }"); | |
108 assertDoesNotThrow("'use strong'; foo: switch(1) {case 1: break foo;}"); | |
OLD | NEW |