method-symbol.js (2917B)
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 symbol 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 Object.getOwnPropertySymbols ( O ) 33 34 1. Return ? GetOwnPropertyKeys(O, symbol). 35 36 Runtime Semantics: GetOwnPropertyKeys ( O, type ) 37 38 1. Let obj be ? ToObject(O). 39 2. Let keys be ? obj.[[OwnPropertyKeys]](). 40 3. Let nameList be a new empty List. 41 4. For each element nextKey of keys in List order, do 42 a. If Type(nextKey) is Symbol and type is symbol or Type(nextKey) is String and type is string, then 43 i. Append nextKey as the last element of nameList. 44 5. Return CreateArrayFromList(nameList). 45 46 [[OwnPropertyKeys]] ( ) 47 48 1. Return ! OrdinaryOwnPropertyKeys(O). 49 50 OrdinaryOwnPropertyKeys ( O ) 51 52 1. Let keys be a new empty List. 53 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do 54 a. Add P as the last element of keys. 55 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 56 a. Add P as the last element of keys. 57 4. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do 58 a. Add P as the last element of keys. 59 5. Return keys. 60 includes: [compareArray.js] 61 features: [Symbol] 62 ---*/ 63 64 var sym1 = Symbol(); 65 var sym2 = Symbol(); 66 class C { 67 static a() { return 'A'; } 68 static [sym1]() { return 'B'; } 69 static c() { return 'C'; } 70 static [sym2]() { return 'D'; } 71 } 72 assert.sameValue(C.a(), 'A', "`C.a()` returns `'A'`. Defined as `static a() { return 'A'; }`"); 73 assert.sameValue(C[sym1](), 'B', "`C[sym1]()` returns `'B'`. Defined as `static [sym1]() { return 'B'; }`"); 74 assert.sameValue(C.c(), 'C', "`C.c()` returns `'C'`. Defined as `static c() { return 'C'; }`"); 75 assert.sameValue(C[sym2](), 'D', "`C[sym2]()` returns `'D'`. Defined as `static [sym2]() { return 'D'; }`"); 76 assert.compareArray( 77 Object.keys(C), 78 [] 79 ); 80 81 reportCompare(0, 0);