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