From b1557df8efb22abf2896418fe5ce7e383ec22c80 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 26 Jun 2015 16:38:39 -0400 Subject: [PATCH] Map.prototype.clear --- .../Map/prototype/clear/clear-map.js | 33 ++++++++++++++++ test/built-ins/Map/prototype/clear/clear.js | 21 ++++++++++ .../clear/context-is-not-map-object.js | 23 +++++++++++ .../prototype/clear/context-is-not-object.js | 38 +++++++++++++++++++ .../clear/context-is-set-object-throws.js | 20 ++++++++++ .../clear/context-is-weakmap-object-throws.js | 20 ++++++++++ test/built-ins/Map/prototype/clear/length.js | 22 +++++++++++ .../clear/map-data-list-is-preserved.js | 31 +++++++++++++++ test/built-ins/Map/prototype/clear/name.js | 22 +++++++++++ .../Map/prototype/clear/returns-undefined.js | 22 +++++++++++ 10 files changed, 252 insertions(+) create mode 100644 test/built-ins/Map/prototype/clear/clear-map.js create mode 100644 test/built-ins/Map/prototype/clear/clear.js create mode 100644 test/built-ins/Map/prototype/clear/context-is-not-map-object.js create mode 100644 test/built-ins/Map/prototype/clear/context-is-not-object.js create mode 100644 test/built-ins/Map/prototype/clear/context-is-set-object-throws.js create mode 100644 test/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js create mode 100644 test/built-ins/Map/prototype/clear/length.js create mode 100644 test/built-ins/Map/prototype/clear/map-data-list-is-preserved.js create mode 100644 test/built-ins/Map/prototype/clear/name.js create mode 100644 test/built-ins/Map/prototype/clear/returns-undefined.js diff --git a/test/built-ins/Map/prototype/clear/clear-map.js b/test/built-ins/Map/prototype/clear/clear-map.js new file mode 100644 index 0000000000..90b7344473 --- /dev/null +++ b/test/built-ins/Map/prototype/clear/clear-map.js @@ -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); diff --git a/test/built-ins/Map/prototype/clear/clear.js b/test/built-ins/Map/prototype/clear/clear.js new file mode 100644 index 0000000000..59f28de2e9 --- /dev/null +++ b/test/built-ins/Map/prototype/clear/clear.js @@ -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'); diff --git a/test/built-ins/Map/prototype/clear/context-is-not-map-object.js b/test/built-ins/Map/prototype/clear/context-is-not-map-object.js new file mode 100644 index 0000000000..ab3b04b6aa --- /dev/null +++ b/test/built-ins/Map/prototype/clear/context-is-not-map-object.js @@ -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([]); +}); diff --git a/test/built-ins/Map/prototype/clear/context-is-not-object.js b/test/built-ins/Map/prototype/clear/context-is-not-object.js new file mode 100644 index 0000000000..c74d01abdf --- /dev/null +++ b/test/built-ins/Map/prototype/clear/context-is-not-object.js @@ -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()); +}); diff --git a/test/built-ins/Map/prototype/clear/context-is-set-object-throws.js b/test/built-ins/Map/prototype/clear/context-is-set-object-throws.js new file mode 100644 index 0000000000..5b28047ff5 --- /dev/null +++ b/test/built-ins/Map/prototype/clear/context-is-set-object-throws.js @@ -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()); +}); diff --git a/test/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js b/test/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js new file mode 100644 index 0000000000..f73121aefa --- /dev/null +++ b/test/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js @@ -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()); +}); diff --git a/test/built-ins/Map/prototype/clear/length.js b/test/built-ins/Map/prototype/clear/length.js new file mode 100644 index 0000000000..60a923c5de --- /dev/null +++ b/test/built-ins/Map/prototype/clear/length.js @@ -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'); diff --git a/test/built-ins/Map/prototype/clear/map-data-list-is-preserved.js b/test/built-ins/Map/prototype/clear/map-data-list-is-preserved.js new file mode 100644 index 0000000000..9df3adf8f2 --- /dev/null +++ b/test/built-ins/Map/prototype/clear/map-data-list-is-preserved.js @@ -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); diff --git a/test/built-ins/Map/prototype/clear/name.js b/test/built-ins/Map/prototype/clear/name.js new file mode 100644 index 0000000000..b498f506e3 --- /dev/null +++ b/test/built-ins/Map/prototype/clear/name.js @@ -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'); diff --git a/test/built-ins/Map/prototype/clear/returns-undefined.js b/test/built-ins/Map/prototype/clear/returns-undefined.js new file mode 100644 index 0000000000..1b971d9a5d --- /dev/null +++ b/test/built-ins/Map/prototype/clear/returns-undefined.js @@ -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');