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

Unified Diff: test/mjsunit/harmony/destructuring.js

Issue 1189743003: [destructuring] Implement parameter pattern matching. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix magic number issue Created 5 years, 6 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
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/regress/regress-1130.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/destructuring.js
diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js
index 731bc6dbe5c6c3a1b9fc10e80dcde7371c16bfb6..c57dbafda6dbbd90862b11bd6af10e986e7bc2eb 100644
--- a/test/mjsunit/harmony/destructuring.js
+++ b/test/mjsunit/harmony/destructuring.js
@@ -3,6 +3,7 @@
// found in the LICENSE file.
//
// Flags: --harmony-destructuring --harmony-computed-property-names
+// Flags: --harmony-arrow-functions
(function TestObjectLiteralPattern() {
var { x : x, y : y } = { x : 1, y : 2 };
@@ -686,3 +687,44 @@
assertEquals('ab', sx);
assertEquals('12', sy);
}());
+
+
+(function TestParameters() {
+ function f({a, b}) { return a - b; }
+ assertEquals(1, f({a : 6, b : 5}));
+
+ function f1(c, {a, b}) { return c + a - b; }
+ assertEquals(8, f1(7, {a : 6, b : 5}));
+
+ function f2({c, d}, {a, b}) { return c - d + a - b; }
+ assertEquals(7, f2({c : 7, d : 1}, {a : 6, b : 5}));
+
+ function f3([{a, b}]) { return a - b; }
+ assertEquals(1, f3([{a : 6, b : 5}]));
+
+ var g = ({a, b}) => { return a - b; };
+ assertEquals(1, g({a : 6, b : 5}));
+
+ var g1 = (c, {a, b}) => { return c + a - b; };
+ assertEquals(8, g1(7, {a : 6, b : 5}));
+
+ var g2 = ({c, d}, {a, b}) => { return c - d + a - b; };
+ assertEquals(7, g2({c : 7, d : 1}, {a : 6, b : 5}));
+
+ var g3 = ([{a, b}]) => { return a - b; };
+ assertEquals(1, g3([{a : 6, b : 5}]));
+}());
+
+
+(function TestDuplicatesInParameters() {
+ assertThrows("'use strict';function f(x,x){}", SyntaxError);
+ assertThrows("'use strict';function f({x,x}){}", SyntaxError);
+ assertThrows("'use strict';function f(x, {x}){}", SyntaxError);
+ assertThrows("'use strict';var f = (x,x) => {};", SyntaxError);
+ assertThrows("'use strict';var f = ({x,x}) => {};", SyntaxError);
+ assertThrows("'use strict';var f = (x, {x}) => {};", SyntaxError);
+
+ function ok(x) { var x; }; ok();
+ assertThrows("function f({x}) { var x; }; f({});", SyntaxError);
+ assertThrows("'use strict'; function f({x}) { let x = 0; }; f({});", SyntaxError);
+}());
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | test/mjsunit/regress/regress-1130.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698