1425bb815Sopenharmony_ci// Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci//
3425bb815Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci// you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci// You may obtain a copy of the License at
6425bb815Sopenharmony_ci//
7425bb815Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci//
9425bb815Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci// See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci// limitations under the License.
14425bb815Sopenharmony_ci
15425bb815Sopenharmony_cifunction assertNameExists(func) {
16425bb815Sopenharmony_ci  assert(func.hasOwnProperty('name') === true);
17425bb815Sopenharmony_ci}
18425bb815Sopenharmony_cifunction assertNameNotExists(func) {
19425bb815Sopenharmony_ci  assert(func.hasOwnProperty('name') === false);
20425bb815Sopenharmony_ci  assert(Function.prototype.name === '');
21425bb815Sopenharmony_ci  assert(func.name === '');
22425bb815Sopenharmony_ci}
23425bb815Sopenharmony_ci
24425bb815Sopenharmony_cifunction assertConfigurableOnlyMethod(func) {
25425bb815Sopenharmony_ci  let desc = Object.getOwnPropertyDescriptor(func, 'name');
26425bb815Sopenharmony_ci  assert(desc.configurable === true);
27425bb815Sopenharmony_ci  assert(desc.writable === false);
28425bb815Sopenharmony_ci  assert(desc.enumerable === false);
29425bb815Sopenharmony_ci
30425bb815Sopenharmony_ci  delete func.name;
31425bb815Sopenharmony_ci  assertNameNotExists(func);
32425bb815Sopenharmony_ci
33425bb815Sopenharmony_ci  Object.defineProperty(func, 'name', {value: 'newName', configurable: true});
34425bb815Sopenharmony_ci  assert (Object.getOwnPropertyDescriptor(func, 'name').value === 'newName');
35425bb815Sopenharmony_ci  assertNameExists(func);
36425bb815Sopenharmony_ci
37425bb815Sopenharmony_ci  delete func.name;
38425bb815Sopenharmony_ci  assertNameNotExists(func);
39425bb815Sopenharmony_ci  Object.defineProperty(func, 'name', desc);
40425bb815Sopenharmony_ci}
41425bb815Sopenharmony_ci
42425bb815Sopenharmony_cifunction assertConfigurableOnlyAccessor(func, name, method) {
43425bb815Sopenharmony_ci  let accessor = Object.getOwnPropertyDescriptor(func, name)[method];
44425bb815Sopenharmony_ci  assertConfigurableOnlyMethod(accessor);
45425bb815Sopenharmony_ci}
46425bb815Sopenharmony_ci
47425bb815Sopenharmony_cifunction assertMethodName(func, name, functionName = name) {
48425bb815Sopenharmony_ci  assertNameExists(func);
49425bb815Sopenharmony_ci  assertConfigurableOnlyMethod(func)
50425bb815Sopenharmony_ci  assert(Object.getOwnPropertyDescriptor(func, 'name').value === functionName)
51425bb815Sopenharmony_ci}
52425bb815Sopenharmony_ci
53425bb815Sopenharmony_cifunction assertGetterName(obj, name, functionName = name) {
54425bb815Sopenharmony_ci  assertConfigurableOnlyAccessor(obj, name, 'get');
55425bb815Sopenharmony_ci  assert(Object.getOwnPropertyDescriptor(obj, name).get['name'] === 'get ' + functionName)
56425bb815Sopenharmony_ci}
57425bb815Sopenharmony_ci
58425bb815Sopenharmony_cifunction assertSetterName(obj, name, functionName = name) {
59425bb815Sopenharmony_ci  assertConfigurableOnlyAccessor(obj, name, 'set');
60425bb815Sopenharmony_ci  assert(Object.getOwnPropertyDescriptor(obj, name).set['name'] === 'set ' + functionName)
61425bb815Sopenharmony_ci}
62425bb815Sopenharmony_ci
63425bb815Sopenharmony_civar func1 = function () {};
64425bb815Sopenharmony_ciassertMethodName(func1, 'func1');
65425bb815Sopenharmony_ci
66425bb815Sopenharmony_civar func2 = function bar() {};
67425bb815Sopenharmony_ciassertMethodName(func2, 'bar');
68425bb815Sopenharmony_ci
69425bb815Sopenharmony_civar func3 = (function () {}).prototype.constructor;
70425bb815Sopenharmony_ciassert(typeof func3 === 'function');
71425bb815Sopenharmony_ciassertNameNotExists(func3);
72425bb815Sopenharmony_ci
73425bb815Sopenharmony_civar func4;
74425bb815Sopenharmony_cifunc4 = function () {}
75425bb815Sopenharmony_ciassertMethodName(func4, 'func4');
76425bb815Sopenharmony_ci
77425bb815Sopenharmony_civar func5;
78425bb815Sopenharmony_cifunc5 = function bar () {}
79425bb815Sopenharmony_ciassertMethodName(func5, 'bar');
80425bb815Sopenharmony_ci
81425bb815Sopenharmony_civar func6;
82425bb815Sopenharmony_ci(func6) = function () {}
83425bb815Sopenharmony_ciassertNameNotExists(func6);
84425bb815Sopenharmony_ci
85425bb815Sopenharmony_civar func7;
86425bb815Sopenharmony_ci(func7) = function bar () {}
87425bb815Sopenharmony_ciassertMethodName(func7, 'bar');
88425bb815Sopenharmony_ci
89425bb815Sopenharmony_cilet emptySymbolMethod = Symbol();
90425bb815Sopenharmony_cilet namedSymbolMethod = Symbol('foo');
91425bb815Sopenharmony_cilet emptySymbolGetter = Symbol();
92425bb815Sopenharmony_cilet namedSymbolGetter = Symbol('foo');
93425bb815Sopenharmony_cilet emptySymbolSetter = Symbol();
94425bb815Sopenharmony_cilet namedSymbolSetter = Symbol('foo');
95425bb815Sopenharmony_ci
96425bb815Sopenharmony_civar o = {
97425bb815Sopenharmony_ci  func1() {},
98425bb815Sopenharmony_ci  func2: function () {},
99425bb815Sopenharmony_ci  func3: function bar() {},
100425bb815Sopenharmony_ci  func4: () => {},
101425bb815Sopenharmony_ci  func5: class {},
102425bb815Sopenharmony_ci  func6: class A {},
103425bb815Sopenharmony_ci  func7: class name { static name () {} },
104425bb815Sopenharmony_ci  ['func' + '8']() {},
105425bb815Sopenharmony_ci  ['func' + '9']: function () {},
106425bb815Sopenharmony_ci  ['func' + '10']: function bar() {},
107425bb815Sopenharmony_ci  ['func' + '11']: () => {},
108425bb815Sopenharmony_ci  ['func' + '12']: class {},
109425bb815Sopenharmony_ci  ['func' + '13']: class A {},
110425bb815Sopenharmony_ci  ['func' + '14']: class name { static name () {} },
111425bb815Sopenharmony_ci  get func15() {},
112425bb815Sopenharmony_ci  get ['func' + '16']() {},
113425bb815Sopenharmony_ci  set func17(a) {},
114425bb815Sopenharmony_ci  set ['func' + '18'](a) {},
115425bb815Sopenharmony_ci  [emptySymbolMethod]() {},
116425bb815Sopenharmony_ci  [namedSymbolMethod]() {},
117425bb815Sopenharmony_ci  get [emptySymbolGetter]() {},
118425bb815Sopenharmony_ci  get [namedSymbolGetter]() {},
119425bb815Sopenharmony_ci  set [emptySymbolSetter](a) {},
120425bb815Sopenharmony_ci  set [namedSymbolSetter](a) {},
121425bb815Sopenharmony_ci}
122425bb815Sopenharmony_ci
123425bb815Sopenharmony_ciassertMethodName(o.func1, 'func1');
124425bb815Sopenharmony_ciassertMethodName(o.func2, 'func2');
125425bb815Sopenharmony_ciassertMethodName(o.func3, 'bar');
126425bb815Sopenharmony_ciassertMethodName(o.func4, 'func4');
127425bb815Sopenharmony_ciassertMethodName(o.func5, 'func5');
128425bb815Sopenharmony_ciassertMethodName(o.func6, 'A');
129425bb815Sopenharmony_ciassert(typeof o.func7 === 'function');
130425bb815Sopenharmony_ci
131425bb815Sopenharmony_ciassertMethodName(o.func8, 'func8');
132425bb815Sopenharmony_ciassertMethodName(o.func9, 'func9');
133425bb815Sopenharmony_ciassertMethodName(o.func10, 'bar');
134425bb815Sopenharmony_ciassertMethodName(o.func11, 'func11');
135425bb815Sopenharmony_ciassertMethodName(o.func12, 'func12');
136425bb815Sopenharmony_ciassertMethodName(o.func13, 'A');
137425bb815Sopenharmony_ciassert(typeof o.func14 === 'function');
138425bb815Sopenharmony_ci
139425bb815Sopenharmony_ciassertGetterName(o, 'func15');
140425bb815Sopenharmony_ciassertGetterName(o, 'func16');
141425bb815Sopenharmony_ciassertSetterName(o, 'func17');
142425bb815Sopenharmony_ciassertSetterName(o, 'func17');
143425bb815Sopenharmony_ci
144425bb815Sopenharmony_ciassertMethodName(o[emptySymbolMethod], '');
145425bb815Sopenharmony_ciassertMethodName(o[namedSymbolMethod], '[foo]');
146425bb815Sopenharmony_ciassertGetterName(o, emptySymbolGetter, '');
147425bb815Sopenharmony_ciassertGetterName(o, namedSymbolGetter, '[foo]');
148425bb815Sopenharmony_ciassertSetterName(o, emptySymbolSetter, '');
149425bb815Sopenharmony_ciassertSetterName(o, namedSymbolSetter, '[foo]');
150425bb815Sopenharmony_ci
151425bb815Sopenharmony_ciclass A  {
152425bb815Sopenharmony_ci  constructor () {}
153425bb815Sopenharmony_ci  func1() {}
154425bb815Sopenharmony_ci  get func2() {}
155425bb815Sopenharmony_ci  set func3(a) {}
156425bb815Sopenharmony_ci
157425bb815Sopenharmony_ci  static func4() {}
158425bb815Sopenharmony_ci  static get func5() {}
159425bb815Sopenharmony_ci  static set func6(a) {}
160425bb815Sopenharmony_ci
161425bb815Sopenharmony_ci  ['func' + '7']() {}
162425bb815Sopenharmony_ci  get ['func' + '8']() {}
163425bb815Sopenharmony_ci  set ['func' + '9'](a) {}
164425bb815Sopenharmony_ci
165425bb815Sopenharmony_ci  static ['func' + '10']() {}
166425bb815Sopenharmony_ci  static get ['func' + '11']() {}
167425bb815Sopenharmony_ci  static set ['func' + '12'](a) {}
168425bb815Sopenharmony_ci
169425bb815Sopenharmony_ci  [emptySymbolMethod]() {}
170425bb815Sopenharmony_ci  [namedSymbolMethod]() {}
171425bb815Sopenharmony_ci  get [emptySymbolGetter]() {}
172425bb815Sopenharmony_ci  get [namedSymbolGetter]() {}
173425bb815Sopenharmony_ci  set [emptySymbolSetter](a) {}
174425bb815Sopenharmony_ci  set [namedSymbolSetter](a) {}
175425bb815Sopenharmony_ci
176425bb815Sopenharmony_ci  static [emptySymbolMethod]() {}
177425bb815Sopenharmony_ci  static [namedSymbolMethod]() {}
178425bb815Sopenharmony_ci  static get [emptySymbolGetter]() {}
179425bb815Sopenharmony_ci  static get [namedSymbolGetter]() {}
180425bb815Sopenharmony_ci  static set [emptySymbolSetter](a) {}
181425bb815Sopenharmony_ci  static set [namedSymbolSetter](a) {}
182425bb815Sopenharmony_ci}
183425bb815Sopenharmony_ci
184425bb815Sopenharmony_ciassertMethodName(A.prototype.func1, 'func1');
185425bb815Sopenharmony_ciassertGetterName(A.prototype, 'func2');
186425bb815Sopenharmony_ciassertSetterName(A.prototype, 'func3');
187425bb815Sopenharmony_ci
188425bb815Sopenharmony_ciassertMethodName(A.func4, 'func4');
189425bb815Sopenharmony_ciassertGetterName(A, 'func5');
190425bb815Sopenharmony_ciassertSetterName(A, 'func6');
191425bb815Sopenharmony_ci
192425bb815Sopenharmony_ciassertMethodName(A.prototype.func7, 'func7');
193425bb815Sopenharmony_ciassertGetterName(A.prototype, 'func8');
194425bb815Sopenharmony_ciassertSetterName(A.prototype, 'func9');
195425bb815Sopenharmony_ci
196425bb815Sopenharmony_ciassertMethodName(A.func10, 'func10');
197425bb815Sopenharmony_ciassertGetterName(A, 'func11');
198425bb815Sopenharmony_ciassertSetterName(A, 'func12');
199425bb815Sopenharmony_ci
200425bb815Sopenharmony_ciassertMethodName(A[emptySymbolMethod], '');
201425bb815Sopenharmony_ciassertMethodName(A[namedSymbolMethod], '[foo]');
202425bb815Sopenharmony_ciassertGetterName(A, emptySymbolGetter, '');
203425bb815Sopenharmony_ciassertGetterName(A, namedSymbolGetter, '[foo]');
204425bb815Sopenharmony_ciassertSetterName(A, emptySymbolSetter, '');
205425bb815Sopenharmony_ciassertSetterName(A, namedSymbolSetter, '[foo]');
206425bb815Sopenharmony_ci
207425bb815Sopenharmony_ciassertMethodName(A.prototype[emptySymbolMethod], '');
208425bb815Sopenharmony_ciassertMethodName(A.prototype[namedSymbolMethod], '[foo]');
209425bb815Sopenharmony_ciassertGetterName(A.prototype, emptySymbolGetter, '');
210425bb815Sopenharmony_ciassertGetterName(A.prototype, namedSymbolGetter, '[foo]');
211425bb815Sopenharmony_ciassertSetterName(A.prototype, emptySymbolSetter, '');
212425bb815Sopenharmony_ciassertSetterName(A.prototype, namedSymbolSetter, '[foo]');
213425bb815Sopenharmony_ci
214425bb815Sopenharmony_ciclass B  {
215425bb815Sopenharmony_ci  func1() {}
216425bb815Sopenharmony_ci  get func2() {}
217425bb815Sopenharmony_ci  set func3(a) {}
218425bb815Sopenharmony_ci
219425bb815Sopenharmony_ci  static func4() {}
220425bb815Sopenharmony_ci  static get func5() {}
221425bb815Sopenharmony_ci  static set func6(a) {}
222425bb815Sopenharmony_ci
223425bb815Sopenharmony_ci  ['func' + '7']() {}
224425bb815Sopenharmony_ci  get ['func' + '8']() {}
225425bb815Sopenharmony_ci  set ['func' + '9'](a) {}
226425bb815Sopenharmony_ci
227425bb815Sopenharmony_ci  static ['func' + '10']() {}
228425bb815Sopenharmony_ci  static get ['func' + '11']() {}
229425bb815Sopenharmony_ci  static set ['func' + '12'](a) {}
230425bb815Sopenharmony_ci
231425bb815Sopenharmony_ci  [emptySymbolMethod]() {}
232425bb815Sopenharmony_ci  [namedSymbolMethod]() {}
233425bb815Sopenharmony_ci  get [emptySymbolGetter]() {}
234425bb815Sopenharmony_ci  get [namedSymbolGetter]() {}
235425bb815Sopenharmony_ci  set [emptySymbolSetter](a) {}
236425bb815Sopenharmony_ci  set [namedSymbolSetter](a) {}
237425bb815Sopenharmony_ci
238425bb815Sopenharmony_ci  static [emptySymbolMethod]() {}
239425bb815Sopenharmony_ci  static [namedSymbolMethod]() {}
240425bb815Sopenharmony_ci  static get [emptySymbolGetter]() {}
241425bb815Sopenharmony_ci  static get [namedSymbolGetter]() {}
242425bb815Sopenharmony_ci  static set [emptySymbolSetter](a) {}
243425bb815Sopenharmony_ci  static set [namedSymbolSetter](a) {}
244425bb815Sopenharmony_ci}
245425bb815Sopenharmony_ci
246425bb815Sopenharmony_ciassertMethodName(B.prototype.func1, 'func1');
247425bb815Sopenharmony_ciassertGetterName(B.prototype, 'func2');
248425bb815Sopenharmony_ciassertSetterName(B.prototype, 'func3');
249425bb815Sopenharmony_ci
250425bb815Sopenharmony_ciassertMethodName(B.func4, 'func4');
251425bb815Sopenharmony_ciassertGetterName(B, 'func5');
252425bb815Sopenharmony_ciassertSetterName(B, 'func6');
253425bb815Sopenharmony_ci
254425bb815Sopenharmony_ciassertMethodName(B.prototype.func7, 'func7');
255425bb815Sopenharmony_ciassertGetterName(B.prototype, 'func8');
256425bb815Sopenharmony_ciassertSetterName(B.prototype, 'func9');
257425bb815Sopenharmony_ci
258425bb815Sopenharmony_ciassertMethodName(B.func10, 'func10');
259425bb815Sopenharmony_ciassertGetterName(B, 'func11');
260425bb815Sopenharmony_ciassertSetterName(B, 'func12');
261425bb815Sopenharmony_ci
262425bb815Sopenharmony_ciassertMethodName(B[emptySymbolMethod], '');
263425bb815Sopenharmony_ciassertMethodName(B[namedSymbolMethod], '[foo]');
264425bb815Sopenharmony_ciassertGetterName(B, emptySymbolGetter, '');
265425bb815Sopenharmony_ciassertGetterName(B, namedSymbolGetter, '[foo]');
266425bb815Sopenharmony_ciassertSetterName(B, emptySymbolSetter, '');
267425bb815Sopenharmony_ciassertSetterName(B, namedSymbolSetter, '[foo]');
268425bb815Sopenharmony_ci
269425bb815Sopenharmony_ciassertMethodName(B.prototype[emptySymbolMethod], '');
270425bb815Sopenharmony_ciassertMethodName(B.prototype[namedSymbolMethod], '[foo]');
271425bb815Sopenharmony_ciassertGetterName(B.prototype, emptySymbolGetter, '');
272425bb815Sopenharmony_ciassertGetterName(B.prototype, namedSymbolGetter, '[foo]');
273425bb815Sopenharmony_ciassertSetterName(B.prototype, emptySymbolSetter, '');
274425bb815Sopenharmony_ciassertSetterName(B.prototype, namedSymbolSetter, '[foo]');
275425bb815Sopenharmony_ci
276425bb815Sopenharmony_cilet names = ['push', 'pop', 'reduce', 'reduceRight'];
277425bb815Sopenharmony_ci
278425bb815Sopenharmony_cifor (let n of names) {
279425bb815Sopenharmony_ci  assert(Array.prototype[n].name === n);
280425bb815Sopenharmony_ci}
281425bb815Sopenharmony_ci
282425bb815Sopenharmony_ciassert(Array.prototype[Symbol.iterator].name === 'values');
283425bb815Sopenharmony_ciassert(Array.prototype.values.name === 'values');
284425bb815Sopenharmony_ciassert(Object.getOwnPropertyDescriptor(Array, Symbol.species).get.name === 'get [Symbol.species]');
285425bb815Sopenharmony_ciassert(Object.getOwnPropertyDescriptor(String.prototype, Symbol.iterator).value.name === '[Symbol.iterator]');
286425bb815Sopenharmony_ciassert(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').get.name === 'get __proto__');
287425bb815Sopenharmony_ciassert(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set.name === 'set __proto__');
288425bb815Sopenharmony_ci
289425bb815Sopenharmony_cilet arFunc;
290425bb815Sopenharmony_cilet array = [];
291425bb815Sopenharmony_ciarray['original'] = array;
292425bb815Sopenharmony_ciarray['original'][arFunc = ()=>{ }]=function(){}
293425bb815Sopenharmony_ciassertNameNotExists(array[arFunc]);
294425bb815Sopenharmony_ci
295425bb815Sopenharmony_civar o = { 0 : class {} };
296425bb815Sopenharmony_ci
297425bb815Sopenharmony_ciassertMethodName(o['0'], '0');
298