mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
Map.prototype.clear
This commit is contained in:
parent
ded4923d27
commit
b1557df8ef
33
test/built-ins/Map/prototype/clear/clear-map.js
vendored
Normal file
33
test/built-ins/Map/prototype/clear/clear-map.js
vendored
Normal 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 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);
|
21
test/built-ins/Map/prototype/clear/clear.js
vendored
Normal file
21
test/built-ins/Map/prototype/clear/clear.js
vendored
Normal 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');
|
23
test/built-ins/Map/prototype/clear/context-is-not-map-object.js
vendored
Normal file
23
test/built-ins/Map/prototype/clear/context-is-not-map-object.js
vendored
Normal 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([]);
|
||||||
|
});
|
38
test/built-ins/Map/prototype/clear/context-is-not-object.js
vendored
Normal file
38
test/built-ins/Map/prototype/clear/context-is-not-object.js
vendored
Normal 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());
|
||||||
|
});
|
20
test/built-ins/Map/prototype/clear/context-is-set-object-throws.js
vendored
Normal file
20
test/built-ins/Map/prototype/clear/context-is-set-object-throws.js
vendored
Normal 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());
|
||||||
|
});
|
20
test/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js
vendored
Normal file
20
test/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js
vendored
Normal 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());
|
||||||
|
});
|
22
test/built-ins/Map/prototype/clear/length.js
vendored
Normal file
22
test/built-ins/Map/prototype/clear/length.js
vendored
Normal 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');
|
31
test/built-ins/Map/prototype/clear/map-data-list-is-preserved.js
vendored
Normal file
31
test/built-ins/Map/prototype/clear/map-data-list-is-preserved.js
vendored
Normal 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 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);
|
22
test/built-ins/Map/prototype/clear/name.js
vendored
Normal file
22
test/built-ins/Map/prototype/clear/name.js
vendored
Normal 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');
|
22
test/built-ins/Map/prototype/clear/returns-undefined.js
vendored
Normal file
22
test/built-ins/Map/prototype/clear/returns-undefined.js
vendored
Normal 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 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');
|
Loading…
x
Reference in New Issue
Block a user