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

Unified 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 side-by-side diff with in-line comments
Download patch
« src/preparser.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/strong/switch.js
diff --git a/test/mjsunit/strong/switch.js b/test/mjsunit/strong/switch.js
new file mode 100644
index 0000000000000000000000000000000000000000..8880166ada1e5e0a9a992336b466a637842f5464
--- /dev/null
+++ b/test/mjsunit/strong/switch.js
@@ -0,0 +1,77 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --strong-mode
+
+"use strict";
+
+function CheckSwitch(code) {
+ let successContexts = [
rossberg 2015/04/15 19:56:34 There are some cases missing, most importantly:
conradw 2015/04/16 10:59:57 Done.
+ ["switch(1) { case 1: ", "};"],
+ ["switch(1) { default: ", "};"],
+ ["switch(1) { case 1: case 2: ", "default: };"],
+ ["switch(1) { case 1: break; case 2: ", "default: };"],
+ ["switch(1) { case 1: case 2: break; case 3: ", "case 4: default: };"],
+ ["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.
+ ]
+
+ 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.
+ ["switch(1) {case 1: 1+1; case 2: ", "};"],
+ ["switch(1) {case 1: foo: break foo; case 2: ", "};"],
+ ["switch(1) {case 1: ", " case 2: foo: break foo; };"],
+ ["switch(1) {case 1: foo:", "};"],
+ ["switch(1) {case 1: foo:{ ", "}};"],
+ ["switch(1) {case 1: foo:{ ", "} default: break;};"],
+ ["switch(1) {case 1: { foo:{ { ", "} } } default: break;};"],
+ ["switch(1) {case 1: if(1) {", "} default: break;};"],
+ ["switch(1) {case 1: foo:if(1) break; else {", "} default: break;};"]
+ ]
+
+ for (let context of successContexts) {
+ assertDoesNotThrow("function f() { 'use strong'; for(;;) {" + context[0] +
+ code + context[1] + "}}");
+ }
+ for (let context of successContexts) {
+ assertDoesNotThrow("function f() { 'use strong'; for(;;) {" + context[0] +
+ "{ 1+1; " + code + "}" + context[1] + "}}");
+ }
+ for (let context of successContexts) {
+ assertDoesNotThrow("function f() { 'use strong'; for(;;) {" + context[0] +
+ "{ 1+1; { 1+1; " + code + "}}" + context[1] + "}}");
+ }
+ for (let context of successContexts) {
+ assertDoesNotThrow("function f() { " + context[0] +
+ "(function g() { for(;;) { " + code + " }});" +
+ context[1] + "}");
+ }
+ for (let context of successContexts) {
+ assertThrows("function f() { 'use strong'; " + context[0] +
+ "(function g() { for(;;) { " + code + " }});" +
+ context[1] + "}", SyntaxError);
+ }
+ for (let context of strongThrowContexts) {
+ assertDoesNotThrow("function f() { for(;;) {" + context[0] + code +
+ context[1] + "}}");
+ }
+ for (let context of strongThrowContexts) {
+ assertThrows("function f() { 'use strong'; for(;;) {" + context[0] +
+ code + context[1] + "}}", SyntaxError);
+ }
+}
+
+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.
+CheckSwitch("continue; ");
+CheckSwitch("return; ");
+CheckSwitch("throw new TypeError(); ");
+CheckSwitch("if (1) break; else continue; ");
+CheckSwitch("if (1) {1+1; {break;}} else continue; ");
+
+assertDoesNotThrow("'use strong'; switch(1) {};");
+assertDoesNotThrow("'use strong'; switch(1) {case 1:};");
+assertDoesNotThrow("'use strong'; switch(1) {case 1: case 2: default: };");
+assertDoesNotThrow("'use strong'; foo: switch(1) {case 1: break foo;};");
+assertThrows("'use strong'; switch(1) {case 1: case 2: default: {} };",
+ SyntaxError);
+assertThrows("'use strong'; \
+ switch(1) {case 1: case 2: (function(){return}); default: };", SyntaxError);
« 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