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

Unified Diff: test/mjsunit/harmony/arrow-functions-parsing.js

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Extra parens in parameter lists now recognized, no longer segfaults on "()" Created 6 years, 7 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
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..712ed62a8303e3a904a47ca2e41b1536da449b4e
--- /dev/null
+++ b/test/mjsunit/harmony/arrow-functions-parsing.js
@@ -0,0 +1,59 @@
+// 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 returnsArrowFun2 = (x, y) => (u, v) => x*u + y*v;
+var objectLiteralResult = ({ value: 42 });
marja 2014/05/26 12:46:06 Pls test that these yield the expected results, to
+
+var yIsUndefined = x => x, y;
+assertEquals(y, undefined);
+
+// This is a valid arrow function literal which is invoked right away
+assertEquals((x => x + 1)(1), 2);
+
+// 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);
marja 2014/05/26 12:46:06 You can move these "parsing should fail" cases to
+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 = , => {};", SyntaxError); // Comma without opening parens
+assertThrows("var f = (,) => {};", SyntaxError); // Just one comma 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 = (a * b) => {};", SyntaxError); // Comma must be the binop in between parameters
+assertThrows("var f = () => {'value': 42};", SyntaxError); // Object literal must be parenthesized
+
+// Parameter lists with extra parens should be recognized as errors.
+assertThrows("(()) => 0;", SyntaxError);
+assertThrows("((x)) => 0;", SyntaxError);
+assertThrows("((x, y)) => 0;", SyntaxError);
+assertThrows("(x, (y)) => 0;", SyntaxError);
marja 2014/05/26 12:46:06 You should add tests for different (legal and ille
« src/preparser.h ('K') | « src/v8natives.js ('k') | tools/generate-runtime-tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698