Index: test/mjsunit/harmony/function-name.js |
diff --git a/test/mjsunit/harmony/function-name.js b/test/mjsunit/harmony/function-name.js |
index 06ada10ac8055bb5be0784cc70679171f223e7a8..5265c2d22a2fd6dd4b39e4c3a11e3058e1160bee 100644 |
--- a/test/mjsunit/harmony/function-name.js |
+++ b/test/mjsunit/harmony/function-name.js |
@@ -90,36 +90,59 @@ |
assertEquals('set 44', descriptor.set.name); |
})(); |
-// TODO(adamk): Make computed property names work. |
(function testComputedProperties() { |
'use strict'; |
var a = 'a'; |
+ var b = 'b'; |
var sym1 = Symbol('1'); |
var sym2 = Symbol('2'); |
+ var sym3 = Symbol('3'); |
+ var symNoDescription = Symbol(); |
var obj = { |
[a]: function() {}, |
[sym1]: function() {}, |
[sym2]: function withName() {}, |
+ [symNoDescription]: function() {}, |
+ |
+ get [sym3]() {}, |
+ set [b](val) {}, |
}; |
- // Should be 'a' |
- assertEquals('', obj[a].name); |
- // Should be '[1]' |
- assertEquals('', obj[sym1].name); |
+ assertEquals('a', obj[a].name); |
+ assertEquals('[1]', obj[sym1].name); |
assertEquals('withName', obj[sym2].name); |
+ assertEquals('', obj[symNoDescription].name); |
+ |
+ assertEquals('get [3]', Object.getOwnPropertyDescriptor(obj, sym3).get.name); |
+ assertEquals('set b', Object.getOwnPropertyDescriptor(obj, 'b').set.name); |
+ |
+ var objMethods = { |
+ [a]() {}, |
+ [sym1]() {}, |
+ [symNoDescription]: function() {}, |
+ }; |
+ |
+ assertEquals('a', objMethods[a].name); |
+ assertEquals('[1]', objMethods[sym1].name); |
+ assertEquals('', objMethods[symNoDescription].name); |
class C { |
[a]() { } |
[sym1]() { } |
static [sym2]() { } |
+ [symNoDescription]() { } |
+ |
+ get [sym3]() { } |
+ static set [b](val) { } |
} |
- // Should be 'a' |
- assertEquals('', C.prototype[a].name); |
- // Should be '[1]' |
- assertEquals('', C.prototype[sym1].name); |
- // Should be '[2]' |
- assertEquals('', C[sym2].name); |
+ assertEquals('a', C.prototype[a].name); |
+ assertEquals('[1]', C.prototype[sym1].name); |
+ assertEquals('[2]', C[sym2].name); |
+ assertEquals('', C.prototype[symNoDescription].name); |
+ |
+ assertEquals('get [3]', Object.getOwnPropertyDescriptor(C.prototype, sym3).get.name); |
+ assertEquals('set b', Object.getOwnPropertyDescriptor(C, 'b').set.name); |
})(); |
@@ -310,3 +333,27 @@ |
assertEquals('inManyParens', inManyParens.name) |
})(); |
})(); |
+ |
+(function testComputedNameNotShared() { |
+ function makeClass(propName) { |
+ return class { |
+ static [propName]() {} |
+ } |
+ } |
+ |
+ var sym1 = Symbol('1'); |
+ var sym2 = Symbol('2'); |
+ var class1 = makeClass(sym1); |
+ assertEquals('[1]', class1[sym1].name); |
+ var class2 = makeClass(sym2); |
+ assertEquals('[2]', class2[sym2].name); |
+ assertEquals('[1]', class1[sym1].name); |
+})(); |
+ |
+ |
+(function testComputedNamesOnlyAppliedSyntactically() { |
+ function factory() { return () => {}; } |
+ |
+ var obj = { ['foo']: factory() }; |
+ assertEquals('', obj.foo.name); |
+})(); |