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

Side by Side Diff: test/mjsunit/harmony/function-name.js

Issue 1626423003: Support computed properties for ES2015 Function.name (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Mostly working Created 4 years, 10 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
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 // Flags: --harmony-destructuring-bind --harmony-destructuring-assignment 6 // Flags: --harmony-destructuring-bind --harmony-destructuring-assignment
7 7
8 (function testVariableDeclarationsFunction() { 8 (function testVariableDeclarationsFunction() {
9 'use strict'; 9 'use strict';
10 var a = function(){}; 10 var a = function(){};
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 var descriptor = Object.getOwnPropertyDescriptor(C.prototype, 'c'); 83 var descriptor = Object.getOwnPropertyDescriptor(C.prototype, 'c');
84 assertEquals('get c', descriptor.get.name); 84 assertEquals('get c', descriptor.get.name);
85 assertEquals('set c', descriptor.set.name); 85 assertEquals('set c', descriptor.set.name);
86 assertEquals('42', C.prototype[42].name); 86 assertEquals('42', C.prototype[42].name);
87 assertEquals('43', C[43].name); 87 assertEquals('43', C[43].name);
88 var descriptor = Object.getOwnPropertyDescriptor(C.prototype, '44'); 88 var descriptor = Object.getOwnPropertyDescriptor(C.prototype, '44');
89 assertEquals('get 44', descriptor.get.name); 89 assertEquals('get 44', descriptor.get.name);
90 assertEquals('set 44', descriptor.set.name); 90 assertEquals('set 44', descriptor.set.name);
91 })(); 91 })();
92 92
93 // TODO(adamk): Make computed property names work.
94 (function testComputedProperties() { 93 (function testComputedProperties() {
95 'use strict'; 94 'use strict';
96 var a = 'a'; 95 var a = 'a';
96 var b = 'b';
97 var sym1 = Symbol('1'); 97 var sym1 = Symbol('1');
98 var sym2 = Symbol('2'); 98 var sym2 = Symbol('2');
99 var sym3 = Symbol('3');
100 var symNoDescription = Symbol();
99 var obj = { 101 var obj = {
100 [a]: function() {}, 102 [a]: function() {},
101 [sym1]: function() {}, 103 [sym1]: function() {},
102 [sym2]: function withName() {}, 104 [sym2]: function withName() {},
105 [symNoDescription]: function() {},
106
107 get [sym3]() {},
108 set [b](val) {},
103 }; 109 };
104 110
105 // Should be 'a' 111 assertEquals('a', obj[a].name);
106 assertEquals('', obj[a].name); 112 assertEquals('[1]', obj[sym1].name);
107 // Should be '[1]'
108 assertEquals('', obj[sym1].name);
109 assertEquals('withName', obj[sym2].name); 113 assertEquals('withName', obj[sym2].name);
114 assertEquals('', obj[symNoDescription].name);
115
116 assertEquals('get [3]', Object.getOwnPropertyDescriptor(obj, sym3).get.name);
117 assertEquals('set b', Object.getOwnPropertyDescriptor(obj, 'b').set.name);
118
119 var objMethods = {
120 [a]() {},
121 [sym1]() {},
122 [symNoDescription]: function() {},
123 };
124
125 assertEquals('a', objMethods[a].name);
126 assertEquals('[1]', objMethods[sym1].name);
127 assertEquals('', objMethods[symNoDescription].name);
110 128
111 class C { 129 class C {
112 [a]() { } 130 [a]() { }
113 [sym1]() { } 131 [sym1]() { }
114 static [sym2]() { } 132 static [sym2]() { }
133 [symNoDescription]() { }
134
135 get [sym3]() { }
136 static set [b](val) { }
115 } 137 }
116 138
117 // Should be 'a' 139 assertEquals('a', C.prototype[a].name);
118 assertEquals('', C.prototype[a].name); 140 assertEquals('[1]', C.prototype[sym1].name);
119 // Should be '[1]' 141 assertEquals('[2]', C[sym2].name);
120 assertEquals('', C.prototype[sym1].name); 142 assertEquals('', C.prototype[symNoDescription].name);
121 // Should be '[2]' 143
122 assertEquals('', C[sym2].name); 144 assertEquals('get [3]', Object.getOwnPropertyDescriptor(C.prototype, sym3).get .name);
145 assertEquals('set b', Object.getOwnPropertyDescriptor(C, 'b').set.name);
123 })(); 146 })();
124 147
125 148
126 (function testAssignment() { 149 (function testAssignment() {
127 var basicFn, arrowFn, generatorFn, classLit; 150 var basicFn, arrowFn, generatorFn, classLit;
128 151
129 basicFn = function() { return true; }; 152 basicFn = function() { return true; };
130 assertEquals('basicFn', basicFn.name); 153 assertEquals('basicFn', basicFn.name);
131 var basicFn2 = basicFn; 154 var basicFn2 = basicFn;
132 assertEquals('basicFn', basicFn2.name); 155 assertEquals('basicFn', basicFn2.name);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 assertEquals('a', a.name); 326 assertEquals('a', a.name);
304 assertEquals('b', b.name); 327 assertEquals('b', b.name);
305 assertEquals('withName', x.name); 328 assertEquals('withName', x.name);
306 assertEquals('y', y.name); 329 assertEquals('y', y.name);
307 assertEquals('ClassName', z.name); 330 assertEquals('ClassName', z.name);
308 assertEquals('function', typeof q.name); 331 assertEquals('function', typeof q.name);
309 assertEquals('inParens', inParens.name) 332 assertEquals('inParens', inParens.name)
310 assertEquals('inManyParens', inManyParens.name) 333 assertEquals('inManyParens', inManyParens.name)
311 })(); 334 })();
312 })(); 335 })();
336
337 (function testComputedNameNotShared() {
338 function makeClass(propName) {
339 return class {
340 static [propName]() {}
341 }
342 }
343
344 var sym1 = Symbol('1');
345 var sym2 = Symbol('2');
346 var class1 = makeClass(sym1);
347 assertEquals('[1]', class1[sym1].name);
348 var class2 = makeClass(sym2);
349 assertEquals('[2]', class2[sym2].name);
350 assertEquals('[1]', class1[sym1].name);
351 })();
352
353
354 (function testComputedNamesOnlyAppliedSyntactically() {
355 function factory() { return () => {}; }
356
357 var obj = { ['foo']: factory() };
358 assertEquals('', obj.foo.name);
359 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698