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

Map.prototype.clear

parent ded4923d
No related branches found
No related tags found
No related merge requests found
Showing with 252 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.1
description: >
Clears a Map.
info: >
Map.prototype.clear ( )
...
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. Set p.[[key]] to empty.
b. Set p.[[value]] to empty.
6. Return undefined.
features: [Symbol]
---*/
var m1 = new Map([['foo', 'bar'], [1, 1]]);
var m2 = new Map();
var m3 = new Map();
m2.set('foo', 'bar');
m2.set(1,1);
m2.set(Symbol('a'), Symbol('a'));
m1.clear();
m2.clear();
m3.clear();
assert.sameValue(m1.size, 0);
assert.sameValue(m2.size, 0);
assert.sameValue(m3.size, 0);
// 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.1
description: >
Map.prototype.clear ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
typeof Map.prototype.clear,
'function',
'typeof Map.prototype.clear is "function"'
);
verifyNotEnumerable(Map.prototype, 'clear');
verifyWritable(Map.prototype, 'clear');
verifyConfigurable(Map.prototype, 'clear');
// 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.1
description: >
Throws a TypeError if `this` does not have a [[MapData]] internal slot.
info: >
Map.prototype.clear ( )
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.clear.call({});
});
assert.throws(TypeError, function() {
Map.prototype.clear.call([]);
});
// 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.1
description: >
Throws a TypeError if `this` is not an Object.
info: >
Map.prototype.clear ( )
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.clear.call(1);
});
assert.throws(TypeError, function() {
Map.prototype.clear.call(true);
});
assert.throws(TypeError, function() {
Map.prototype.clear.call('');
});
assert.throws(TypeError, function() {
Map.prototype.clear.call(null);
});
assert.throws(TypeError, function() {
Map.prototype.clear.call(undefined);
});
assert.throws(TypeError, function() {
Map.prototype.clear.call(Symbol());
});
// 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.1
description: >
Throws a TypeError if `this` is a Set object.
info: >
Map.prototype.clear ( )
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.clear.call(new Set());
});
// 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.1
description: >
Throws a TypeError if `this` is a WeakMap object.
info: >
Map.prototype.clear ( )
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.clear.call(new WeakMap());
});
// 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.1
description: >
Map.prototype.clear.length value and descriptor.
info: >
Map.prototype.clear ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Map.prototype.clear.length, 0,
'The value of `Map.prototype.clear.length` is `0`'
);
verifyNotEnumerable(Map.prototype.clear, 'length');
verifyNotWritable(Map.prototype.clear, 'length');
verifyConfigurable(Map.prototype.clear, '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.1
description: >
The existing [[MapData]] List is preserved.
info: >
The existing [[MapData]] List is preserved because there may be existing
MapIterator objects that are suspended midway through iterating over that
List.
Map.prototype.clear ( )
...
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. Set p.[[key]] to empty.
b. Set p.[[value]] to empty.
6. Return undefined.
---*/
var m = new Map([[1,1], [2,2], [3,3]]);
var e = m.entries();
e.next();
m.clear();
var 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.1
description: >
Map.prototype.entries.name value and descriptor.
info: >
Map.prototype.clear ( )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
Map.prototype.clear.name, 'clear',
'The value of `Map.prototype.clear.name` is `"clear"`'
);
verifyNotEnumerable(Map.prototype.clear, 'name');
verifyNotWritable(Map.prototype.clear, 'name');
verifyConfigurable(Map.prototype.clear, '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.1
description: >
Returns undefined.
info: >
Map.prototype.clear ( )
...
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. Set p.[[key]] to empty.
b. Set p.[[value]] to empty.
6. Return undefined.
---*/
var m1 = new Map([['foo', 'bar'], [1, 1]]);
assert.sameValue(m1.clear(), undefined, 'clears a map and returns undefined');
assert.sameValue(m1.clear(), undefined, 'returns undefined on an empty map');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment