mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 04:24:40 +02:00
Add [[DefineOwnProperty]] tests
This commit is contained in:
parent
2c432e35b2
commit
6b9929a31d
@ -0,0 +1,48 @@
|
|||||||
|
// 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-defineownproperty-p-desc
|
||||||
|
description: >
|
||||||
|
If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call
|
||||||
|
is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
|
||||||
|
info: |
|
||||||
|
[[DefineOwnProperty]] (P, Desc)
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. Let target be O.[[ProxyTarget]].
|
||||||
|
6. Let trap be ? GetMethod(handler, "defineProperty").
|
||||||
|
7. If trap is undefined, then
|
||||||
|
a. Return ? target.[[DefineOwnProperty]](P, Desc).
|
||||||
|
features: [Proxy, Reflect]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var string = new String("str");
|
||||||
|
var stringTarget = new Proxy(string, {});
|
||||||
|
var stringProxy = new Proxy(stringTarget, {});
|
||||||
|
|
||||||
|
assert(Reflect.defineProperty(stringProxy, "4", {value: 4}));
|
||||||
|
assert.sameValue(string[4], 4);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(stringProxy, "0", {
|
||||||
|
value: "x",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.preventExtensions(string);
|
||||||
|
assert(!Reflect.defineProperty(stringProxy, "foo", {value: 5}));
|
||||||
|
|
||||||
|
|
||||||
|
var func = function() {};
|
||||||
|
var funcTarget = new Proxy(func, {});
|
||||||
|
var funcProxy = new Proxy(funcTarget, {});
|
||||||
|
|
||||||
|
Object.defineProperty(funcProxy, "name", {value: "foo"});
|
||||||
|
assert.sameValue(func.name, "foo");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(funcProxy, "prototype", {
|
||||||
|
set: function(_value) {},
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,57 @@
|
|||||||
|
// 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-defineownproperty-p-desc
|
||||||
|
description: >
|
||||||
|
If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call
|
||||||
|
is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
|
||||||
|
info: |
|
||||||
|
[[DefineOwnProperty]] (P, Desc)
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. Let target be O.[[ProxyTarget]].
|
||||||
|
6. Let trap be ? GetMethod(handler, "defineProperty").
|
||||||
|
7. If trap is undefined, then
|
||||||
|
a. Return ? target.[[DefineOwnProperty]](P, Desc).
|
||||||
|
features: [Proxy, Reflect]
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var plainObject = Object.create(null);
|
||||||
|
Object.defineProperty(plainObject, "foo", {
|
||||||
|
configurable: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
var plainObjectTarget = new Proxy(plainObject, {});
|
||||||
|
var plainObjectProxy = new Proxy(plainObjectTarget, {
|
||||||
|
defineProperty: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(plainObjectProxy, "foo", {
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(plainObjectProxy, "bar", {
|
||||||
|
get: function() {
|
||||||
|
return 2;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
assert.sameValue(plainObject.bar, 2);
|
||||||
|
|
||||||
|
|
||||||
|
var regExp = /(?:)/g;
|
||||||
|
var regExpTarget = new Proxy(regExp, {});
|
||||||
|
var regExpProxy = new Proxy(regExpTarget, {
|
||||||
|
defineProperty: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(
|
||||||
|
Reflect.defineProperty(regExpProxy, "lastIndex", {
|
||||||
|
writable: false,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotWritable(regExp, "lastIndex");
|
@ -0,0 +1,55 @@
|
|||||||
|
// 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-defineownproperty-p-desc
|
||||||
|
description: >
|
||||||
|
If "defineProperty" trap is null or undefined, [[DefineOwnProperty]] call
|
||||||
|
is properly forwarded to [[ProxyTarget]] (which is also a Proxy object).
|
||||||
|
info: |
|
||||||
|
[[DefineOwnProperty]] (P, Desc)
|
||||||
|
|
||||||
|
[...]
|
||||||
|
5. Let target be O.[[ProxyTarget]].
|
||||||
|
6. Let trap be ? GetMethod(handler, "defineProperty").
|
||||||
|
7. If trap is undefined, then
|
||||||
|
a. Return ? target.[[DefineOwnProperty]](P, Desc).
|
||||||
|
features: [Proxy, Reflect]
|
||||||
|
includes: [compareArray.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var array = [];
|
||||||
|
var arrayTarget = new Proxy(array, {});
|
||||||
|
var arrayProxy = new Proxy(arrayTarget, {
|
||||||
|
defineProperty: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(arrayProxy, "0", {value: 1});
|
||||||
|
assert.compareArray(array, [1]);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(arrayProxy, "length", {
|
||||||
|
get: function() {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var trapCalls = 0;
|
||||||
|
var target = new Proxy({}, {
|
||||||
|
defineProperty: function(_target, key) {
|
||||||
|
trapCalls++;
|
||||||
|
return key === "foo";
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
var proxy = new Proxy(target, {
|
||||||
|
defineProperty: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(Reflect.defineProperty(proxy, "foo", {}));
|
||||||
|
assert.sameValue(trapCalls, 1);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(proxy, "bar", {});
|
||||||
|
});
|
||||||
|
assert.sameValue(trapCalls, 2);
|
Loading…
x
Reference in New Issue
Block a user