From b103418a17a09d978800495be52b1a8a483c24f1 Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Mon, 29 Jun 2015 15:57:49 -0400
Subject: [PATCH] Map.prototype.get

---
 ...does-not-have-mapdata-internal-slot-set.js | 24 ++++++++++
 ...-not-have-mapdata-internal-slot-weakmap.js | 24 ++++++++++
 .../does-not-have-mapdata-internal-slot.js    | 32 +++++++++++++
 test/built-ins/Map/prototype/get/get.js       | 22 +++++++++
 test/built-ins/Map/prototype/get/length.js    | 22 +++++++++
 test/built-ins/Map/prototype/get/name.js      | 22 +++++++++
 .../Map/prototype/get/returns-undefined.js    | 41 ++++++++++++++++
 .../get/returns-value-different-key-types.js  | 48 +++++++++++++++++++
 .../get/returns-value-normalized-zero-key.js  | 25 ++++++++++
 .../prototype/get/this-not-object-throw.js    | 43 +++++++++++++++++
 10 files changed, 303 insertions(+)
 create mode 100644 test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js
 create mode 100644 test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js
 create mode 100644 test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js
 create mode 100644 test/built-ins/Map/prototype/get/get.js
 create mode 100644 test/built-ins/Map/prototype/get/length.js
 create mode 100644 test/built-ins/Map/prototype/get/name.js
 create mode 100644 test/built-ins/Map/prototype/get/returns-undefined.js
 create mode 100644 test/built-ins/Map/prototype/get/returns-value-different-key-types.js
 create mode 100644 test/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js
 create mode 100644 test/built-ins/Map/prototype/get/this-not-object-throw.js

diff --git a/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js
new file mode 100644
index 0000000000..94a00466bc
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js
@@ -0,0 +1,24 @@
+// 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.6
+description: >
+  Throws a TypeError if `this` is a Set object.
+info: >
+  Map.prototype.get ( key )
+
+  ...
+  3. If M does not have a [[MapData]] internal slot, throw a TypeError
+  exception.
+  ...
+features: [Set]
+---*/
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call(new Set(), 1);
+});
+
+assert.throws(TypeError, function() {
+  var m = new Map();
+  m.get.call(new Set(), 1);
+});
diff --git a/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js
new file mode 100644
index 0000000000..535c655755
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js
@@ -0,0 +1,24 @@
+// 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.6
+description: >
+  Throws a TypeError if `this` is a WeakMap object.
+info: >
+  Map.prototype.get ( key )
+
+  ...
+  3. If M does not have a [[MapData]] internal slot, throw a TypeError
+  exception.
+  ...
+features: [WeakMap]
+---*/
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call(new WeakMap(), 1);
+});
+
+assert.throws(TypeError, function() {
+  var m = new Map();
+  m.get.call(new WeakMap(), 1);
+});
diff --git a/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js b/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js
new file mode 100644
index 0000000000..50f7ecc3b6
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js
@@ -0,0 +1,32 @@
+// 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.6
+description: >
+  Throws a TypeError if `this` object does not have a [[MapData]] internal slot.
+info: >
+  Map.prototype.get ( key )
+
+  ...
+  3. If M does not have a [[MapData]] internal slot, throw a TypeError
+  exception.
+  ...
+---*/
+
+var m = new Map();
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call([], 1);
+});
+
+assert.throws(TypeError, function() {
+  m.get.call([], 1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call({}, 1);
+});
+
+assert.throws(TypeError, function() {
+  m.get.call({}, 1);
+});
diff --git a/test/built-ins/Map/prototype/get/get.js b/test/built-ins/Map/prototype/get/get.js
new file mode 100644
index 0000000000..dc455d5b20
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/get.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.6
+description: >
+  Property type and descriptor.
+info: >
+  Map.prototype.get ( key )
+
+  17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  typeof Map.prototype.get,
+  'function',
+  '`typeof Map.prototype.get` is `function`'
+);
+
+verifyNotEnumerable(Map.prototype, 'get');
+verifyWritable(Map.prototype, 'get');
+verifyConfigurable(Map.prototype, 'get');
diff --git a/test/built-ins/Map/prototype/get/length.js b/test/built-ins/Map/prototype/get/length.js
new file mode 100644
index 0000000000..1cf71d3245
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/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.6
+description: >
+  Map.prototype.get.length value and descriptor.
+info: >
+  Map.prototype.get ( key )
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Map.prototype.get.length, 1,
+  'The value of `Map.prototype.get.length` is `1`'
+);
+
+verifyNotEnumerable(Map.prototype.get, 'length');
+verifyNotWritable(Map.prototype.get, 'length');
+verifyConfigurable(Map.prototype.get, 'length');
diff --git a/test/built-ins/Map/prototype/get/name.js b/test/built-ins/Map/prototype/get/name.js
new file mode 100644
index 0000000000..1ddbf258c8
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/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.6
+description: >
+  Map.prototype.get.name value and descriptor.
+info: >
+  Map.prototype.get ( key )
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Map.prototype.get.name, 'get',
+  'The value of `Map.prototype.get.name` is `"get"`'
+);
+
+verifyNotEnumerable(Map.prototype.get, 'name');
+verifyNotWritable(Map.prototype.get, 'name');
+verifyConfigurable(Map.prototype.get, 'name');
diff --git a/test/built-ins/Map/prototype/get/returns-undefined.js b/test/built-ins/Map/prototype/get/returns-undefined.js
new file mode 100644
index 0000000000..3adcdd16f1
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/returns-undefined.js
@@ -0,0 +1,41 @@
+// 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.6
+description: >
+  Returns undefined when key is not on the map.
+info: >
+  Map.prototype.get ( key )
+
+  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. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
+    return p.[[value]].
+  6. Return undefined.
+  ...
+---*/
+
+var map = new Map();
+
+assert.sameValue(
+  map.get('item'), undefined,
+ 'returns undefined if key is not on the map'
+);
+
+map.set('item', 1);
+map.set('another_item', 2);
+map.delete('item');
+
+assert.sameValue(
+  map.get('item'), undefined,
+  'returns undefined if key was deleted'
+);
+
+map.set('item', 1);
+map.clear();
+
+assert.sameValue(
+  map.get('item'), undefined,
+  'returns undefined after map is cleared'
+);
diff --git a/test/built-ins/Map/prototype/get/returns-value-different-key-types.js b/test/built-ins/Map/prototype/get/returns-value-different-key-types.js
new file mode 100644
index 0000000000..8f7ea286d2
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/returns-value-different-key-types.js
@@ -0,0 +1,48 @@
+// 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.6
+description: >
+  Returns the value from the specified key on different types.
+info: >
+  Map.prototype.get ( key )
+
+  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. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
+    return p.[[value]].
+  ...
+features: [Symbol]
+---*/
+
+var map = new Map();
+
+map.set('bar', 0);
+assert.sameValue(map.get('bar'), 0);
+
+map.set(1, 42);
+assert.sameValue(map.get(1), 42);
+
+map.set(NaN, 1);
+assert.sameValue(map.get(NaN), 1);
+
+var item = {};
+map.set(item, 2);
+assert.sameValue(map.get(item), 2);
+
+item = [];
+map.set(item, 3);
+assert.sameValue(map.get(item), 3);
+
+item = Symbol('item');
+map.set(item, 4);
+assert.sameValue(map.get(item), 4);
+
+item = null;
+map.set(item, 5);
+assert.sameValue(map.get(item), 5);
+
+item = undefined;
+map.set(item, 6);
+assert.sameValue(map.get(item), 6);
diff --git a/test/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js b/test/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js
new file mode 100644
index 0000000000..93a9ee8424
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js
@@ -0,0 +1,25 @@
+// 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.6
+description: >
+  -0 and +0 are normalized to +0;
+info: >
+  Map.prototype.get ( key )
+
+  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. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true,
+    return p.[[value]].
+  ...
+---*/
+
+var map = new Map();
+
+map.set(+0, 42);
+assert.sameValue(map.get(-0), 42);
+
+map = new Map();
+map.set(-0, 43);
+assert.sameValue(map.get(+0), 43);
diff --git a/test/built-ins/Map/prototype/get/this-not-object-throw.js b/test/built-ins/Map/prototype/get/this-not-object-throw.js
new file mode 100644
index 0000000000..44ac9d9cb4
--- /dev/null
+++ b/test/built-ins/Map/prototype/get/this-not-object-throw.js
@@ -0,0 +1,43 @@
+// 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.6
+description: >
+  Throws a TypeError if `this` is not an Object.
+info: >
+  Map.prototype.get ( key )
+
+  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.get.call(false, 1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call(1, 1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call('', 1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call(undefined, 1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call(null, 1);
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.get.call(Symbol(), 1);
+});
+
+assert.throws(TypeError, function() {
+  var map = new Map();
+  map.get.call(false, 1);
+});
-- 
GitLab