Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(864)

Side by Side Diff: test/mjsunit/strong/switch.js

Issue 1084983002: [strong] Implement static restrictions on switch statement (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix scope issue Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/preparser.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(code) {
10 let successContexts = [
rossberg 2015/04/15 19:56:34 There are some cases missing, most importantly:
conradw 2015/04/16 10:59:57 Done.
11 ["switch(1) { case 1: ", "};"],
12 ["switch(1) { default: ", "};"],
13 ["switch(1) { case 1: case 2: ", "default: };"],
14 ["switch(1) { case 1: break; case 2: ", "default: };"],
15 ["switch(1) { case 1: case 2: break; case 3: ", "case 4: default: };"],
16 ["switch(1) {case 1: if(1) break; else {", "} default: break;};"]
rossberg 2015/04/15 19:56:34 Nit: consistent spacing (here and below)
conradw 2015/04/16 10:59:57 Done.
17 ]
18
19 let strongThrowContexts = [
rossberg 2015/04/15 19:56:34 Add some cases here as well, e.g. loops as last st
conradw 2015/04/16 10:59:57 Done.
20 ["switch(1) {case 1: 1+1; case 2: ", "};"],
21 ["switch(1) {case 1: foo: break foo; case 2: ", "};"],
22 ["switch(1) {case 1: ", " case 2: foo: break foo; };"],
23 ["switch(1) {case 1: foo:", "};"],
24 ["switch(1) {case 1: foo:{ ", "}};"],
25 ["switch(1) {case 1: foo:{ ", "} default: break;};"],
26 ["switch(1) {case 1: { foo:{ { ", "} } } default: break;};"],
27 ["switch(1) {case 1: if(1) {", "} default: break;};"],
28 ["switch(1) {case 1: foo:if(1) break; else {", "} default: break;};"]
29 ]
30
31 for (let context of successContexts) {
32 assertDoesNotThrow("function f() { 'use strong'; for(;;) {" + context[0] +
33 code + context[1] + "}}");
34 }
35 for (let context of successContexts) {
36 assertDoesNotThrow("function f() { 'use strong'; for(;;) {" + context[0] +
37 "{ 1+1; " + code + "}" + context[1] + "}}");
38 }
39 for (let context of successContexts) {
40 assertDoesNotThrow("function f() { 'use strong'; for(;;) {" + context[0] +
41 "{ 1+1; { 1+1; " + code + "}}" + context[1] + "}}");
42 }
43 for (let context of successContexts) {
44 assertDoesNotThrow("function f() { " + context[0] +
45 "(function g() { for(;;) { " + code + " }});" +
46 context[1] + "}");
47 }
48 for (let context of successContexts) {
49 assertThrows("function f() { 'use strong'; " + context[0] +
50 "(function g() { for(;;) { " + code + " }});" +
51 context[1] + "}", SyntaxError);
52 }
53 for (let context of strongThrowContexts) {
54 assertDoesNotThrow("function f() { for(;;) {" + context[0] + code +
55 context[1] + "}}");
56 }
57 for (let context of strongThrowContexts) {
58 assertThrows("function f() { 'use strong'; for(;;) {" + context[0] +
59 code + context[1] + "}}", SyntaxError);
60 }
61 }
62
63 CheckSwitch("break; ");
rossberg 2015/04/15 19:56:35 Nit: Make these an outer loop inside the test func
conradw 2015/04/16 10:59:57 Done.
64 CheckSwitch("continue; ");
65 CheckSwitch("return; ");
66 CheckSwitch("throw new TypeError(); ");
67 CheckSwitch("if (1) break; else continue; ");
68 CheckSwitch("if (1) {1+1; {break;}} else continue; ");
69
70 assertDoesNotThrow("'use strong'; switch(1) {};");
71 assertDoesNotThrow("'use strong'; switch(1) {case 1:};");
72 assertDoesNotThrow("'use strong'; switch(1) {case 1: case 2: default: };");
73 assertDoesNotThrow("'use strong'; foo: switch(1) {case 1: break foo;};");
74 assertThrows("'use strong'; switch(1) {case 1: case 2: default: {} };",
75 SyntaxError);
76 assertThrows("'use strong'; \
77 switch(1) {case 1: case 2: (function(){return}); default: };", SyntaxError);
OLDNEW
« src/preparser.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698