Add [[GetOwnProperty]] tests

This commit is contained in:
Alexey Shvayka 2020-03-11 04:28:32 +02:00 committed by Rick Waldron
parent d46e72d95e
commit b9377e7b6d
3 changed files with 159 additions and 0 deletions

View File

@ -0,0 +1,46 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p
description: >
If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]]
call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
info: |
[[GetOwnProperty]] ( P )
[...]
5. Let target be O.[[ProxyTarget]].
6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
7. If trap is undefined, then
a. Return ? target.[[GetOwnProperty]](P).
includes: [propertyHelper.js]
features: [Proxy]
---*/
var stringTarget = new Proxy(new String("str"), {});
var stringProxy = new Proxy(stringTarget, {});
verifyProperty(stringProxy, "0", {
value: "s",
writable: false,
enumerable: true,
configurable: false,
});
verifyProperty(stringProxy, "length", {
value: 3,
writable: false,
enumerable: false,
configurable: false,
});
var functionTarget = new Proxy(function() {}, {});
var functionProxy = new Proxy(functionTarget, {});
verifyProperty(functionProxy, "prototype", {
writable: true,
enumerable: false,
configurable: false,
});

View File

@ -0,0 +1,62 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p
description: >
If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]]
call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
info: |
[[GetOwnProperty]] ( P )
[...]
5. Let target be O.[[ProxyTarget]].
6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
7. If trap is undefined, then
a. Return ? target.[[GetOwnProperty]](P).
includes: [propertyHelper.js]
features: [Proxy]
---*/
var plainObjectTarget = new Proxy({foo: 1}, {});
var plainObjectProxy = new Proxy(plainObjectTarget, {
getOwnPropertyDescriptor: null,
});
verifyProperty(plainObjectProxy, "bar", undefined);
verifyProperty(plainObjectProxy, "foo", {
value: 1,
writable: true,
enumerable: true,
configurable: true,
});
var fooDescriptor = {
get: function() {},
set: function(_value) {},
enumerable: false,
configurable: true,
};
var target = new Proxy({}, {
getOwnPropertyDescriptor: function(_target, key) {
if (key === "foo") {
return fooDescriptor;
}
},
deleteProperty: function(_target, key) {
if (key === "foo") {
fooDescriptor = undefined;
}
return true;
},
});
var proxy = new Proxy(target, {
getOwnPropertyDescriptor: null,
});
verifyProperty(proxy, "bar", undefined);
verifyProperty(proxy, "foo", fooDescriptor);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p
description: >
If "getOwnPropertyDescriptor" trap is null or undefined, [[GetOwnProperty]]
call is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
info: |
[[GetOwnProperty]] ( P )
[...]
5. Let target be O.[[ProxyTarget]].
6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
7. If trap is undefined, then
a. Return ? target.[[GetOwnProperty]](P).
includes: [propertyHelper.js]
features: [Proxy]
---*/
var arrayTarget = new Proxy([42], {});
var arrayProxy = new Proxy(arrayTarget, {
getOwnPropertyDescriptor: undefined,
});
verifyProperty(arrayProxy, "0", {
value: 42,
writable: true,
enumerable: true,
configurable: true,
});
verifyProperty(arrayProxy, "length", {
value: 1,
// writable: true,
enumerable: false,
configurable: false,
});
var regExpTarget = new Proxy(/(?:)/, {});
var regExpProxy = new Proxy(regExpTarget, {
getOwnPropertyDescriptor: undefined,
});
verifyProperty(regExpProxy, "lastIndex", {
value: 0,
writable: true,
enumerable: false,
configurable: false,
});