Add tests for Reflect.deleteProperty

This commit is contained in:
Leonardo Balter 2015-07-28 17:26:14 -04:00
parent 2fcf931f81
commit ed233ccb2d
10 changed files with 223 additions and 0 deletions

View File

@ -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: 26.1.4
description: >
Delete property.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
4. Return target.[[Delete]](key).
---*/
var o = {
prop: 42
};
Reflect.deleteProperty(o, 'prop');
assert.sameValue(o.hasOwnProperty('prop'), false);

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: 26.1.4
description: >
Delete a symbol property.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
...
7.1.14 ToPropertyKey ( argument )
...
3. If Type(key) is Symbol, then
a. Return key.
...
features: [Symbol]
---*/
var s = Symbol('1');
var o = {};
o[s] = 42;
Reflect.deleteProperty(o, s);
assert.sameValue(o.hasOwnProperty(s), false);
assert.sameValue(o[s], undefined);

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: 26.1.4
description: >
Reflect.deleteProperty is configurable, writable and not enumerable.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(Reflect, 'deleteProperty');
verifyWritable(Reflect, 'deleteProperty');
verifyConfigurable(Reflect, 'deleteProperty');

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: 26.1.4
description: >
Reflect.deleteProperty.length value and property descriptor
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.deleteProperty.length, 2,
'The value of `Reflect.deleteProperty.length` is `2`'
);
verifyNotEnumerable(Reflect.deleteProperty, 'length');
verifyNotWritable(Reflect.deleteProperty, 'length');
verifyConfigurable(Reflect.deleteProperty, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 26.1.4
description: >
Reflect.deleteProperty.name value and property descriptor
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Reflect.deleteProperty.name, 'deleteProperty',
'The value of `Reflect.deleteProperty.name` is `"deleteProperty"`'
);
verifyNotEnumerable(Reflect.deleteProperty, 'name');
verifyNotWritable(Reflect.deleteProperty, 'name');
verifyConfigurable(Reflect.deleteProperty, 'name');

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: 26.1.4
description: >
Return abrupt from ToPropertyKey(propertyKey)
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
2. Let key be ToPropertyKey(propertyKey).
3. ReturnIfAbrupt(key).
...
---*/
var p = {
toString: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Reflect.deleteProperty({}, p);
});

View File

@ -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: 26.1.4
description: >
Return abrupt result from deleting a property.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
6. Return target.[[DefineOwnProperty]](key, desc).
...
features: [Proxy]
---*/
var o = {};
var p = new Proxy(o, {
deleteProperty: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
Reflect.deleteProperty(p, 'p1');
});

View File

@ -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: 26.1.4
description: >
Return boolean result.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
...
4. Return target.[[Delete]](key).
---*/
var o = {};
o.p1 = 'foo';
assert.sameValue(Reflect.deleteProperty(o, 'p1'), true);
assert.sameValue(o.hasOwnProperty('p1'), false);
o.p2 = 'foo';
Object.freeze(o);
assert.sameValue(Reflect.deleteProperty(o, 'p2'), false);
assert.sameValue(o.hasOwnProperty('p2'), true);

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: 26.1.4
description: >
Throws a TypeError if target is not an Object.
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
---*/
assert.throws(TypeError, function() {
Reflect.deleteProperty(1, 'p');
});
assert.throws(TypeError, function() {
Reflect.deleteProperty(null, 'p');
});
assert.throws(TypeError, function() {
Reflect.deleteProperty(undefined, 'p');
});
assert.throws(TypeError, function() {
Reflect.deleteProperty('', 'p');
});

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: 26.1.4
description: >
Throws a TypeError if target is a Symbol
info: >
26.1.4 Reflect.deleteProperty ( target, propertyKey )
1. If Type(target) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Reflect.deleteProperty(Symbol(1), 'p');
});