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

Unified Diff: test/mjsunit/harmony/function-name.js

Issue 1563923002: [es6] Handle function names in object and class literals (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Handled review comments Created 4 years, 11 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 | « src/parsing/preparser.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/function-name.js
diff --git a/test/mjsunit/harmony/function-name.js b/test/mjsunit/harmony/function-name.js
index 5da761f3c2ca7823b1a8f1212254610da035f0c0..af49bc0b2c3b4843b3bda782be397638d005afc5 100644
--- a/test/mjsunit/harmony/function-name.js
+++ b/test/mjsunit/harmony/function-name.js
@@ -33,3 +33,90 @@
assertEquals('x', x.name);
assertEquals('NamedClass', y.name);
})();
+
+(function testObjectProperties() {
+ 'use strict';
+ var obj = {
+ a: function() {},
+ b: () => {},
+ c() { },
+ get d() { },
+ set d(val) { },
+ x: function withName() { },
+ y: class { },
+ z: class ClassName { },
+ 42: function() {},
+ 4.2: function() {},
+ __proto__: function() {},
+ };
+
+ assertEquals('a', obj.a.name);
+ assertEquals('b', obj.b.name);
+ assertEquals('c', obj.c.name);
+ var dDescriptor = Object.getOwnPropertyDescriptor(obj, 'd');
+ assertEquals('get d', dDescriptor.get.name);
+ assertEquals('set d', dDescriptor.set.name);
+ assertEquals('withName', obj.x.name);
+ assertEquals('y', obj.y.name);
+ assertEquals('ClassName', obj.z.name);
+ assertEquals('42', obj[42].name);
+ assertEquals('4.2', obj[4.2].name);
+ assertEquals('', obj.__proto__.name);
+})();
+
+(function testClassProperties() {
+ 'use strict';
+ class C {
+ a() { }
+ static b() { }
+ get c() { }
+ set c(val) { }
+ 42() { }
+ static 43() { }
+ get 44() { }
+ set 44(val) { }
+ };
+
+ assertEquals('a', C.prototype.a.name);
+ assertEquals('b', C.b.name);
+ var descriptor = Object.getOwnPropertyDescriptor(C.prototype, 'c');
+ assertEquals('get c', descriptor.get.name);
+ assertEquals('set c', descriptor.set.name);
+ assertEquals('42', C.prototype[42].name);
+ assertEquals('43', C[43].name);
+ var descriptor = Object.getOwnPropertyDescriptor(C.prototype, '44');
+ assertEquals('get 44', descriptor.get.name);
+ assertEquals('set 44', descriptor.set.name);
+})();
+
+// TODO(adamk): Make computed property names work.
+(function testComputedProperties() {
+ 'use strict';
+ var a = 'a';
+ var sym1 = Symbol('1');
+ var sym2 = Symbol('2');
+ var obj = {
+ [a]: function() {},
+ [sym1]: function() {},
+ [sym2]: function withName() {},
+ };
+
+ // Should be 'a'
+ assertEquals('', obj[a].name);
+ // Should be '[1]'
+ assertEquals('', obj[sym1].name);
+ assertEquals('withName', obj[sym2].name);
+
+ class C {
+ [a]() { }
+ [sym1]() { }
+ static [sym2]() { }
+ }
+
+ // Should be 'a'
+ assertEquals('', C.prototype[a].name);
+ // Should be '[1]'
+ assertEquals('', C.prototype[sym1].name);
+ // Should be '[2]'
+ assertEquals('', C[sym2].name);
+})();
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698