Index: test/mjsunit/harmony/completion.js |
diff --git a/test/mjsunit/harmony/completion.js b/test/mjsunit/harmony/completion.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0ff6c14d06703973dbbc0a0df28ed2d63a644efa |
--- /dev/null |
+++ b/test/mjsunit/harmony/completion.js |
@@ -0,0 +1,92 @@ |
+// 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: --harmony-completion |
+ |
+ |
+function assertUndef(x) { |
rossberg
2015/10/05 11:33:00
Can we also have tests that check for the correct
neis
2015/10/07 11:58:40
I added some. There's also a bunch in harmony/bloc
|
+ assertEquals(undefined, x); |
+} |
+ |
+ |
+// IfStatement [13.6.7] |
+assertUndef(eval('42; if (true) ; else 0;')); // ES5: 42 |
+assertUndef(eval('42; if (true) ;')); // ES5: 42 |
+assertUndef(eval('42; if (false) 0;')); // ES5: 42 |
+ |
+ |
+// IterationStatement [13.7] (a few of them) |
+assertUndef(eval('42; do ; while (false);')); // ES5: 42 |
+assertUndef(eval('42; var x = 1; do ; while (x--);')); // ES5: 42 |
+assertUndef(eval('42; while (false) 0;')); // ES5: 42 |
+assertUndef(eval('42; while (true) break;')); // ES5: 42 |
+assertUndef(eval('42; var x = 1; while (x--) ;')); // ES5: 42 |
+assertUndef(eval('42; for (; false; ) 0;')); // ES5: 42 |
+assertUndef(eval('42; for (var x = 1; x; x--) ;')); // ES5: 42 |
rossberg
2015/10/05 11:33:00
No tests for for-let, for-of, for-in?
neis
2015/10/07 11:58:40
Done.
|
+ |
+ |
+// WithStatement [13.11.7] |
+assertUndef(eval('42; with ({}) ;')); // ES5: 42 |
+ |
+ |
+// SwitchStatement [13.12.11] |
+assertUndef(eval('42; switch (0) {};')); // ES5: 42 |
+assertUndef(eval('42; switch (0) { case 1: 1; };')); // ES5: 42 |
+assertUndef(eval('42; switch (0) { case 0: ; };')); // ES5: 42 |
+assertUndef(eval('42; switch (0) { default: ; };')); // ES5: 42 |
+assertUndef(eval('42; switch (0) { case 0: break; }')); // ES5: 42 |
+assertEquals(0, eval('42; switch (0) { case 0: 0; }')); |
+assertEquals(0, eval('42; switch (0) { case 0: 0; break; }')); |
+ |
+ |
+// TryStatement [13.15.8] |
+assertUndef(eval('42; try { } catch(e) { };')); // ES5: 42 |
+assertUndef(eval('42; try { } catch(e) { 0; };')); // ES5: 42 |
+assertUndef(eval('42; try { throw Error } catch(e) { };')); // ES5: 42 |
+assertUndef(eval('42; try { throw Error } catch(e) { } finally { };')); // ES5: 42 |
+ |
+ |
+// Some combinations |
rossberg
2015/10/05 11:33:00
Can we have more of those? There probably are vari
neis
2015/10/07 11:58:40
Added some. There's also a bunch in harmony/block
|
+assertUndef(eval('42; switch (0) { case 0: if (true) break; }')); // ES5: 42 |
+assertUndef(eval('42; switch (0) { case 0: 0; if (true) ; }')); // ES5: 0 |
+assertUndef(eval('42; switch (0) { case 0: 0; try { break } catch(e) { }; }')); // ES5: 0 |
+ |
+// The following is not what ES6 says, but see ES bug 4540. |
+assertUndef(eval('42; switch (0) { case 0: 0; if (true) break; }')); // ES5: 0 |
+ |
+ |
+ |
+///////////////////////////////////////////////////////////////////////////////// |
rossberg
2015/10/05 11:33:00
Nit: line length
neis
2015/10/07 11:58:40
Done.
|
+// |
+// The following are copied from webkit/eval-throw-return.and adapted. |
+ |
+function throwFunc() { |
+ throw ""; |
+} |
+ |
+function throwOnReturn(){ |
+ 1; |
+ return throwFunc(); |
+} |
+ |
+function twoFunc() { |
+ 2; |
+} |
+ |
+assertEquals(1, eval("1;")); |
+assertUndef(eval("1; try { foo = [2,3,throwFunc(), 4]; } catch (e){}")); |
+assertUndef(eval("1; try { 2; throw ''; } catch (e){}")); |
+assertUndef(eval("1; try { 2; throwFunc(); } catch (e){}")); |
+assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {}")); |
+assertEquals(3, eval("1; try { 2; throwFunc(); } catch (e){3;} finally {4;}")); |
+assertUndef(eval("function blah() { 1; }; blah();")); |
+assertUndef(eval("var x = 1;")); |
+assertEquals(1, eval("if (true) { 1; } else { 2; }")); |
+assertEquals(2, eval("if (false) { 1; } else { 2; }")); |
+assertUndef(eval("try{1; if (true) { 2; throw ''; } else { 2; }} catch(e){}")); |
+assertEquals(2, eval("1; var i = 0; do { ++i; 2; } while(i!=1);")); |
+assertUndef(eval("try{1; var i = 0; do { ++i; 2; throw ''; } while(i!=1);} catch(e){}")); |
rossberg
2015/10/05 11:33:00
Line length
neis
2015/10/07 11:58:40
Done.
|
+assertUndef(eval("1; try{2; throwOnReturn();} catch(e){}")); |
+assertUndef(eval("1; twoFunc();")); |
+assertEquals(2, eval("1; with ( { a: 0 } ) { 2; }")); |