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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Flags: --harmony-function-name 5 // Flags: --harmony-function-name
6 6
7 (function testVariableDeclarationsFunction() { 7 (function testVariableDeclarationsFunction() {
8 'use strict'; 8 'use strict';
9 var a = function(){}; 9 var a = function(){};
10 assertEquals('a', a.name); 10 assertEquals('a', a.name);
(...skipping 15 matching lines...) Expand all
26 let b = ((class {})); 26 let b = ((class {}));
27 assertEquals('b', b.name); 27 assertEquals('b', b.name);
28 // Should not overwrite name property. 28 // Should not overwrite name property.
29 const c = class { static name() { } } 29 const c = class { static name() { } }
30 assertEquals('function', typeof c.name); 30 assertEquals('function', typeof c.name);
31 31
32 var x = class {}, y = class NamedClass {}; 32 var x = class {}, y = class NamedClass {};
33 assertEquals('x', x.name); 33 assertEquals('x', x.name);
34 assertEquals('NamedClass', y.name); 34 assertEquals('NamedClass', y.name);
35 })(); 35 })();
36
37 (function testObjectProperties() {
38 'use strict';
39 var obj = {
40 a: function() {},
41 b: () => {},
42 c() { },
43 get d() { },
44 set d(val) { },
45 x: function withName() { },
46 y: class { },
47 z: class ClassName { },
48 42: function() {},
49 4.2: function() {},
50 __proto__: function() {},
51 };
52
53 assertEquals('a', obj.a.name);
54 assertEquals('b', obj.b.name);
55 assertEquals('c', obj.c.name);
56 var dDescriptor = Object.getOwnPropertyDescriptor(obj, 'd');
57 assertEquals('get d', dDescriptor.get.name);
58 assertEquals('set d', dDescriptor.set.name);
59 assertEquals('withName', obj.x.name);
60 assertEquals('y', obj.y.name);
61 assertEquals('ClassName', obj.z.name);
62 assertEquals('42', obj[42].name);
63 assertEquals('4.2', obj[4.2].name);
64 assertEquals('', obj.__proto__.name);
65 })();
66
67 (function testClassProperties() {
68 'use strict';
69 class C {
70 a() { }
71 static b() { }
72 get c() { }
73 set c(val) { }
74 42() { }
75 static 43() { }
76 get 44() { }
77 set 44(val) { }
78 };
79
80 assertEquals('a', C.prototype.a.name);
81 assertEquals('b', C.b.name);
82 var descriptor = Object.getOwnPropertyDescriptor(C.prototype, 'c');
83 assertEquals('get c', descriptor.get.name);
84 assertEquals('set c', descriptor.set.name);
85 assertEquals('42', C.prototype[42].name);
86 assertEquals('43', C[43].name);
87 var descriptor = Object.getOwnPropertyDescriptor(C.prototype, '44');
88 assertEquals('get 44', descriptor.get.name);
89 assertEquals('set 44', descriptor.set.name);
90 })();
91
92 // TODO(adamk): Make computed property names work.
93 (function testComputedProperties() {
94 'use strict';
95 var a = 'a';
96 var sym1 = Symbol('1');
97 var sym2 = Symbol('2');
98 var obj = {
99 [a]: function() {},
100 [sym1]: function() {},
101 [sym2]: function withName() {},
102 };
103
104 // Should be 'a'
105 assertEquals('', obj[a].name);
106 // Should be '[1]'
107 assertEquals('', obj[sym1].name);
108 assertEquals('withName', obj[sym2].name);
109
110 class C {
111 [a]() { }
112 [sym1]() { }
113 static [sym2]() { }
114 }
115
116 // Should be 'a'
117 assertEquals('', C.prototype[a].name);
118 // Should be '[1]'
119 assertEquals('', C.prototype[sym1].name);
120 // Should be '[2]'
121 assertEquals('', C[sym2].name);
122 })();
OLDNEW
« 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