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

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

Issue 1129083009: [destructuring] Support computed property names in patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Patch for landing Created 5 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
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | no next file » | 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 3e1726fdc2d6ab99b152548c32f401b2701a6072..257c4a164dbfb6f7034a534d77269d5737ee3dc7 100644
--- a/test/mjsunit/harmony/destructuring.js
+++ b/test/mjsunit/harmony/destructuring.js
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// Flags: --harmony-destructuring
+// Flags: --harmony-destructuring --harmony-computed-property-names
(function TestObjectLiteralPattern() {
var { x : x, y : y } = { x : 1, y : 2 };
@@ -283,6 +283,100 @@
}());
+(function TestComputedNames() {
+ var x = 1;
+ var {[x]:y} = {1:2};
+ assertSame(2, y);
+
+ (function(){
+ 'use strict';
+ let {[x]:y} = {1:2};
+ assertSame(2, y);
+ }());
+
+ var callCount = 0;
+ function foo(v) { callCount++; return v; }
+
+ (function() {
+ callCount = 0;
+ var {[foo("abc")]:x} = {abc:42};
+ assertSame(42, x);
+ assertEquals(1, callCount);
+ }());
+
+ (function() {
+ 'use strict';
+ callCount = 0;
+ let {[foo("abc")]:x} = {abc:42};
+ assertSame(42, x);
+ assertEquals(1, callCount);
+ }());
+
+ (function() {
+ callCount = 0;
+ var {[foo("abc")]:x} = {};
+ assertSame(undefined, x);
+ assertEquals(1, callCount);
+ }());
+
+ (function() {
+ 'use strict';
+ callCount = 0;
+ let {[foo("abc")]:x} = {};
+ assertSame(undefined, x);
+ assertEquals(1, callCount);
+ }());
+
+ for (val of [null, undefined]) {
+ callCount = 0;
+ assertThrows(function() {
+ var {[foo()]:x} = val;
+ }, TypeError);
+ assertEquals(0, callCount);
+
+ callCount = 0;
+ assertThrows(function() {
+ 'use strict';
+ let {[foo()]:x} = val;
+ }, TypeError);
+ assertEquals(0, callCount);
+ }
+
+ var log = [];
+ var o = {
+ get x() { log.push("get x"); return 1; },
+ get y() { log.push("get y"); return 2; }
+ }
+ function f(v) { log.push("f " + v); return v; }
+
+ (function() {
+ log = [];
+ var { [f('x')]:x, [f('y')]:y } = o;
+ assertSame(1, x);
+ assertSame(2, y);
+ assertArrayEquals(["f x", "get x", "f y", "get y"], log);
+ }());
+
+ (function() {
+ 'use strict';
+ log = [];
+ let { [f('x')]:x, [f('y')]:y } = o;
+ assertSame(1, x);
+ assertSame(2, y);
+ assertArrayEquals(["f x", "get x", "f y", "get y"], log);
+ }());
+
+ (function() {
+ 'use strict';
+ log = [];
+ const { [f('x')]:x, [f('y')]:y } = o;
+ assertSame(1, x);
+ assertSame(2, y);
+ assertArrayEquals(["f x", "get x", "f y", "get y"], log);
+ }());
+}());
+
+
(function TestExceptions() {
for (var val of [null, undefined]) {
assertThrows(function() { var {} = val; }, TypeError);
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698