set-mutable-binding-idref-compound-assign-with-proxy-env.js (2643B)
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-setmutablebinding-n-v-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 9.1.1.2.5 SetMutableBinding ( N, V, S ) 28 29 1. Let bindingObject be envRec.[[BindingObject]]. 30 2. Let stillExists be ? HasProperty(bindingObject, N). 31 ... 32 4. Perform ? Set(bindingObject, N, V, S). 33 ... 34 35 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) 36 37 ... 38 2. If IsDataDescriptor(ownDesc) is true, then 39 ... 40 c. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P). 41 d. If existingDescriptor is not undefined, then 42 ... 43 iv. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc). 44 ... 45 46 features: [Proxy, Reflect] 47 flags: [noStrict] 48 includes: [compareArray.js, proxyTrapsHelper.js] 49 ---*/ 50 51 var log = []; 52 53 // Environment contains referenced binding. 54 var env = { 55 p: 0, 56 }; 57 58 var proxy = new Proxy(env, allowProxyTraps({ 59 has(t, pk) { 60 log.push("has:" + String(pk)); 61 return Reflect.has(t, pk); 62 }, 63 get(t, pk, r) { 64 log.push("get:" + String(pk)); 65 return Reflect.get(t, pk, r); 66 }, 67 set(t, pk, v, r) { 68 log.push("set:" + String(pk)); 69 return Reflect.set(t, pk, v, r); 70 }, 71 getOwnPropertyDescriptor(t, pk) { 72 log.push("getOwnPropertyDescriptor:" + String(pk)); 73 return Reflect.getOwnPropertyDescriptor(t, pk); 74 }, 75 defineProperty(t, pk, d) { 76 log.push("defineProperty:" + String(pk)); 77 return Reflect.defineProperty(t, pk, d); 78 }, 79 })); 80 81 with (proxy) { 82 p += 1; 83 } 84 85 assert.compareArray(log, [ 86 // HasBinding, step 2. 87 "has:p", 88 89 // HasBinding, step 5. 90 "get:Symbol(Symbol.unscopables)", 91 92 // GetBindingValue, step 2. 93 "has:p", 94 95 // GetBindingValue, step 4. 96 "get:p", 97 98 // SetMutableBinding, step 2. 99 "has:p", 100 101 // SetMutableBinding, step 4. 102 "set:p", 103 "getOwnPropertyDescriptor:p", 104 "defineProperty:p", 105 ]); 106 107 reportCompare(0, 0);