diff --git a/test/built-ins/Proxy/defineProperty/call-parameters.js b/test/built-ins/Proxy/defineProperty/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..82db233a1f00b99391131b9edf475d739456152b --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/call-parameters.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Trap is called with handler as context and parameters are target, P, and the + descriptor object. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 9. Let descObj be FromPropertyDescriptor(Desc). + 10. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, + descObj»)). + ... +---*/ + +var _handler, _target, _prop, _desc; +var target = {}; +var descriptor = { + configurable: true, + enumerable: true, + writable: true, + value: 1 +}; +var handler = { + defineProperty: function(t, prop, desc) { + _handler = this; + _target = t; + _prop = prop; + _desc = desc; + + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(p, "attr", descriptor); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); + +assert.sameValue( + Object.keys(_desc).length, 4, + "descriptor arg has the same amount of keys as given descriptor" +); + +assert(_desc.configurable); +assert(_desc.writable); +assert(_desc.enumerable); +assert.sameValue(_desc.value, 1); diff --git a/test/built-ins/Proxy/defineProperty/null-handler.js b/test/built-ins/Proxy/defineProperty/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..ffbf14733787daa65c7bafef2098efba6e587184 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/null-handler.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.defineProperty(p.proxy, "foo", { + configurable: true, + enumerable: true + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js b/test/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js new file mode 100644 index 0000000000000000000000000000000000000000..2e4699cbf6e65d74cd269b458d8ce758e36966bc --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/return-boolean-and-define-target.js @@ -0,0 +1,46 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + If a property has a corresponding target object property then applying the + Property Descriptor of the property to the target object using + [[DefineOwnProperty]] will not throw an exception. +features: [Reflect] +includes: [propertyHelper.js] +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return Object.defineProperty(t, prop, desc); + } +}); + +var result = Reflect.defineProperty(p, "attr", { + configurable: true, + enumerable: true, + writable: true, + value: 1 +}); + +assert.sameValue(result, true, "result === true"); + +verifyEqualTo(target, "attr", 1); +verifyWritable(target, "attr"); +verifyEnumerable(target, "attr"); +verifyConfigurable(target, "attr"); + +result = Reflect.defineProperty(p, "attr", { + configurable: false, + enumerable: false, + writable: false, + value: 2 +}); + +assert.sameValue(result, true, "result === true"); + +verifyEqualTo(target, "attr", 2); +verifyNotWritable(target, "attr"); +verifyNotEnumerable(target, "attr"); +verifyNotConfigurable(target, "attr"); diff --git a/test/built-ins/Proxy/defineProperty/return-is-abrupt.js b/test/built-ins/Proxy/defineProperty/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..ad5727ae0e509de22891bb424ef2f79607debe6f --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/return-is-abrupt.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Trap return is an abrupt. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 10. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, + descObj»)). + 11. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + defineProperty: function(t, prop, desc) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.defineProperty(p, "foo", {}); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js b/test/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..4c26d4c093d76e3f8b4304659260a49cf3a23cc5 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-configurable-desc-not-configurable.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc is not configurable and target property + descriptor is configurable and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + b. If settingConfigFalse is true and targetDesc.[[Configurable]] is + true, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.defineProperty(target, "foo", { + value: 1, + configurable: true +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1, + configurable: false + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js new file mode 100644 index 0000000000000000000000000000000000000000..8617001c6cdaa2f6389bbb8f42b4278093f4b627 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor-not-configurable-target.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc and target property descriptor are not + compatible and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc , + targetDesc) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.defineProperty(target, "foo", { + value: 1, + configurable: false +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1, + configurable: true + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..abc0c8665e5137877c14203c67f4673a82a3f596 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-not-compatible-descriptor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc and target property descriptor are not + compatible and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 20. Else targetDesc is not undefined, + a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc , + targetDesc) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.defineProperty(target, "foo", { + value: 1 +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 2 + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..c9c6f05be6a44bdac02223cadc2b772932fdd935 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-not-configurable-descriptor.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc is not configurable and target property + descriptor is undefined, and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 19. If targetDesc is undefined, then + ... + b. If settingConfigFalse is true, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + configurable: false + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..85df7c30aeaeb6d5711c834a7d3f9836d0fa5e3e --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/targetdesc-undefined-target-is-not-extensible.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if Desc is not configurable and target is not + extensible, and trap result is true. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 19. If targetDesc is undefined, then + a. If extensibleTarget is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return true; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", {}); +}); diff --git a/test/built-ins/Proxy/defineProperty/trap-is-not-callable.js b/test/built-ins/Proxy/defineProperty/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..115605a860c272e466977a01225b8fdc0eb726e2 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/trap-is-not-callable.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Throw a TypeError exception if trap is not callable. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 6. Let trap be GetMethod(handler, "defineProperty"). + ... + 7.3.9 GetMethod (O, P) + ... + 2. Let func be GetV(O, P). + 5. If IsCallable(func) is false, throw a TypeError exception. + ... +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: {} +}); + +assert.throws(TypeError, function() { + Object.defineProperty(p, "foo", { + value: 1 + }); +}); diff --git a/test/built-ins/Proxy/defineProperty/trap-is-undefined.js b/test/built-ins/Proxy/defineProperty/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..a7578da92a3f2c3bb39aa3f5ca10702d2d8a85da --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/trap-is-undefined.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Return target.[[DefineOwnProperty]](P, Desc) if trap is undefined. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 8. If trap is undefined, then + a. Return target.[[DefineOwnProperty]](P, Desc). + ... +includes: [propertyHelper.js] +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +Object.defineProperty(p, "attr", { + configurable: true, + enumerable: true, + writable: true, + value: 1 +}); + +verifyEqualTo(target, "attr", 1); +verifyWritable(target, "attr"); +verifyEnumerable(target, "attr"); +verifyConfigurable(target, "attr"); + +Object.defineProperty(p, "attr", { + configurable: false, + enumerable: false, + writable: false, + value: 2 +}); + +verifyEqualTo(target, "attr", 2); +verifyNotWritable(target, "attr"); +verifyNotEnumerable(target, "attr"); +verifyNotConfigurable(target, "attr"); diff --git a/test/built-ins/Proxy/defineProperty/trap-return-is-false.js b/test/built-ins/Proxy/defineProperty/trap-return-is-false.js new file mode 100644 index 0000000000000000000000000000000000000000..3481dbb57bd7904aafebae0271f14c06f70e8616 --- /dev/null +++ b/test/built-ins/Proxy/defineProperty/trap-return-is-false.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.5.6 +description: > + Trap returns a boolean. Checking on false values. +info: > + [[DefineOwnProperty]] (P, Desc) + + ... + 12. If booleanTrapResult is false, return false. + ... +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + defineProperty: function(t, prop, desc) { + return 0; + } +}); + +assert.sameValue(Reflect.defineProperty(p, "attr", {}), false); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +);