private-method-visible-to-direct-eval-on-initializer.js (1913B)
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 is visible on initializer with direct eval 6 esid: sec-privatefieldget 7 info: | 8 PrivateFieldGet (P, O) 9 1. Assert: P is a Private Name. 10 2. If O is not an object, throw a TypeError exception. 11 3. If P.[[Kind]] is "field", 12 a. Let entry be PrivateFieldFind(P, O). 13 b. If entry is empty, throw a TypeError exception. 14 c. Return entry.[[PrivateFieldValue]]. 15 4. Perform ? PrivateBrandCheck(O, P). 16 5. If P.[[Kind]] is "method", 17 a. Return P.[[Value]]. 18 6. Else, 19 a. Assert: P.[[Kind]] is "accessor". 20 b. If P does not have a [[Get]] field, throw a TypeError exception. 21 c. Let getter be P.[[Get]]. 22 d. Return ? Call(getter, O). 23 24 ClassElementName : PrivateIdentifier 25 1. Let privateIdentifier be StringValue of PrivateIdentifier. 26 2. Let privateName be NewPrivateName(privateIdentifier). 27 3. Let scope be the running execution context's PrivateEnvironment. 28 4. Let scopeEnvRec be scope's EnvironmentRecord. 29 5. Perform ! scopeEnvRec.InitializeBinding(privateIdentifier, privateName). 30 6. Return privateName. 31 32 MakePrivateReference ( baseValue, privateIdentifier ) 33 1. Let env be the running execution context's PrivateEnvironment. 34 2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env). 35 3. Let privateName be GetValue(privateNameBinding). 36 4. Assert: privateName is a Private Name. 37 5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true. 38 features: [class-methods-private, class-fields-public, class] 39 ---*/ 40 41 class C { 42 #m() { return "Test262"; }; 43 v = eval("this.#m()"); 44 } 45 46 let c = new C(); 47 assert.sameValue(c.v, "Test262"); 48 49 reportCompare(0, 0);