diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-boolean-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-boolean-return-false.js new file mode 100644 index 0000000000..0e7100cfc8 --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-boolean-return-false.js @@ -0,0 +1,20 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return false; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-null-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-null-return-false.js new file mode 100644 index 0000000000..c6ca59a135 --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-null-return-false.js @@ -0,0 +1,20 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return null; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-number-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-number-return-false.js new file mode 100644 index 0000000000..58380a602d --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-number-return-false.js @@ -0,0 +1,20 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return 0; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-string-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-string-return-false.js new file mode 100644 index 0000000000..9d3783668e --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-string-return-false.js @@ -0,0 +1,20 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return ""; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/boolean-trap-result-is-false-undefined-return-false.js b/test/built-ins/Proxy/set/boolean-trap-result-is-false-undefined-return-false.js new file mode 100644 index 0000000000..3d05404a97 --- /dev/null +++ b/test/built-ins/Proxy/set/boolean-trap-result-is-false-undefined-return-false.js @@ -0,0 +1,20 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 11. If booleanTrapResult is false, return false. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return undefined; + } +}; +var p = new Proxy(target, handler); + +assert.sameValue(Reflect.set(p, "attr", "foo"), false); diff --git a/test/built-ins/Proxy/set/call-parameters.js b/test/built-ins/Proxy/set/call-parameters.js new file mode 100644 index 0000000000..812333e924 --- /dev/null +++ b/test/built-ins/Proxy/set/call-parameters.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.9 +description: > + [[Set]] ( P, V, Receiver) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, + Receiver»)). + +---*/ + +var _target, _handler, _prop, _value, _receiver; +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + _handler = this; + _target = t; + _prop = prop; + _value = value; + _receiver = receiver; + return t[prop] = value; + } +}; +var p = new Proxy(target, handler); + +p.attr = "foo"; + +assert.sameValue(_handler, handler, "handler object as the trap context"); +assert.sameValue(_target, target, "first argument is the target object"); +assert.sameValue(_prop, "attr", "second argument is the property name"); +assert.sameValue(_value, "foo", "third argument is the new value"); +assert.sameValue(_receiver, p, "forth argument is the proxy object"); diff --git a/test/built-ins/Proxy/set/null-handler.js b/test/built-ins/Proxy/set/null-handler.js new file mode 100644 index 0000000000..3b20350858 --- /dev/null +++ b/test/built-ins/Proxy/set/null-handler.js @@ -0,0 +1,21 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 3. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.attr = 1; +}); + +assert.throws(TypeError, function() { + p.proxy['attr'] = 1; +}); diff --git a/test/built-ins/Proxy/set/return-is-abrupt.js b/test/built-ins/Proxy/set/return-is-abrupt.js new file mode 100644 index 0000000000..d4be173fb6 --- /dev/null +++ b/test/built-ins/Proxy/set/return-is-abrupt.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.9 +description: > + Trap returns abrupt. +info: > + [[Set]] ( P, V, Receiver) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, Receiver»)). + 10. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + set: function(t, prop, value, receiver) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.attr = "bar"; +}); + +assert.throws(Test262Error, function() { + p["attr"] = "bar"; +}); diff --git a/test/built-ins/Proxy/set/return-true-target-property-accessor-is-configurable-set-is-undefined.js b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-configurable-set-is-undefined.js new file mode 100644 index 0000000000..11f3563873 --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-configurable-set-is-undefined.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.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property accessor is + configurable and set is undefined. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: true, + set: undefined +}); + +assert(Reflect.set(p, "attr", "bar")); diff --git a/test/built-ins/Proxy/set/return-true-target-property-accessor-is-not-configurable.js b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-not-configurable.js new file mode 100644 index 0000000000..0277b54c18 --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-accessor-is-not-configurable.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.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property accessor is not + configurable and set is not undefined. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + set: function( value ) { + return value; + } +}); + +assert(Reflect.set(p, "attr", 1)); diff --git a/test/built-ins/Proxy/set/return-true-target-property-is-not-configurable.js b/test/built-ins/Proxy/set/return-true-target-property-is-not-configurable.js new file mode 100644 index 0000000000..0bd1f6328d --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-is-not-configurable.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.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property is not configurable + but writable. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: true, + value: 'foo' +}); + +assert(Reflect.set(p, "attr", 1)); diff --git a/test/built-ins/Proxy/set/return-true-target-property-is-not-writable.js b/test/built-ins/Proxy/set/return-true-target-property-is-not-writable.js new file mode 100644 index 0000000000..314d164ef0 --- /dev/null +++ b/test/built-ins/Proxy/set/return-true-target-property-is-not-writable.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.9 +description: > + [[Set]] ( P, V, Receiver) + + Returns true if trap returns true and target property is configurable + but not writable. +features: [Reflect] +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, "attr", { + configurable: true, + writable: false, + value: "foo" +}); + +assert(Reflect.set(p, "attr", "foo")); diff --git a/test/built-ins/Proxy/set/target-property-is-accessor-not-configurable-set-is-undefined.js b/test/built-ins/Proxy/set/target-property-is-accessor-not-configurable-set-is-undefined.js new file mode 100644 index 0000000000..32075bce31 --- /dev/null +++ b/test/built-ins/Proxy/set/target-property-is-accessor-not-configurable-set-is-undefined.js @@ -0,0 +1,36 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + Throws a TypeError when target property is an accessor not configurable and + and set is undefined. +info: > + 14. If targetDesc is not undefined, then + b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] is false, then + i. If targetDesc.[[Set]] is undefined, throw a TypeError exception. + +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + set: undefined +}); + +assert.throws(TypeError, function() { + p.attr = 'bar'; +}); + +assert.throws(TypeError, function() { + p['attr'] = 'bar'; +}); diff --git a/test/built-ins/Proxy/set/target-property-is-not-configurable-not-writable-not-equal-to-v.js b/test/built-ins/Proxy/set/target-property-is-not-configurable-not-writable-not-equal-to-v.js new file mode 100644 index 0000000000..4b1a9f919d --- /dev/null +++ b/test/built-ins/Proxy/set/target-property-is-not-configurable-not-writable-not-equal-to-v.js @@ -0,0 +1,38 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + Throws a TypeError when target property is not configurable neither writable + and its value is not strictly equal to V. +info: > + 14. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(V, targetDesc.[[Value]]) is false, throw a TypeError + exception. +---*/ + +var target = {}; +var handler = { + set: function(t, prop, value, receiver) { + return true; + } +}; +var p = new Proxy(target, handler); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 'foo' +}); + +assert.throws(TypeError, function() { + p.attr = 'bar'; +}); + +assert.throws(TypeError, function() { + p['attr'] = 'bar'; +}); diff --git a/test/built-ins/Proxy/set/trap-is-not-callable.js b/test/built-ins/Proxy/set/trap-is-not-callable.js new file mode 100644 index 0000000000..fb044e5be9 --- /dev/null +++ b/test/built-ins/Proxy/set/trap-is-not-callable.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.9 +description: > + Trap is not callable. +info: > + [[Set]] ( P, V, Receiver) + + 6. Let trap be GetMethod(handler, "set"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, { + set: {} +}); + +assert.throws(TypeError, function() { + p.attr = 1; +}); + +assert.throws(TypeError, function() { + p["attr"] = 1; +}); diff --git a/test/built-ins/Proxy/set/trap-is-undefined-no-property.js b/test/built-ins/Proxy/set/trap-is-undefined-no-property.js new file mode 100644 index 0000000000..f0b29b0ff8 --- /dev/null +++ b/test/built-ins/Proxy/set/trap-is-undefined-no-property.js @@ -0,0 +1,19 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 8. If trap is undefined, then return target.[[Set]](P, V, Receiver). + +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +p.attr = 2; + +assert.sameValue(target.attr, 2); diff --git a/test/built-ins/Proxy/set/trap-is-undefined.js b/test/built-ins/Proxy/set/trap-is-undefined.js new file mode 100644 index 0000000000..82399fa343 --- /dev/null +++ b/test/built-ins/Proxy/set/trap-is-undefined.js @@ -0,0 +1,21 @@ +// 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.9 +description: > + [[Set]] ( P, V, Receiver) + + 8. If trap is undefined, then return target.[[Set]](P, V, Receiver). + +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: undefined +}); + +p.attr = 1; + +assert.sameValue(target.attr, 1);