get-binding-value-idref-with-proxy-env.js (1570B)
1 // Copyright (C) 2024 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-object-environment-records-getbindingvalue-n-s 6 description: > 7 Lookups in proxy binding object for identifier reference. 8 info: | 9 9.1.1.2.1 HasBinding ( N ) 10 11 1. Let bindingObject be envRec.[[BindingObject]]. 12 2. Let foundBinding be ? HasProperty(bindingObject, N). 13 3. If foundBinding is false, return false. 14 ... 15 5. Let unscopables be ? Get(bindingObject, %Symbol.unscopables%). 16 ... 17 7. Return true. 18 19 9.1.1.2.6 GetBindingValue ( N, S ) 20 21 1. Let bindingObject be envRec.[[BindingObject]]. 22 2. Let value be ? HasProperty(bindingObject, N). 23 3. If value is false, then 24 a. If S is false, return undefined; otherwise throw a ReferenceError exception. 25 4. Return ? Get(bindingObject, N). 26 27 features: [Proxy, Reflect] 28 flags: [noStrict] 29 includes: [compareArray.js, proxyTrapsHelper.js] 30 ---*/ 31 32 var log = []; 33 34 // Environment contains referenced binding. 35 var env = { 36 Object, 37 }; 38 39 var proxy = new Proxy(env, allowProxyTraps({ 40 has(t, pk) { 41 log.push("has:" + String(pk)); 42 return Reflect.has(t, pk); 43 }, 44 get(t, pk, r) { 45 log.push("get:" + String(pk)); 46 return Reflect.get(t, pk, r); 47 }, 48 })); 49 50 with (proxy) { 51 Object; 52 } 53 54 assert.compareArray(log, [ 55 // HasBinding, step 2. 56 "has:Object", 57 58 // HasBinding, step 5. 59 "get:Symbol(Symbol.unscopables)", 60 61 // GetBindingValue, step 2. 62 "has:Object", 63 64 // GetBindingValue, step 4. 65 "get:Object", 66 ]); 67 68 reportCompare(0, 0);