Proxy: deleteProperty

This commit is contained in:
Leonardo Balter 2015-06-02 19:14:56 -04:00
parent 99ca320b01
commit d9edb3593a
12 changed files with 289 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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;
});

View File

@ -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);

View File

@ -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);

View File

@ -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;
});

View File

@ -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;
});

View File

@ -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);

View File

@ -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;
});

View File

@ -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);

View File

@ -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);