Map.prototype.clear

This commit is contained in:
Leonardo Balter 2015-06-26 16:38:39 -04:00
parent ded4923d27
commit b1557df8ef
10 changed files with 252 additions and 0 deletions

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: 23.1.3.1
description: >
Clears a Map.
info: >
Map.prototype.clear ( )
...
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. 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);

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.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');

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.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([]);
});

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.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());
});

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.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());
});

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.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());
});

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.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');

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: 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 Ms [[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);

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.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');

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.1
description: >
Returns undefined.
info: >
Map.prototype.clear ( )
...
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. 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');