From d9edb3593ad34da799e35089fbcfa27591e15acb Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 2 Jun 2015 19:14:56 -0400 Subject: [PATCH] Proxy: deleteProperty --- .../boolean-trap-result-boolean-false.js | 32 ++++++++++++++++++ .../boolean-trap-result-boolean-true.js | 17 ++++++++++ .../Proxy/deleteProperty/call-parameters.js | 33 +++++++++++++++++++ .../Proxy/deleteProperty/null-handler.js | 19 +++++++++++ .../deleteProperty/return-false-not-strict.js | 18 ++++++++++ .../deleteProperty/return-false-strict.js | 19 +++++++++++ .../Proxy/deleteProperty/return-is-abrupt.js | 21 ++++++++++++ .../targetdesc-is-not-configurable.js | 28 ++++++++++++++++ .../targetdesc-is-undefined-return-true.js | 17 ++++++++++ .../deleteProperty/trap-is-not-callable.js | 24 ++++++++++++++ .../trap-is-undefined-not-strict.js | 30 +++++++++++++++++ .../trap-is-undefined-strict.js | 31 +++++++++++++++++ 12 files changed, 289 insertions(+) create mode 100644 test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js create mode 100644 test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js create mode 100644 test/built-ins/Proxy/deleteProperty/call-parameters.js create mode 100644 test/built-ins/Proxy/deleteProperty/null-handler.js create mode 100644 test/built-ins/Proxy/deleteProperty/return-false-not-strict.js create mode 100644 test/built-ins/Proxy/deleteProperty/return-false-strict.js create mode 100644 test/built-ins/Proxy/deleteProperty/return-is-abrupt.js create mode 100644 test/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js create mode 100644 test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js create mode 100644 test/built-ins/Proxy/deleteProperty/trap-is-not-callable.js create mode 100644 test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js create mode 100644 test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.js diff --git a/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.js new file mode 100644 index 0000000000..148a7b81af --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-false.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.10 +description: > + [[Delete]] (P) + + The result is a Boolean value. +features: [Reflect] +---*/ + +var target = {}; +var p = new Proxy(target, { + deleteProperty: function() { + return 0; + } +}); + +Object.defineProperties(target, { + isConfigurable: { + value: 1, + configurable: true + }, + notConfigurable: { + value: 1, + configurable: false + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); +assert.sameValue(Reflect.deleteProperty(p, "isConfigurable"), false); +assert.sameValue(Reflect.deleteProperty(p, "notConfigurable"), false); diff --git a/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js new file mode 100644 index 0000000000..fe506f109e --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/boolean-trap-result-boolean-true.js @@ -0,0 +1,17 @@ +// 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.10 +description: > + [[Delete]] (P) + + The result is a Boolean value. +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return 1; + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), true); diff --git a/test/built-ins/Proxy/deleteProperty/call-parameters.js b/test/built-ins/Proxy/deleteProperty/call-parameters.js new file mode 100644 index 0000000000..38a4f57fd9 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/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.10 +description: > + [[Delete]] (P) + + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). +info: > + 6.1.7.2 Object Internal Methods and Internal Slots + + (...) Receiver is used as the this value when evaluating the code +---*/ + +var _handler, _target, _prop; +var target = { + attr: 1 +}; +var handler = { + deleteProperty: function(t, prop) { + _handler = this; + _target = t; + _prop = prop; + return delete t[prop]; + } +}; +var p = new Proxy(target, handler); + +delete p.attr; + +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"); diff --git a/test/built-ins/Proxy/deleteProperty/null-handler.js b/test/built-ins/Proxy/deleteProperty/null-handler.js new file mode 100644 index 0000000000..1b280f79ed --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/null-handler.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.10 +description: > + [[Delete]] (P) + + 3. If handler is null, throw a TypeError exception. +---*/ + +var p = Proxy.revocable({ + attr: 1 +}, {}); + +p.revoke(); + +assert.throws(TypeError, function() { + delete p.proxy.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/return-false-not-strict.js b/test/built-ins/Proxy/deleteProperty/return-false-not-strict.js new file mode 100644 index 0000000000..c0785c90bf --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/return-false-not-strict.js @@ -0,0 +1,18 @@ +// 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.10 +description: > + [[Delete]] (P) + + 11. If booleanTrapResult is false, return false. +flags: [noStrict] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return false; + } +}); + +assert.sameValue(delete p.attr, false); diff --git a/test/built-ins/Proxy/deleteProperty/return-false-strict.js b/test/built-ins/Proxy/deleteProperty/return-false-strict.js new file mode 100644 index 0000000000..94d33a91e3 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/return-false-strict.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.10 +description: > + [[Delete]] (P) + + 11. If booleanTrapResult is false, return false. +flags: [onlyStrict] +features: [Reflect] +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return false; + } +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false); diff --git a/test/built-ins/Proxy/deleteProperty/return-is-abrupt.js b/test/built-ins/Proxy/deleteProperty/return-is-abrupt.js new file mode 100644 index 0000000000..7a37fc91f5 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/return-is-abrupt.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.10 +description: > + Trap return is an abrupt. +info: > + 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). + 10. ReturnIfAbrupt(booleanTrapResult). +includes: [Test262Error.js] +---*/ + +var p = new Proxy({}, { + deleteProperty: function(t, prop) { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + delete p.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js b/test/built-ins/Proxy/deleteProperty/targetdesc-is-not-configurable.js new file mode 100644 index 0000000000..13af3bbc53 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/targetdesc-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.10 +description: > + [[Delete]] (P) + + A property cannot be reported as deleted, if it exists as a non-configurable + own property of the target object. +info: > + 14. If targetDesc.[[Configurable]] is false, throw a TypeError exception. +---*/ + +var target = {}; +var p = new Proxy(target, { + deleteProperty: function() { + return true; + } +}); + +Object.defineProperty(target, "attr", { + configurable: false, + value: 1 +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js b/test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js new file mode 100644 index 0000000000..fc70773fa7 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/targetdesc-is-undefined-return-true.js @@ -0,0 +1,17 @@ +// 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.10 +description: > + [[Delete]] (P) + + 14. If targetDesc is undefined, return true. +---*/ + +var p = new Proxy({}, { + deleteProperty: function() { + return true; + } +}); + +assert.sameValue(delete p.attr, true); diff --git a/test/built-ins/Proxy/deleteProperty/trap-is-not-callable.js b/test/built-ins/Proxy/deleteProperty/trap-is-not-callable.js new file mode 100644 index 0000000000..756e310384 --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/trap-is-not-callable.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.10 +description: > + Throws when trap is not callable. +info: > + 9.5.10 [[Delete]] (P) + + 6. Let trap be GetMethod(handler, "deleteProperty"). + ... + + 7.3.9 GetMethod (O, P) + + 5. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +var p = new Proxy({}, { + deleteProperty: {} +}); + +assert.throws(TypeError, function() { + delete p.attr; +}); diff --git a/test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.js new file mode 100644 index 0000000000..3adf23123b --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-not-strict.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.10 +description: > + [[Delete]] (P) + + 8. If trap is undefined, then Return target.[[Delete]](P). +flags: [noStrict] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(delete p.attr, true); +assert.sameValue(delete p.notThere, true); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +assert.sameValue(delete p.attr, false); diff --git a/test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.js b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.js new file mode 100644 index 0000000000..070fba7f5a --- /dev/null +++ b/test/built-ins/Proxy/deleteProperty/trap-is-undefined-strict.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.10 +description: > + [[Delete]] (P) + + 8. If trap is undefined, then Return target.[[Delete]](P). +flags: [onlyStrict] +features: [Reflect] +---*/ + +var target = { + attr: 1 +}; +var p = new Proxy(target, {}); + +assert.sameValue(delete p.attr, true); +assert.sameValue(delete p.notThere, true); +assert.sameValue( + Object.getOwnPropertyDescriptor(target, "attr"), + undefined +); + +Object.defineProperty(target, "attr", { + configurable: false, + enumerable: true, + value: 1 +}); + +assert.sameValue(Reflect.deleteProperty(p, "attr"), false);