static-private-getter.js (1822B)
1 // This file was procedurally generated from the following sources: 2 // - src/class-elements/static-private-getter.case 3 // - src/class-elements/default/cls-decl.template 4 /*--- 5 description: static private getter declaration and usage (field definitions in a class declaration) 6 esid: prod-FieldDefinition 7 features: [class-static-methods-private, class] 8 flags: [generated] 9 info: | 10 MethodDefinition : 11 get ClassElementName () { FunctionBody } 12 set ClassElementName ( PropertySetParameterList ) { FunctionBody } 13 14 ClassTail : ClassHeritage { ClassBody } 15 ... 16 33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, 17 a. PrivateBrandAdd(F, F). 18 34. For each item fieldRecord in order from staticFields, 19 a. Perform ? DefineField(F, field). 20 21 PrivateFieldGet (P, O) 22 1. Assert: P is a Private Name. 23 2. If O is not an object, throw a TypeError exception. 24 3. If P.[[Kind]] is "field", 25 ... 26 4. Perform ? PrivateBrandCheck(O, P). 27 5. If P.[[Kind]] is "method", 28 ... 29 6. Else, 30 a. Assert: P.[[Kind]] is "accessor". 31 b. If P does not have a [[Get]] field, throw a TypeError exception. 32 c. Let getter be P.[[Get]]. 33 d. Return ? Call(getter, O). 34 35 PrivateBrandCheck(O, P) 36 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, 37 a. Throw a TypeError exception. 38 39 ---*/ 40 41 42 class C { 43 static get #f() { 44 return 'Test262'; 45 } 46 47 static access() { 48 return this.#f; 49 } 50 } 51 52 assert.sameValue(C.access(), 'Test262'); 53 assert.throws(TypeError, function() { 54 C.access.call({}); 55 }, 'Accessed static private getter from an arbitrary object'); 56 57 reportCompare(0, 0);