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); |