super-access-inside-a-private-method.js (1711B)
1 // Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: Private method contains proper HomeObject 6 esid: sec-method-definitions-runtime-semantics-classelementevaluation 7 info: | 8 MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } 9 1. Let methodDef be DefineMethod of MethodDefinition with argument homeObject. 10 2. ReturnIfAbrupt(methodDef). 11 3. Perform ? DefineOrdinaryMethod(methodDef.[[Key]], homeObject, methodDef.[[Closure]], _enumerable). 12 13 MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } 14 1. Let propKey be the result of evaluating PropertyName. 15 2. ReturnIfAbrupt(propKey). 16 3. Let scope be the running execution context's LexicalEnvironment. 17 4. If functionPrototype is present as a parameter, then 18 a. Let kind be Normal. 19 b. Let prototype be functionPrototype. 20 5. Else, 21 a. Let kind be Method. 22 b. Let prototype be the intrinsic object %FunctionPrototype%. 23 6. Let closure be FunctionCreate(kind, UniqueFormalParameters, FunctionBody, scope, prototype). 24 7. Perform MakeMethod(closure, object). 25 8. Set closure.[[SourceText]] to the source text matched by MethodDefinition. 26 9. Return the Record { [[Key]]: propKey, [[Closure]]: closure }. 27 features: [class-methods-private, class] 28 ---*/ 29 30 class A { 31 method() { 32 return "Test262"; 33 } 34 } 35 36 class C extends A { 37 #m() { 38 return super.method(); 39 } 40 41 access(o) { 42 return this.#m.call(o); 43 } 44 } 45 46 let c = new C(); 47 assert.sameValue(c.access(c), "Test262"); 48 49 let o = {}; 50 assert.sameValue(c.access(o), "Test262"); 51 52 reportCompare(0, 0);