From 79a256cd5a65633d6717a9a0fb4b22673f2cf744 Mon Sep 17 00:00:00 2001 From: Leonardo Balter <leonardo.balter@gmail.com> Date: Tue, 2 Jun 2015 18:39:27 -0400 Subject: [PATCH] Proxy: preventExtensions --- .../preventExtensions/call-parameters.js | 31 +++++++++++++++++++ .../Proxy/preventExtensions/null-handler.js | 15 +++++++++ .../Proxy/preventExtensions/return-false.js | 21 +++++++++++++ .../preventExtensions/return-is-abrupt.js | 25 +++++++++++++++ .../return-true-target-is-extensible.js | 27 ++++++++++++++++ .../return-true-target-is-not-extensible.js | 19 ++++++++++++ .../preventExtensions/trap-is-not-callable.js | 29 +++++++++++++++++ .../preventExtensions/trap-is-undefined.js | 13 ++++++++ 8 files changed, 180 insertions(+) create mode 100644 test/built-ins/Proxy/preventExtensions/call-parameters.js create mode 100644 test/built-ins/Proxy/preventExtensions/null-handler.js create mode 100644 test/built-ins/Proxy/preventExtensions/return-false.js create mode 100644 test/built-ins/Proxy/preventExtensions/return-is-abrupt.js create mode 100644 test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js create mode 100644 test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js create mode 100644 test/built-ins/Proxy/preventExtensions/trap-is-not-callable.js create mode 100644 test/built-ins/Proxy/preventExtensions/trap-is-undefined.js diff --git a/test/built-ins/Proxy/preventExtensions/call-parameters.js b/test/built-ins/Proxy/preventExtensions/call-parameters.js new file mode 100644 index 0000000000..16007d3980 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/call-parameters.js @@ -0,0 +1,31 @@ +// 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.4 +description: > + Trap is called with handler on its context and target as the first + parameter. +info: > + [[PreventExtensions]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + ... +---*/ + +var _target, _handler; +var target = {}; +var handler = { + preventExtensions: function(t) { + _handler = this; + _target = t; + + return Object.preventExtensions(target); + } +}; +var p = new Proxy(target, handler); + +Object.preventExtensions(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/preventExtensions/null-handler.js b/test/built-ins/Proxy/preventExtensions/null-handler.js new file mode 100644 index 0000000000..12b7ee8657 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/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.4 +description: > + Throws a TypeError exception if handler is null. +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.preventExtensions(p.proxy); +}); diff --git a/test/built-ins/Proxy/preventExtensions/return-false.js b/test/built-ins/Proxy/preventExtensions/return-false.js new file mode 100644 index 0000000000..c448d70e80 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-false.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.4 +description: > + If boolean trap result if false, return false. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy({}, { + preventExtensions: function(t) { + return 0; + } +}); + +assert.sameValue(Reflect.preventExtensions(p), false); + +Object.preventExtensions(target); + +assert.sameValue(Reflect.preventExtensions(p), false); diff --git a/test/built-ins/Proxy/preventExtensions/return-is-abrupt.js b/test/built-ins/Proxy/preventExtensions/return-is-abrupt.js new file mode 100644 index 0000000000..8daf7b3187 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-is-abrupt.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.4 +description: > + Trap returns abrupt. +info: > + [[PreventExtensions]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + 9. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + preventExtensions: function(t) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js b/test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.js new file mode 100644 index 0000000000..7676c139f1 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-true-target-is-extensible.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.4 +description: > + Throws a TypeError exception if boolean trap result is true and target is + extensible. +info: > + [[PreventExtensions]] ( ) + + ... + 10. If booleanTrapResult is true, then + ... + c. If targetIsExtensible is true, throw a TypeError exception. + 11. Return booleanTrapResult. + ... +---*/ + +var p = new Proxy({}, { + preventExtensions: function(t) { + return true; + } +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js b/test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.js new file mode 100644 index 0000000000..14143824f4 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/return-true-target-is-not-extensible.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.4 +description: > + Return boolean trap result if its true and target is not extensible. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + preventExtensions: function(t) { + return 1; + } +}); + +Object.preventExtensions(target); + +assert(Reflect.preventExtensions(p)); diff --git a/test/built-ins/Proxy/preventExtensions/trap-is-not-callable.js b/test/built-ins/Proxy/preventExtensions/trap-is-not-callable.js new file mode 100644 index 0000000000..77e2966ee6 --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/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.4 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[PreventExtensions]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let trap be GetMethod(handler, "preventExtensions"). + ... + 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, { + preventExtensions: {} +}); + +assert.throws(TypeError, function() { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Proxy/preventExtensions/trap-is-undefined.js b/test/built-ins/Proxy/preventExtensions/trap-is-undefined.js new file mode 100644 index 0000000000..0cd82e501b --- /dev/null +++ b/test/built-ins/Proxy/preventExtensions/trap-is-undefined.js @@ -0,0 +1,13 @@ +// 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.4 +description: > + Return target.[[PreventExtensions]]() if target is undefined. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +assert.sameValue(Reflect.preventExtensions(p), true); -- GitLab