diff --git a/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js b/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..15a3cebd1ba643e85964b4d2b1d0c4e5808a916b --- /dev/null +++ b/test/built-ins/Proxy/get/accessor-get-is-undefined-throws.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.8 +description: > + [[Get]] (P, Receiver) + + if trap result is not undefined, then proxy must report the same value for a + non-configurable accessor property with an undefined get. +info: > + 13. If targetDesc is not undefined, then + b. If IsAccessorDescriptor(targetDesc) and targetDesc.[[Configurable]] + is false and targetDesc.[[Get]] is undefined, then + i. If trapResult is not undefined, throw a TypeError exception. + +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + get: undefined +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); diff --git a/test/built-ins/Proxy/get/call-parameters.js b/test/built-ins/Proxy/get/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..55f7e71fcf675221bb471390d0a6d1a08a25afab --- /dev/null +++ b/test/built-ins/Proxy/get/call-parameters.js @@ -0,0 +1,41 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). +info: > + 6.1.7.2 Object Internal Methods and Internal Slots + + (...) Receiver is used as the this value when evaluating the code +---*/ + +var _target, _handler, _prop, _receiver; +var target = { + attr: 1 +}; +var handler = { + get: function(t, prop, receiver) { + _handler = this; + _target = t; + _prop = prop; + _receiver = receiver; + } +}; +var p = new Proxy(target, handler); + +p.attr; + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_prop, "attr"); +assert.sameValue(_receiver, p, "receiver is the Proxy object"); + +_prop = null; +p["attr"]; +assert.sameValue( + _prop, "attr", + "trap is triggered both by p.attr and p['attr']" +); diff --git a/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js b/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..97eff7da68235b21ff2c4967126a11264218360d --- /dev/null +++ b/test/built-ins/Proxy/get/not-same-value-configurable-false-writable-false-throws.js @@ -0,0 +1,37 @@ +// 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.8 +description: > + Throws if proxy return has not the same value for a non-writable, + non-configurable property +info: > + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p['attr']; +}); diff --git a/test/built-ins/Proxy/get/null-handler.js b/test/built-ins/Proxy/get/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..82dc3a187c986cddee2587c9b1ac509a1160cbcd --- /dev/null +++ b/test/built-ins/Proxy/get/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.8 +description: > + [[Get]] (P, Receiver) + + 2. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + p.proxy.attr; +}); + +assert.throws(TypeError, function() { + p.proxy['attr']; +}); diff --git a/test/built-ins/Proxy/get/return-is-abrupt.js b/test/built-ins/Proxy/get/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..ea6a7c4bb598c76684fd99f50679252ddedd7e21 --- /dev/null +++ b/test/built-ins/Proxy/get/return-is-abrupt.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.8 +description: > + Trap returns abrupt. +info: > + [[Get]] (P, Receiver) + + 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). + 10. ReturnIfAbrupt(trapResult). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + p.attr; +}); + +assert.throws(Test262Error, function() { + p["attr"]; +}); diff --git a/test/built-ins/Proxy/get/return-trap-result-accessor-property.js b/test/built-ins/Proxy/get/return-trap-result-accessor-property.js new file mode 100644 index 0000000000000000000000000000000000000000..560bd56506f4d9492ee03af69faa309552578ffc --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-accessor-property.js @@ -0,0 +1,25 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + get: function() { + return 1; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js b/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js new file mode 100644 index 0000000000000000000000000000000000000000..46ddaeff0b3abf4bedf1d7efb9a8658edc3069cf --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-configurable-false-writable-true.js @@ -0,0 +1,25 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: true, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js b/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..930265b6e6b39bd33dbcfe3e2e9a366a0e86b984 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-configurable-true-assessor-get-undefined.js @@ -0,0 +1,24 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + get: undefined +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js b/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js new file mode 100644 index 0000000000000000000000000000000000000000..1ad1eca0a657b2d67701ec6b97dad3c962d30c82 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-configurable-true-writable-false.js @@ -0,0 +1,25 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: true, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p['attr'], 2); diff --git a/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js b/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js new file mode 100644 index 0000000000000000000000000000000000000000..bec57837e9cc1061be5c31e3740a7224f8e88117 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result-same-value-configurable-false-writable-false.js @@ -0,0 +1,34 @@ +// 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.8 +description: > + Proxy must report the same value for a non-writable, non-configurable + property. +info: > + [[Get]] (P, Receiver) + + 13. If targetDesc is not undefined, then + a. If IsDataDescriptor(targetDesc) and targetDesc.[[Configurable]] is + false and targetDesc.[[Writable]] is false, then + i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a + TypeError exception. + ... + 14. Return trapResult. +---*/ + +var target = {}; +var p = new Proxy(target, { + get: function() { + return 1; + } +}); + +Object.defineProperty(target, 'attr', { + configurable: false, + writable: false, + value: 1 +}); + +assert.sameValue(p.attr, 1); +assert.sameValue(p['attr'], 1); diff --git a/test/built-ins/Proxy/get/return-trap-result.js b/test/built-ins/Proxy/get/return-trap-result.js new file mode 100644 index 0000000000000000000000000000000000000000..d045e1492763d02fb2db383123ddee8f9c60a009 --- /dev/null +++ b/test/built-ins/Proxy/get/return-trap-result.js @@ -0,0 +1,24 @@ +// 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.8 +description: > + [[Get]] (P, Receiver) + + 14. Return trapResult. +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: function() { + return 2; + } +}); + +assert.sameValue(p.attr, 2); +assert.sameValue(p.foo, 2); + +assert.sameValue(p['attr'], 2); +assert.sameValue(p['foo'], 2); diff --git a/test/built-ins/Proxy/get/trap-is-not-callable.js b/test/built-ins/Proxy/get/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..9ea5caed59563e3f854187f9399a693792bf184b --- /dev/null +++ b/test/built-ins/Proxy/get/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.8 +description: > + Trap is not callable. +info: > + [[Get]] (P, Receiver) + + 6. Let trap be GetMethod(handler, "get"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, { + get: {} +}); + +assert.throws(TypeError, function() { + p.attr; +}); + +assert.throws(TypeError, function() { + p["attr"]; +}); diff --git a/test/built-ins/Proxy/get/trap-is-undefined-no-property.js b/test/built-ins/Proxy/get/trap-is-undefined-no-property.js new file mode 100644 index 0000000000000000000000000000000000000000..c9d107f5926b9996b76b2ed2cb8ea140ddee0811 --- /dev/null +++ b/test/built-ins/Proxy/get/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.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo'); +assert.sameValue(p['attr'], 1, 'return target.attr'); +assert.sameValue(p['foo'], undefined, 'return target.foo'); diff --git a/test/built-ins/Proxy/get/trap-is-undefined.js b/test/built-ins/Proxy/get/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..4c2257aa612e4cea51c002276fe46eb7be9e3947 --- /dev/null +++ b/test/built-ins/Proxy/get/trap-is-undefined.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.8 +description: > + [[Get]] (P, Receiver) + + 8. If trap is undefined, then return target.[[Get]](P, Receiver). + +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, { + get: undefined +}); + +assert.sameValue(p.attr, 1, 'return target.attr'); +assert.sameValue(p.foo, undefined, 'return target.foo');