From 15a9a1581523ec411ce7a9ed8b795f343ed2d500 Mon Sep 17 00:00:00 2001 From: Leonardo Balter <leonardo.balter@gmail.com> Date: Tue, 2 Jun 2015 18:27:36 -0400 Subject: [PATCH] Proxy: isExtensible --- .../Proxy/isExtensible/call-parameters.js | 31 +++++++++++++++++++ .../Proxy/isExtensible/null-handler.js | 15 +++++++++ .../Proxy/isExtensible/return-is-abrupt.js | 25 +++++++++++++++ .../Proxy/isExtensible/return-is-boolean.js | 24 ++++++++++++++ .../return-is-different-from-target.js | 25 +++++++++++++++ .../return-same-result-from-target.js | 20 ++++++++++++ .../isExtensible/trap-is-not-callable.js | 30 ++++++++++++++++++ .../Proxy/isExtensible/trap-is-undefined.js | 23 ++++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 test/built-ins/Proxy/isExtensible/call-parameters.js create mode 100644 test/built-ins/Proxy/isExtensible/null-handler.js create mode 100644 test/built-ins/Proxy/isExtensible/return-is-abrupt.js create mode 100644 test/built-ins/Proxy/isExtensible/return-is-boolean.js create mode 100644 test/built-ins/Proxy/isExtensible/return-is-different-from-target.js create mode 100644 test/built-ins/Proxy/isExtensible/return-same-result-from-target.js create mode 100644 test/built-ins/Proxy/isExtensible/trap-is-not-callable.js create mode 100644 test/built-ins/Proxy/isExtensible/trap-is-undefined.js diff --git a/test/built-ins/Proxy/isExtensible/call-parameters.js b/test/built-ins/Proxy/isExtensible/call-parameters.js new file mode 100644 index 0000000000..e2e5db3cc3 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/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.3 +description: > + The trap is called with handler on its context and the target object as the + first parabeter +info: > + [[IsExtensible]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + ... + +---*/ + +var _target, _handler; +var target = {}; +var handler = { + isExtensible: function(t) { + _handler = this; + _target = t; + return Object.isExtensible(t); + } +} +var p = new Proxy(target, handler); + +Object.isExtensible(p); + +assert.sameValue(_handler, handler); +assert.sameValue(_target, target); diff --git a/test/built-ins/Proxy/isExtensible/null-handler.js b/test/built-ins/Proxy/isExtensible/null-handler.js new file mode 100644 index 0000000000..d8d14bf7c8 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/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.3 +description: > + Throws a TypeError exception if handler is null +---*/ + +var p = Proxy.revocable({}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + Object.isExtensible(p.proxy); +}); diff --git a/test/built-ins/Proxy/isExtensible/return-is-abrupt.js b/test/built-ins/Proxy/isExtensible/return-is-abrupt.js new file mode 100644 index 0000000000..d288dee824 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/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.3 +description: > + Trap returns abrupt. +info: > + [[IsExtensible]] ( ) + + ... + 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). + 9. ReturnIfAbrupt(booleanTrapResult). + ... +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + isExtensible: function(t) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Object.isExtensible(p); +}); diff --git a/test/built-ins/Proxy/isExtensible/return-is-boolean.js b/test/built-ins/Proxy/isExtensible/return-is-boolean.js new file mode 100644 index 0000000000..29d54369ed --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-is-boolean.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.3 +description: > + The trap returns a boolean result. +---*/ + +var target = {}; +var p = new Proxy(target, { + isExtensible: function(t) { + if ( Object.isExtensible(t) ) { + return 1; + } else { + return 0; + } + } +}); + +assert.sameValue(Object.isExtensible(p), true); + +Object.preventExtensions(target); + +assert.sameValue(Object.isExtensible(p), false); diff --git a/test/built-ins/Proxy/isExtensible/return-is-different-from-target.js b/test/built-ins/Proxy/isExtensible/return-is-different-from-target.js new file mode 100644 index 0000000000..9c5ee18c99 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-is-different-from-target.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.3 +description: > + Throws a TypeError exception if boolean trap result is not the same as + target.[[IsExtensible]]() result +info: > + [[IsExtensible]] ( ) + + ... + 12. If SameValue(booleanTrapResult, targetResult) is false, throw a + TypeError exception. + ... +---*/ + +var p = new Proxy({}, { + isExtensible: function(t) { + return false; + } +}); + +assert.throws(TypeError, function() { + Object.isExtensible(p); +}); diff --git a/test/built-ins/Proxy/isExtensible/return-same-result-from-target.js b/test/built-ins/Proxy/isExtensible/return-same-result-from-target.js new file mode 100644 index 0000000000..4858765c37 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/return-same-result-from-target.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.3 +description: > + Return trap result. +---*/ + +var target = {}; +var p = new Proxy(target, { + isExtensible: function(t) { + return Object.isExtensible(t); + } +}); + +assert.sameValue(Object.isExtensible(p), true); + +Object.preventExtensions(target); + +assert.sameValue(Object.isExtensible(p), false); diff --git a/test/built-ins/Proxy/isExtensible/trap-is-not-callable.js b/test/built-ins/Proxy/isExtensible/trap-is-not-callable.js new file mode 100644 index 0000000000..adca793833 --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/trap-is-not-callable.js @@ -0,0 +1,30 @@ +// 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.3 +description: > + Throws a TypeError exception if trap is not callable. +info: > + [[IsExtensible]] ( ) + + ... + 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. + ... + 5. Let trap be GetMethod(handler, "isExtensible"). + ... + 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, { + isExtensible: {} +}); + +assert.throws(TypeError, function() { + Object.isExtensible(p); +}); diff --git a/test/built-ins/Proxy/isExtensible/trap-is-undefined.js b/test/built-ins/Proxy/isExtensible/trap-is-undefined.js new file mode 100644 index 0000000000..a69acac26d --- /dev/null +++ b/test/built-ins/Proxy/isExtensible/trap-is-undefined.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.3 +description: > + Return target.[[IsExtensible]]() if trap is undefined. +info: > + [[IsExtensible]] ( ) + + ... + 7. If trap is undefined, then + a. Return target.[[IsExtensible]](). + ... +---*/ + +var target = {}; +var p = new Proxy(target, {}); + +assert.sameValue(Object.isExtensible(p), true); + +Object.preventExtensions(target); + +assert.sameValue(Object.isExtensible(p), false); -- GitLab