Add tests for Proxy semantics change (#2143)

* Add not extensible target test for `deleteProperty`

* Add non-writable descriptor test for `defineProperty`

* Add non-writable descriptor test for `getOwnPropertyDescriptor`
This commit is contained in:
Aleksey Shvayka 2019-05-03 16:21:48 +02:00 committed by Leo Balter
parent d47749e84d
commit 4d33170d0e
3 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,40 @@
// Copyright (C) 2019 Aleksey 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: >
Throw a TypeError exception if trap result is true, targetDesc is not configurable
and writable, while Desc is not writable.
info: |
[[DefineOwnProperty]] (P, Desc)
...
16. Else targetDesc is not undefined,
...
c. If IsDataDescriptor(targetDesc) is true, targetDesc.[[Configurable]] is
false, and targetDesc.[[Writable]] is true, then
i. If Desc has a [[Writable]] field and Desc.[[Writable]] is
false, throw a TypeError exception.
...
features: [Proxy, Reflect]
---*/
var trapCalls = 0;
var p = new Proxy({}, {
defineProperty: function(t, prop, desc) {
Object.defineProperty(t, prop, {
configurable: false,
writable: true,
});
trapCalls++;
return true;
},
});
assert.throws(TypeError, function() {
Reflect.defineProperty(p, "prop", {
writable: false,
});
});
assert.sameValue(trapCalls, 1);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2019 Aleksey 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-delete-p
description: >
Throw a TypeError exception if trap result is true, targetDesc is configurable,
and target is not extensible.
info: |
[[Delete]] (P)
...
13. Let extensibleTarget be ? IsExtensible(target).
14. If extensibleTarget is false, throw a TypeError exception.
...
features: [Proxy, Reflect]
---*/
var trapCalls = 0;
var p = new Proxy({prop: 1}, {
deleteProperty: function(t, prop) {
Object.preventExtensions(t);
trapCalls++;
return true;
},
});
assert.throws(TypeError, function() {
Reflect.deleteProperty(p, "prop");
});
assert.sameValue(trapCalls, 1);
assert(Reflect.deleteProperty(p, "nonExistent"));
assert.sameValue(trapCalls, 2);

View File

@ -0,0 +1,40 @@
// Copyright (C) 2019 Aleksey 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: >
Throws a TypeError exception if resultDesc is both non-configurable and
non-writable, while targetDesc is writable.
info: |
[[GetOwnProperty]] (P)
...
17. If resultDesc.[[Configurable]] is false, then
...
b. If resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is
false, then
i. If targetDesc.[[Writable]] is true, throw a TypeError exception.
...
features: [Proxy]
---*/
var trapCalls = 0;
var p = new Proxy({}, {
getOwnPropertyDescriptor: function(t, prop) {
Object.defineProperty(t, prop, {
configurable: false,
writable: true,
});
trapCalls++;
return {
configurable: false,
writable: false,
};
},
});
assert.throws(TypeError, function() {
Object.getOwnPropertyDescriptor(p, "prop");
});
assert.sameValue(trapCalls, 1);