| 1 |
// Copyright (C) 2014 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
esid: sec-runtime-semantics-classdefinitionevaluation |
| 5 |
description: > |
| 6 |
In a class, static computed property method names can be a string |
| 7 |
info: | |
| 8 |
Set order: "length", "name", "prototype", static methods |
| 9 |
|
| 10 |
Runtime Semantics: ClassDefinitionEvaluation |
| 11 |
|
| 12 |
... |
| 13 |
11. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. |
| 14 |
12. Let F be constructorInfo.[[Closure]]. |
| 15 |
13. Perform SetFunctionName(F, className). |
| 16 |
14. Perform MakeConstructor(F, false, proto). |
| 17 |
... |
| 18 |
19. Else, let methods be NonConstructorMethodDefinitions of ClassBody. |
| 19 |
20. For each ClassElement m in order from methods, do |
| 20 |
a. If IsStatic of m is false, then |
| 21 |
... |
| 22 |
b. Else, |
| 23 |
i. Let status be PropertyDefinitionEvaluation of m with arguments F and false. |
| 24 |
... |
| 25 |
|
| 26 |
--- |
| 27 |
|
| 28 |
Object.getOwnPropertyNames ( O ) |
| 29 |
|
| 30 |
1. Return ? GetOwnPropertyKeys(O, string). |
| 31 |
|
| 32 |
Runtime Semantics: GetOwnPropertyKeys ( O, type ) |
| 33 |
|
| 34 |
1. Let obj be ? ToObject(O). |
| 35 |
2. Let keys be ? obj.[[OwnPropertyKeys]](). |
| 36 |
3. Let nameList be a new empty List. |
| 37 |
4. For each element nextKey of keys in List order, do |
| 38 |
a. If Type(nextKey) is Symbol and type is symbol or Type(nextKey) is String and type is string, then |
| 39 |
i. Append nextKey as the last element of nameList. |
| 40 |
5. Return CreateArrayFromList(nameList). |
| 41 |
|
| 42 |
[[OwnPropertyKeys]] ( ) |
| 43 |
|
| 44 |
1. Return ! OrdinaryOwnPropertyKeys(O). |
| 45 |
|
| 46 |
OrdinaryOwnPropertyKeys ( O ) |
| 47 |
|
| 48 |
1. Let keys be a new empty List. |
| 49 |
2. For each own property key P of O such that P is an array index, in ascending numeric index order, do |
| 50 |
a. Add P as the last element of keys. |
| 51 |
3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do |
| 52 |
a. Add P as the last element of keys. |
| 53 |
4. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do |
| 54 |
a. Add P as the last element of keys. |
| 55 |
5. Return keys. |
| 56 |
includes: [compareArray.js] |
| 57 |
---*/ |
| 58 |
|
| 59 |
class C { |
| 60 |
static a() { return 'A'} |
| 61 |
static ['b']() { return 'B'; } |
| 62 |
static c() { return 'C'; } |
| 63 |
static ['d']() { return 'D'; } |
| 64 |
} |
| 65 |
assert.sameValue(C.a(), 'A', "`C.a()` returns `'A'`. Defined as `static a() { return 'A'}`"); |
| 66 |
assert.sameValue(C.b(), 'B', "`C.b()` returns `'B'`. Defined as `static ['b']() { return 'B'; }`"); |
| 67 |
assert.sameValue(C.c(), 'C', "`C.c()` returns `'C'`. Defined as `static c() { return 'C'; }`"); |
| 68 |
assert.sameValue(C.d(), 'D', "`C.d()` returns `'D'`. Defined as `static ['d']() { return 'D'; }`"); |
| 69 |
assert.compareArray( |
| 70 |
Object.keys(C), |
| 71 |
[] |
| 72 |
); |
| 73 |
|
| 74 |
reportCompare(0, 0); |