| 1 |
// Copyright (C) 2020 Alexey Shvayka. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p |
| 6 |
description: > |
| 7 |
If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]] |
| 8 |
call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object). |
| 9 |
info: | |
| 10 |
[[GetOwnProperty]] ( P ) |
| 11 |
|
| 12 |
[...] |
| 13 |
5. Let target be O.[[ProxyTarget]]. |
| 14 |
6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor"). |
| 15 |
7. If trap is undefined, then |
| 16 |
a. Return ? target.[[GetOwnProperty]](P). |
| 17 |
includes: [propertyHelper.js] |
| 18 |
features: [Proxy] |
| 19 |
---*/ |
| 20 |
|
| 21 |
var plainObjectTarget = new Proxy({foo: 1}, {}); |
| 22 |
var plainObjectProxy = new Proxy(plainObjectTarget, { |
| 23 |
getOwnPropertyDescriptor: null, |
| 24 |
}); |
| 25 |
|
| 26 |
verifyProperty(plainObjectProxy, "bar", undefined); |
| 27 |
verifyProperty(plainObjectProxy, "foo", { |
| 28 |
value: 1, |
| 29 |
writable: true, |
| 30 |
enumerable: true, |
| 31 |
configurable: true, |
| 32 |
}); |
| 33 |
|
| 34 |
|
| 35 |
var fooDescriptor = { |
| 36 |
get: function() {}, |
| 37 |
set: function(_value) {}, |
| 38 |
enumerable: false, |
| 39 |
configurable: true, |
| 40 |
}; |
| 41 |
|
| 42 |
var target = new Proxy({}, { |
| 43 |
getOwnPropertyDescriptor: function(_target, key) { |
| 44 |
if (key === "foo") { |
| 45 |
return fooDescriptor; |
| 46 |
} |
| 47 |
}, |
| 48 |
deleteProperty: function(_target, key) { |
| 49 |
if (key === "foo") { |
| 50 |
fooDescriptor = undefined; |
| 51 |
} |
| 52 |
|
| 53 |
return true; |
| 54 |
}, |
| 55 |
}); |
| 56 |
|
| 57 |
var proxy = new Proxy(target, { |
| 58 |
getOwnPropertyDescriptor: null, |
| 59 |
}); |
| 60 |
|
| 61 |
verifyProperty(proxy, "bar", undefined); |
| 62 |
verifyProperty(proxy, "foo", fooDescriptor); |
| 63 |
|
| 64 |
reportCompare(0, 0); |