From cdcd91c8b25cf6c33fd08b1d0c9d165f798c7320 Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Tue, 30 Jun 2015 14:52:57 -0400
Subject: [PATCH] Map.prototype.values

---
 ...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 ++++++++++++++
 test/built-ins/Map/prototype/values/length.js | 22 ++++++++
 test/built-ins/Map/prototype/values/name.js   | 22 ++++++++
 .../values/returns-iterator-empty.js          | 27 ++++++++++
 .../Map/prototype/values/returns-iterator.js  | 50 +++++++++++++++++++
 .../prototype/values/this-not-object-throw.js | 47 +++++++++++++++++
 test/built-ins/Map/prototype/values/values.js | 22 ++++++++
 9 files changed, 286 insertions(+)
 create mode 100644 test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js
 create mode 100644 test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js
 create mode 100644 test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot.js
 create mode 100644 test/built-ins/Map/prototype/values/length.js
 create mode 100644 test/built-ins/Map/prototype/values/name.js
 create mode 100644 test/built-ins/Map/prototype/values/returns-iterator-empty.js
 create mode 100644 test/built-ins/Map/prototype/values/returns-iterator.js
 create mode 100644 test/built-ins/Map/prototype/values/this-not-object-throw.js
 create mode 100644 test/built-ins/Map/prototype/values/values.js

diff --git a/test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js
new file mode 100644
index 0000000000..35d889d6a8
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Throws a TypeError if `this` is a Set object.
+info: >
+  Map.prototype.values ()
+
+  1. Let M be the this value.
+  2. Return CreateMapIterator(M, "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.values.call(new Set());
+});
+
+assert.throws(TypeError, function() {
+  var m = new Map();
+  m.values.call(new Set());
+});
diff --git a/test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js
new file mode 100644
index 0000000000..a8b00b225c
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Throws a TypeError if `this` is a WeakMap object.
+info: >
+  Map.prototype.values ()
+
+  1. Let M be the this value.
+  2. Return CreateMapIterator(M, "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.values.call(new WeakMap());
+});
+
+assert.throws(TypeError, function() {
+  var m = new Map();
+  m.values.call(new WeakMap());
+});
diff --git a/test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot.js b/test/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot.js
new file mode 100644
index 0000000000..1085ccc9a1
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Throws a TypeError if `this` object does not have a [[MapData]] internal slot.
+info: >
+  Map.prototype.values ()
+
+  1. Let M be the this value.
+  2. Return CreateMapIterator(M, "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.values.call([]);
+});
+
+assert.throws(TypeError, function() {
+  m.values.call([]);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call({});
+});
+
+assert.throws(TypeError, function() {
+  m.values.call({});
+});
diff --git a/test/built-ins/Map/prototype/values/length.js b/test/built-ins/Map/prototype/values/length.js
new file mode 100644
index 0000000000..5e94cab898
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Map.prototype.values.length value and descriptor.
+info: >
+  Map.prototype.values ()
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Map.prototype.values.length, 0,
+  'The value of `Map.prototype.values.length` is `0`'
+);
+
+verifyNotEnumerable(Map.prototype.values, 'length');
+verifyNotWritable(Map.prototype.values, 'length');
+verifyConfigurable(Map.prototype.values, 'length');
diff --git a/test/built-ins/Map/prototype/values/name.js b/test/built-ins/Map/prototype/values/name.js
new file mode 100644
index 0000000000..b211bd6d77
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Map.prototype.values.name value and descriptor.
+info: >
+  Map.prototype.values ()
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Map.prototype.values.name, 'values',
+  'The value of `Map.prototype.values.name` is `"values"`'
+);
+
+verifyNotEnumerable(Map.prototype.values, 'name');
+verifyNotWritable(Map.prototype.values, 'name');
+verifyConfigurable(Map.prototype.values, 'name');
diff --git a/test/built-ins/Map/prototype/values/returns-iterator-empty.js b/test/built-ins/Map/prototype/values/returns-iterator-empty.js
new file mode 100644
index 0000000000..9ef4f39a30
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Returns an iterator on an empty Map object.
+info: >
+  Map.prototype.values ()
+
+  ...
+  2. Return CreateMapIterator(M, "value").
+
+  23.1.5.1 CreateMapIterator Abstract Operation
+
+  ...
+  7. Return iterator.
+---*/
+
+var map = new Map();
+var iterator = map.values();
+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/values/returns-iterator.js b/test/built-ins/Map/prototype/values/returns-iterator.js
new file mode 100644
index 0000000000..e86ac67748
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/returns-iterator.js
@@ -0,0 +1,50 @@
+// 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.11
+description: >
+  Returns an iterator.
+info: >
+  Map.prototype.values ( )
+
+  ...
+  2. Return CreateMapIterator(M, "value").
+
+  23.1.5.1 CreateMapIterator Abstract Operation
+
+  ...
+  7. Return iterator.
+---*/
+
+var obj = {};
+var map = new Map();
+map.set(1, 'foo');
+map.set(2, obj);
+map.set(3, map);
+
+var iterator = map.values();
+var result;
+
+result = iterator.next();
+assert.sameValue(result.value, 'foo', 'First result `value` ("value")');
+assert.sameValue(result.done, false, 'First result `done` flag');
+
+result = iterator.next();
+assert.sameValue(result.value, obj, 'Second result `value` ("value")');
+assert.sameValue(result.done, false, 'Second result `done` flag');
+
+result = iterator.next();
+assert.sameValue(result.value, map, 'Third result `value` ("value")');
+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/values/this-not-object-throw.js b/test/built-ins/Map/prototype/values/this-not-object-throw.js
new file mode 100644
index 0000000000..116d2cef79
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/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.11
+description: >
+  Throws a TypeError if `this` is not an Object.
+info: >
+  Map.prototype.values ()
+
+  ...
+  2. Return CreateMapIterator(M, "values").
+
+  23.1.5.1 CreateMapIterator Abstract Operation
+
+  1. If Type(map) is not Object, throw a TypeError exception.
+  ...
+features: [Symbol]
+---*/
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call(false);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call(1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call('');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call(undefined);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call(null);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.values.call(Symbol());
+});
+
+assert.throws(TypeError, function() {
+  var map = new Map();
+  map.values.call(false);
+});
diff --git a/test/built-ins/Map/prototype/values/values.js b/test/built-ins/Map/prototype/values/values.js
new file mode 100644
index 0000000000..4489bbea28
--- /dev/null
+++ b/test/built-ins/Map/prototype/values/values.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.11
+description: >
+  Property type and descriptor.
+info: >
+  Map.prototype.values ()
+
+  17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  typeof Map.prototype.values,
+  'function',
+  '`typeof Map.prototype.values` is `function`'
+);
+
+verifyNotEnumerable(Map.prototype, 'values');
+verifyWritable(Map.prototype, 'values');
+verifyConfigurable(Map.prototype, 'values');
-- 
GitLab