Map.prototype.delete

This commit is contained in:
Leonardo Balter 2015-06-26 16:39:08 -04:00
parent 66c08508ae
commit e345635a75
10 changed files with 245 additions and 0 deletions

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: 23.1.3.3
description: >
Throws a TypeError if `this` does not have a [[MapData]] internal slot.
info: >
Map.prototype.delete ( key )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
---*/
assert.throws(TypeError, function() {
Map.prototype.delete.call({}, 'attr');
});
assert.throws(TypeError, function() {
Map.prototype.delete.call([], 'attr');
});

View File

@ -0,0 +1,38 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.3.3
description: >
Throws a TypeError if `this` is not an Object.
info: >
Map.prototype.delete ( key )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
...
features: [Symbol]
---*/
assert.throws(TypeError, function() {
Map.prototype.delete.call(1, 'attr');
});
assert.throws(TypeError, function() {
Map.prototype.delete.call(true, 'attr');
});
assert.throws(TypeError, function() {
Map.prototype.delete.call('', 'attr');
});
assert.throws(TypeError, function() {
Map.prototype.delete.call(null, 'attr');
});
assert.throws(TypeError, function() {
Map.prototype.delete.call(undefined, 'attr');
});
assert.throws(TypeError, function() {
Map.prototype.delete.call(Symbol(), 'attr');
});

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: 23.1.3.3
description: >
Throws a TypeError if `this` is a Set object.
info: >
Map.prototype.delete ( key )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
features: [Set]
---*/
assert.throws(TypeError, function() {
Map.prototype.delete.call(new Set(), 'attr');
});

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: 23.1.3.3
description: >
Throws a TypeError if `this` is a WeakMap object.
info: >
Map.prototype.delete ( key )
1. Let M be the this value.
2. If Type(M) is not Object, throw a TypeError exception.
3. If M does not have a [[MapData]] internal slot, throw a TypeError
exception.
...
features: [WeakMap]
---*/
assert.throws(TypeError, function() {
Map.prototype.delete.call(new WeakMap(), 'attr');
});

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: 23.1.3.3
description: >
Map.prototype.delete ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
typeof Map.prototype.delete,
'function',
'typeof Map.prototype.delete is "function"'
);
verifyNotEnumerable(Map.prototype, 'delete');
verifyWritable(Map.prototype, 'delete');
verifyConfigurable(Map.prototype, 'delete');

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: 23.1.3.3
description: >
Deleting an entry does not break a [[MapData]] List.
info: >
Map.prototype.delete ( key )
4. Let entries be the List that is the value of Ms [[MapData]] internal slot.
5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries,
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then
i. Set p.[[key]] to empty.
ii. Set p.[[value]] to empty.
iii. Return true.
...
---*/
var m = new Map([['a',1], ['b', 2], ['c', 3]]);
var e = m.entries();
e.next();
m.delete('b');
var n = e.next();
assert.sameValue(n.value[0], 'c');
assert.sameValue(n.value[1], 3);
n = e.next();
assert.sameValue(n.value, undefined);
assert.sameValue(n.done, true);

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: 23.1.3.3
description: >
Map.prototype.delete.length value and descriptor.
info: >
Map.prototype.delete ( key )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Map.prototype.delete.length, 1,
'The value of `Map.prototype.delete.length` is `1`'
);
verifyNotEnumerable(Map.prototype.delete, 'length');
verifyNotWritable(Map.prototype.delete, 'length');
verifyConfigurable(Map.prototype.delete, '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: 23.1.3.3
description: >
Map.prototype.delete.name value and descriptor.
info: >
Map.prototype.delete ( key )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Map.prototype.delete.name, 'delete',
'The value of `Map.prototype.delete.name` is `"delete"`'
);
verifyNotEnumerable(Map.prototype.delete, 'name');
verifyNotWritable(Map.prototype.delete, 'name');
verifyConfigurable(Map.prototype.delete, 'name');

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: 23.1.3.3
description: >
Returns false when it does not delete an entry.
info: >
Map.prototype.delete ( key )
4. Let entries be the List that is the value of Ms [[MapData]] internal slot.
5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries,
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then
...
iii. Return true.
6. Return false.
---*/
var m = new Map([['a',1], ['b', 2]]);
assert.sameValue(m.delete('not-in-the-map'), false);
m.delete('a');
assert.sameValue(m.delete('a'), false);

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: 23.1.3.3
description: >
Returns true when deletes an entry.
info: >
Map.prototype.delete ( key )
4. Let entries be the List that is the value of Ms [[MapData]] internal slot.
5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries,
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then
i. Set p.[[key]] to empty.
ii. Set p.[[value]] to empty.
iii. Return true.
...
---*/
var m = new Map([['a',1], ['b', 2]]);
var result = m.delete('a');
assert(result);
assert.sameValue(m.size, 1);