From 1ddb99eebd1982c0f9f94fb4cee75614fd1c60d2 Mon Sep 17 00:00:00 2001 From: Leonardo Balter <leonardo.balter@gmail.com> Date: Tue, 30 Jun 2015 14:45:12 -0400 Subject: [PATCH] Map.prototype.size --- ...does-not-have-mapdata-internal-slot-set.js | 26 ++++++++++ ...-not-have-mapdata-internal-slot-weakmap.js | 27 +++++++++++ .../does-not-have-mapdata-internal-slot.js | 26 ++++++++++ test/built-ins/Map/prototype/size/length.js | 23 +++++++++ test/built-ins/Map/prototype/size/name.js | 27 +++++++++++ ...f-present-values-before-after-set-clear.js | 30 ++++++++++++ ...-present-values-before-after-set-delete.js | 29 ++++++++++++ ...ns-count-of-present-values-by-insertion.js | 26 ++++++++++ ...rns-count-of-present-values-by-iterable.js | 26 ++++++++++ test/built-ins/Map/prototype/size/size.js | 29 ++++++++++++ .../prototype/size/this-not-object-throw.js | 47 +++++++++++++++++++ 11 files changed, 316 insertions(+) create mode 100644 test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js create mode 100644 test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js create mode 100644 test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.js create mode 100644 test/built-ins/Map/prototype/size/length.js create mode 100644 test/built-ins/Map/prototype/size/name.js create mode 100644 test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js create mode 100644 test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js create mode 100644 test/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.js create mode 100644 test/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js create mode 100644 test/built-ins/Map/prototype/size/size.js create mode 100644 test/built-ins/Map/prototype/size/this-not-object-throw.js diff --git a/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..b2d487cc35 --- /dev/null +++ b/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,26 @@ +// 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.10 +description: > + Throws a TypeError if `this` is a Set object. +info: > + Map.prototype.set ( key , value ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +var map = new Map(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call(new Set()); +}); diff --git a/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..2cc3e8b586 --- /dev/null +++ b/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,27 @@ +// 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.9 +description: > + Throws a TypeError if `this` is a WeakMap object. +info: > + get Map.prototype.size + + 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] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +var map = new Map(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call(new WeakMap()); +}); diff --git a/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.js b/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..ae115355d4 --- /dev/null +++ b/test/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,26 @@ +// 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.9 +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: > + get Map.prototype.size + + 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. + ... +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +var map = new Map(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call([]); +}); diff --git a/test/built-ins/Map/prototype/size/length.js b/test/built-ins/Map/prototype/size/length.js new file mode 100644 index 0000000000..27a8c7fe6d --- /dev/null +++ b/test/built-ins/Map/prototype/size/length.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.10 +description: > + Map.prototype.size.length value and descriptor. +info: > + get Map.prototype.size + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.sameValue( + descriptor.get.length, 0, + 'The value of `Map.prototype.size.length` is `0`' +); + +verifyNotEnumerable(descriptor.get, 'length'); +verifyNotWritable(descriptor.get, 'length'); +verifyConfigurable(descriptor.get, 'length'); diff --git a/test/built-ins/Map/prototype/size/name.js b/test/built-ins/Map/prototype/size/name.js new file mode 100644 index 0000000000..c1ec7cb7c0 --- /dev/null +++ b/test/built-ins/Map/prototype/size/name.js @@ -0,0 +1,27 @@ +// 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.10 +description: > + Map.prototype.size.name value and descriptor. +info: > + get Map.prototype.size + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.sameValue(descriptor.get.name, + 'get size', + 'The value of `descriptor.get.name` is `get size`' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); diff --git a/test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js b/test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js new file mode 100644 index 0000000000..e46bca6906 --- /dev/null +++ b/test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js @@ -0,0 +1,30 @@ +// 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.10 +description: > + Returns count of present values before and after using `set` and `clear`. +info: > + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +---*/ + +var map = new Map(); + +assert.sameValue(map.size, 0, 'The value of `map.size` is `0`'); + +map.set(1, 1); +map.set(2, 2); +assert.sameValue( + map.size, 2, + 'The value of `map.size` is `2`' +); + +map.clear(); +assert.sameValue( + map.size, 0, + 'The value of `map.size` is `0`, after executing `map.clear()`' +); diff --git a/test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js b/test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js new file mode 100644 index 0000000000..b14852a4e8 --- /dev/null +++ b/test/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js @@ -0,0 +1,29 @@ +// 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.10 +description: > + Returns count of present values before and after using `set` and `delete`. +info: > + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +---*/ + +var map = new Map(); + +assert.sameValue(map.size, 0, 'The value of `map.size` is `0`'); + +map.set(1, 1); +assert.sameValue( + map.size, 1, + 'The value of `map.size` is `1`, after executing `map.set(1, 1)`' +); + +map.delete(1); +assert.sameValue( + map.size, 0, + 'The value of `map.size` is `0`, after executing `map.delete(1)`' +); diff --git a/test/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.js b/test/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.js new file mode 100644 index 0000000000..eb2c5270ac --- /dev/null +++ b/test/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.js @@ -0,0 +1,26 @@ +// 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.10 +description: > + Returns count of present values inserted with set. +info: > + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +features: [Symbol] +---*/ + +var map = new Map(); + +map.set(0, undefined); +map.set(undefined, undefined); +map.set(false, undefined); +map.set(NaN, undefined); +map.set(null, undefined); +map.set('', undefined); +map.set(Symbol(), undefined); + +assert.sameValue(map.size, 7, 'The value of `map.size` is `7`'); diff --git a/test/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js b/test/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js new file mode 100644 index 0000000000..4f15613ed7 --- /dev/null +++ b/test/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js @@ -0,0 +1,26 @@ +// 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.10 +description: > + Returns count of present values inserted via iterable argument. +info: > + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +features: [Symbol] +---*/ + +var map = new Map([ + [0, undefined], + [undefined, undefined], + [false, undefined], + [NaN, undefined], + [null, undefined], + ['', undefined], + [Symbol(), undefined], +]); + +assert.sameValue(map.size, 7, 'The value of `map.size` is `7`'); diff --git a/test/built-ins/Map/prototype/size/size.js b/test/built-ins/Map/prototype/size/size.js new file mode 100644 index 0000000000..519870f55e --- /dev/null +++ b/test/built-ins/Map/prototype/size/size.js @@ -0,0 +1,29 @@ +// 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.10 +description: > + Property type and descriptor. +info: > + get Map.prototype.size + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.sameValue( + typeof descriptor.get, + 'function', + 'typeof descriptor.get is function' +); +assert.sameValue( + typeof descriptor.set, + 'undefined', + 'typeof descriptor.set is undefined' +); + +verifyNotEnumerable(Map.prototype, 'size'); +verifyConfigurable(Map.prototype, 'size'); diff --git a/test/built-ins/Map/prototype/size/this-not-object-throw.js b/test/built-ins/Map/prototype/size/this-not-object-throw.js new file mode 100644 index 0000000000..d55730db89 --- /dev/null +++ b/test/built-ins/Map/prototype/size/this-not-object-throw.js @@ -0,0 +1,47 @@ +// 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.10 +description: > + Throws a TypeError if `this` is not an Object. +info: > + get Map.prototype.size + + 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. + ... + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(false); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(''); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(undefined); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(null); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(Symbol()); +}); -- GitLab