diff --git a/test/built-ins/Proxy/setPrototypeOf/boolean-trap-result-extensible-target.js b/test/built-ins/Proxy/setPrototypeOf/boolean-trap-result-extensible-target.js new file mode 100644 index 0000000000000000000000000000000000000000..6365345c489f29ea2f94d8e3c80ecb1092e55f6f --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/boolean-trap-result-extensible-target.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.2 +description: > + Return a boolean trap result if target is extensible. +info: > + [[SetPrototypeOf]] (V) + + ... + 13. If extensibleTarget is true, return booleanTrapResult. + ... +flags: [onlyStrict] +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return v.attr; + } +}); + +var result = Reflect.setPrototypeOf(p, { attr: 0 }); +assert.sameValue(result, false); + +result = Reflect.setPrototypeOf(p, { attr: 1 }); +assert.sameValue(result, true); diff --git a/test/built-ins/Proxy/setPrototypeOf/call-parameters.js b/test/built-ins/Proxy/setPrototypeOf/call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..e62aa54869e75343e818e29ec9c2241b5e115ce9 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/call-parameters.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.2 +description: > + Trap is called with handler on its context, first parameter is target and + second parameter is the given value. +info: > + [[SetPrototypeOf]] (V) + + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). + ... +---*/ + +var _handler, _target, _value; +var target = {}; +var val = {foo: 1}; +var handler = { + setPrototypeOf: function(t, v) { + _handler = this; + _target = t; + _value = v; + + Object.setPrototypeOf(t, v); + + return true; + } +}; +var p = new Proxy(target, handler); + +Object.setPrototypeOf(p, val); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); +assert.sameValue(_value, val); diff --git a/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-not-same-target-prototype.js b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-not-same-target-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..8d015b8703a87de83ece783ae07261a90bc0c312 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-not-same-target-prototype.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.2 +description: > + Throws a TypeError exception if boolean trap result is true, target is + not extensible, and the given parameter is not the same object as the target + prototype. +info: > + [[SetPrototypeOf]] (V) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "setPrototypeOf"). + ... + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). + 14. Let targetProto be target.[[GetPrototypeOf]](). + 15. ReturnIfAbrupt(targetProto). + 16. If booleanTrapResult is true and SameValue(V, targetProto) is false, + throw a TypeError exception. + ... + +---*/ + +var target = {}; +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return true; + } +}); + +Object.preventExtensions(target); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(p, {}); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-same-target-prototype.js b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-same-target-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..8af42c56a3f1ab025eab14e79f6c49027e9e0492 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/not-extensible-target-same-target-prototype.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.2 +description: > + Return true if boolean trap result is true, target is not extensible, and + given parameter is the same as target prototype. +features: [Reflect] +---*/ + +var target = Object.create(Array.prototype); +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return true; + } +}); + +Object.preventExtensions(target); + +assert(Reflect.setPrototypeOf(p, Array.prototype)); diff --git a/test/built-ins/Proxy/setPrototypeOf/not-extensible-trap-is-false-return-false.js b/test/built-ins/Proxy/setPrototypeOf/not-extensible-trap-is-false-return-false.js new file mode 100644 index 0000000000000000000000000000000000000000..59a26338793ec0ef9300cfe1a4337dc3e086e52c --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/not-extensible-trap-is-false-return-false.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.2 +description: > + Return false if boolean trap result is false. +features: [Reflect] +---*/ + +var target = []; +var p = new Proxy(target, { + setPrototypeOf: function(t, v) { + return false; + } +}); + +Object.preventExtensions(target); + +assert.sameValue(Reflect.setPrototypeOf(p, {}), false); diff --git a/test/built-ins/Proxy/setPrototypeOf/null-handler.js b/test/built-ins/Proxy/setPrototypeOf/null-handler.js new file mode 100644 index 0000000000000000000000000000000000000000..4d4a7a6b6897b0b7836cda3efdfe2ad47342b9ef --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/null-handler.js @@ -0,0 +1,15 @@ +// 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.2 +description: > + Throws a TypeError exception if handler is null +---*/ + +var p = Proxy.revocable({},{}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(p.proxy, {}); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/return-is-abrupt.js b/test/built-ins/Proxy/setPrototypeOf/return-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..9675507370d72781ec36785417236835f7c2ab90 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/return-is-abrupt.js @@ -0,0 +1,23 @@ +// 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.2 +description: > + Trap returns abrupt. +info: > + [[SetPrototypeOf]] (V) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). + 10. ReturnIfAbrupt(booleanTrapResult). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + setPrototypeOf: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.setPrototypeOf(p, {value: 1}); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/trap-is-not-callable.js b/test/built-ins/Proxy/setPrototypeOf/trap-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..a6e77ed1238e36eb341177407c6d74e4bee14019 --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/trap-is-not-callable.js @@ -0,0 +1,32 @@ +// 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.2 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[SetPrototypeOf]] (V) + + ... + 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let target be the value of the [[ProxyTarget]] internal slot of O. + 6. Let trap be GetMethod(handler, "setPrototypeOf"). + ... + 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, { + setPrototypeOf: {} +}); + +assert.throws(TypeError, function() { + Object.setPrototypeOf(p, { + value: 1 + }); +}); diff --git a/test/built-ins/Proxy/setPrototypeOf/trap-is-undefined.js b/test/built-ins/Proxy/setPrototypeOf/trap-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..1dc0ef324f2882c110754a0976e9f2fdef5f013e --- /dev/null +++ b/test/built-ins/Proxy/setPrototypeOf/trap-is-undefined.js @@ -0,0 +1,14 @@ +// 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.2 +description: > + Return target.[[SetPrototypeOf]] (V) if trap is undefined. +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +Object.setPrototypeOf(p, {attr: 1}); + +assert.sameValue(target.attr, 1);