Skip to content
Snippets Groups Projects
Commit e345635a authored by Leonardo Balter's avatar Leonardo Balter
Browse files

Map.prototype.delete

parent 66c08508
No related branches found
No related tags found
No related merge requests found
Showing with 245 additions and 0 deletions
// 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');
});
// 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');
});
// 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');
});
// 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');
});
// 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');
// 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 M’s [[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);
// 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');
// 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');
// 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 M’s [[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);
// 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 M’s [[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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment