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

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: fixed my broken tests 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
« test/cctest/test-parsing.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..e61fe1b908da480e898c41fe1a1d4032e6e10a54
--- /dev/null
+++ b/test/mjsunit/strong/switch.js
@@ -0,0 +1,108 @@
+// 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() {
rossberg 2015/04/16 12:01:16 I like this much better now.
+ let jumpStatements = [
+ "break; ",
+ "continue; ",
rossberg 2015/04/16 12:01:16 Add break and continue to label.
conradw 2015/04/16 12:34:20 Done.
+ "return; ",
+ "throw new TypeError(); ",
+ "if(1) break; else continue; ",
+ "if(1) {1+1; {break;}} else continue; "
+ ]
+
+ let otherStatements = [
+ "null; ",
+ "1+1; ",
+ "for(;false;) {break;} ",
+ "for(;false;) {1+1; {throw new TypeError();}} ",
+ "(function(){return});",
+ "(function(){throw new TypeError();});",
+ "{break; 1+1;} ",
+ "if(1) break; ",
+ "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.
+ ]
+
+ let successContexts = [
+ ["switch(1) {case 1: ", "case 2: }"],
+ ["switch(1) {case 1: case 2: ", "default: }"],
+ ["switch(1) {case 1: case 2: ", "default: {}}"],
+ ["switch(1) {case 1: case 2: ", "default: 1+1}"],
+ ["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;}"]
+ ]
+
+ let strongThrowContexts = [
+ ["switch(1) {case 1: 1+1; case 2: ", "}"],
+ ["switch(1) {case 1: foo: break foo; case 2: ", "}"],
+ ["switch(1) {case 1: foo:", " case 2: }"],
+ ["switch(1) {case 1: foo:{ ", "} case 2: }"],
+ ["switch(1) {case 1: foo:{ ", "} default: break;}"],
+ ["switch(1) {case 1: { foo:{ { ", "} } } default: break;}"],
+ ["switch(1) {case 1: { { { ", "} 1+1;} } default: break;}"],
+ ["switch(1) {case 1: if(1) {", "} default: break;}"],
+ ["switch(1) {case 1: foo:if(1) break; else {", "} default: break;}"]
+ ]
+
+ let sloppy_wrap = ["function f() { for(;;) {", "}}"];
+ let strong_wrap = ["function f() { 'use strong'; for(;;) {", "}}"];
+
+ for (let context of successContexts) {
+ let sloppy_prefix = sloppy_wrap[0] + context[0];
+ let sloppy_suffix = context[1] + sloppy_wrap[1];
+ let strong_prefix = strong_wrap[0] + context[0];
+ let strong_suffix = context[1] + strong_wrap[1];
+
+ for (let code of jumpStatements) {
+ 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
+ assertDoesNotThrow(strong_prefix + code + strong_suffix);
+ assertDoesNotThrow(strong_prefix + "{ 1+1; " + code + "}" +
+ strong_suffix);
+ assertDoesNotThrow(strong_prefix + "{ 1+1; { 1+1; " + code + "}}" +
+ strong_suffix);
+ assertDoesNotThrow(strong_prefix + "if(1) " + code + "else break;" +
+ strong_suffix);
+ assertDoesNotThrow(strong_prefix + "if(1) " + code +
+ "else if (1) break; else " + code + strong_suffix);
+ }
+ for (let code of otherStatements) {
+ assertDoesNotThrow(sloppy_prefix + code + sloppy_suffix);
+ assertThrows(strong_prefix + code + strong_suffix, SyntaxError);
+ }
+ }
+
+ for (let context of strongThrowContexts) {
+ let sloppy_prefix = sloppy_wrap[0] + context[0];
+ let sloppy_suffix = context[1] + sloppy_wrap[1];
+ let strong_prefix = strong_wrap[0] + context[0];
+ let strong_suffix = context[1] + strong_wrap[1];
+
+ for (let code of jumpStatements.concat(otherStatements)) {
+ assertDoesNotThrow(sloppy_prefix + code + sloppy_suffix);
+ assertThrows(strong_prefix + code + strong_suffix, SyntaxError);
+ }
+ }
+
+ for (let code of otherStatements) {
+ 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
+ assertDoesNotThrow("switch(1) {case 1: " + code + "}");
+ assertDoesNotThrow("switch(1) {case 1: break; default: " + code + "}");
+ assertDoesNotThrow("switch(1) {case 1: " + code + "break; default: }");
+ }
+}
+
+CheckSwitch();
+
+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
+assertDoesNotThrow("'use strong'; switch(1) {case 1:}");
+assertDoesNotThrow("'use strong'; switch(1) {case 1: case 2: default: }");
+assertDoesNotThrow("'use strong'; switch (1) { default: null; }");
+assertDoesNotThrow("'use strong'; switch (1) { case 0: case 1: null; }");
+assertDoesNotThrow("'use strong'; switch (1) { default: {} }");
+assertDoesNotThrow("'use strong'; foo: switch(1) {case 1: break foo;}");
« test/cctest/test-parsing.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