Index: test/mjsunit/harmony/arrow-functions-parsing.js |
diff --git a/test/mjsunit/harmony/arrow-functions-parsing.js b/test/mjsunit/harmony/arrow-functions-parsing.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3c6681490f2fc2edc42e914ddd96d3fd695662ed |
--- /dev/null |
+++ b/test/mjsunit/harmony/arrow-functions-parsing.js |
@@ -0,0 +1,53 @@ |
+// Copyright 2014 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_arrow_functions |
+ |
+ |
+// Test basic arrow functions syntax. |
+ |
+// Bracketed block body. |
+var bracketedEmptyBody = () => {}; |
+var bracketedNoArgs = () => { return 42; }; |
+var bracketedIdent = x => { return x; }; |
+var bracketedIdentParens = (x) => { return x; }; |
+var bracketedAddTwo = (x, y) => { return x + y; }; |
+var bracketedAddThree = (x, y, z) => { return x + y + z; }; |
+ |
+// Single expression body. |
+var noArgs = () => 24; |
+var ident = x => x; |
+var square = x => x * x; |
+var addTwo = (x, y) => x + y; |
+var addThree = (x, y, z) => x + y + z; |
+var mutateObject = (x, y) => x.a = y; |
+var objectLiteral = () => ({"value": 42}); |
+var returnsArrowFun = x => y => x + y; |
+var returnsArrowFun = (x, y) => (u, v) => x*u + y*v; |
+ |
+var yIsUndefined = x => x, y |
+assertEquals(y, undefined); |
+ |
+// Parsing arrow functions introduces a return in ParseAssignmentExpression |
+// when a closing parenthesis is found. This tests that errors are still |
+// raised when closing them incorrectly. |
+assertThrows(");", SyntaxError); |
+assertThrows(") => 0;", SyntaxError); |
+ |
+assertThrows("=> 0;", SyntaxError); // Empty param list not optional |
+assertThrows("var f = =>;", SyntaxError); // No arguments or body |
+assertThrows("var f = () =>;", SyntaxError); // No body |
+assertThrows("var f = => {};", SyntaxError); // No argument list or single argument |
+assertThrows("var f = ) => {};", SyntaxError); // No opening paren in parameter list |
+assertThrows("var f = x, y => {};", SyntaxError); // Multiple args without parens |
+assertThrows("var f = return => {};", SyntaxError); // Argument name is reserved |
+assertThrows("var f = (a,if) => {};", SyntaxError); // Argument name in list is reserved |
+assertThrows("var f = () => {'value': 42};", SyntaxError); // Object literal must be parenthesized |
+ |
+// TODO(aperez): Those cases do not pass because for now it is not possible |
+// to know whether expressions have multiple parenthesis nesting levels from |
+// the AST. |
+//assertThrows("(()) => 0;", SyntaxError); // Double-paren not allowed |
+//assertThrows("((x)) => 0;", SyntaxError); // Double-paren not allowed |
+//assertThrows("((x, y)) => 0;", SyntaxError); // Double-paren not allowed |