From ad604366583edcc86998fc2dc18724132e0918d9 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 26 Jun 2015 17:13:56 -0400 Subject: [PATCH] Map.prototype.entries --- ...does-not-have-mapdata-internal-slot-set.js | 29 ++++++++++ ...-not-have-mapdata-internal-slot-weakmap.js | 29 ++++++++++ .../does-not-have-mapdata-internal-slot.js | 38 +++++++++++++ .../Map/prototype/entries/entries.js | 22 ++++++++ .../built-ins/Map/prototype/entries/length.js | 22 ++++++++ test/built-ins/Map/prototype/entries/name.js | 22 ++++++++ .../entries/returns-iterator-empty.js | 27 +++++++++ .../Map/prototype/entries/returns-iterator.js | 55 +++++++++++++++++++ .../entries/this-not-object-throw.js | 47 ++++++++++++++++ 9 files changed, 291 insertions(+) create mode 100644 test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js create mode 100644 test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js create mode 100644 test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js create mode 100644 test/built-ins/Map/prototype/entries/entries.js create mode 100644 test/built-ins/Map/prototype/entries/length.js create mode 100644 test/built-ins/Map/prototype/entries/name.js create mode 100644 test/built-ins/Map/prototype/entries/returns-iterator-empty.js create mode 100644 test/built-ins/Map/prototype/entries/returns-iterator.js create mode 100644 test/built-ins/Map/prototype/entries/this-not-object-throw.js diff --git a/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..cc11d2e11e --- /dev/null +++ b/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.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.4 +description: > + Throws a TypeError if `this` is a Set object. +info: > + Map.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 2. If map does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.entries.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.entries.call(new Set()); +}); diff --git a/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..57a7a03113 --- /dev/null +++ b/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.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.4 +description: > + Throws a TypeError if `this` is a WeakMap object. +info: > + Map.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 2. If map does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.entries.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.entries.call(new WeakMap()); +}); diff --git a/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js b/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..2ecb0de14c --- /dev/null +++ b/test/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.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.4 +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: > + Map.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 2. If map does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +var m = new Map(); + +assert.throws(TypeError, function() { + Map.prototype.entries.call([]); +}); + +assert.throws(TypeError, function() { + m.entries.call([]); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call({}); +}); + +assert.throws(TypeError, function() { + m.entries.call({}); +}); diff --git a/test/built-ins/Map/prototype/entries/entries.js b/test/built-ins/Map/prototype/entries/entries.js new file mode 100644 index 0000000000..853b1f96dc --- /dev/null +++ b/test/built-ins/Map/prototype/entries/entries.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.4 +description: > + Property type and descriptor. +info: > + Map.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.entries, + 'function', + '`typeof Map.prototype.entries` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'entries'); +verifyWritable(Map.prototype, 'entries'); +verifyConfigurable(Map.prototype, 'entries'); diff --git a/test/built-ins/Map/prototype/entries/length.js b/test/built-ins/Map/prototype/entries/length.js new file mode 100644 index 0000000000..fef6c7f473 --- /dev/null +++ b/test/built-ins/Map/prototype/entries/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.4 +description: > + Map.prototype.entries.length value and descriptor. +info: > + Map.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.entries.length, 0, + 'The value of `Map.prototype.entries.length` is `0`' +); + +verifyNotEnumerable(Map.prototype.entries, 'length'); +verifyNotWritable(Map.prototype.entries, 'length'); +verifyConfigurable(Map.prototype.entries, 'length'); diff --git a/test/built-ins/Map/prototype/entries/name.js b/test/built-ins/Map/prototype/entries/name.js new file mode 100644 index 0000000000..f80d038090 --- /dev/null +++ b/test/built-ins/Map/prototype/entries/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.4 +description: > + Map.prototype.entries.name value and descriptor. +info: > + Map.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.entries.name, 'entries', + 'The value of `Map.prototype.entries.name` is `"entries"`' +); + +verifyNotEnumerable(Map.prototype.entries, 'name'); +verifyNotWritable(Map.prototype.entries, 'name'); +verifyConfigurable(Map.prototype.entries, 'name'); diff --git a/test/built-ins/Map/prototype/entries/returns-iterator-empty.js b/test/built-ins/Map/prototype/entries/returns-iterator-empty.js new file mode 100644 index 0000000000..2584d4d5ca --- /dev/null +++ b/test/built-ins/Map/prototype/entries/returns-iterator-empty.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.4 +description: > + Returns an iterator on an empty Map object. +info: > + Map.prototype.entries ( ) + + ... + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new Map(); +var iterator = map.entries(); +var result = iterator.next(); + +assert.sameValue( + result.value, undefined, + 'The value of `result.value` is `undefined`' +); +assert.sameValue(result.done, true, 'The value of `result.done` is `true`'); diff --git a/test/built-ins/Map/prototype/entries/returns-iterator.js b/test/built-ins/Map/prototype/entries/returns-iterator.js new file mode 100644 index 0000000000..5e6ad2b2e3 --- /dev/null +++ b/test/built-ins/Map/prototype/entries/returns-iterator.js @@ -0,0 +1,55 @@ +// 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.4 +description: > + Returns an iterator. +info: > + Map.prototype.entries ( ) + + ... + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new Map(); +map.set('a',1); +map.set('b',2); +map.set('c',3); + +var iterator = map.entries(); +var result; + +result = iterator.next(); +assert.sameValue(result.value[0], 'a', 'First result `value` ("key")'); +assert.sameValue(result.value[1], 1, 'First result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 'b', 'Second result `value` ("key")'); +assert.sameValue(result.value[1], 2, 'Second result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Second result `value` (length)'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 'c', 'Third result `value` ("key")'); +assert.sameValue(result.value[1], 3, 'Third result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Third result `value` (length)'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/built-ins/Map/prototype/entries/this-not-object-throw.js b/test/built-ins/Map/prototype/entries/this-not-object-throw.js new file mode 100644 index 0000000000..6e5d56213b --- /dev/null +++ b/test/built-ins/Map/prototype/entries/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.4 +description: > + Throws a TypeError if `this` is not an Object. +info: > + Map.prototype.entries ( ) + + ... + 2. Return CreateSetIterator(M, "key+value"). + + 23.1.5.1 CreateSetIterator Abstract Operation + + 1. If Type(map) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.entries.call(false); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(1); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(''); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(undefined); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(null); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.entries.call(false); +});