From e345635a75943d3a3ef43981022fbc541b4f208f Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Fri, 26 Jun 2015 16:39:08 -0400
Subject: [PATCH] Map.prototype.delete

---
 .../delete/context-is-not-map-object.js       | 23 +++++++++++
 .../prototype/delete/context-is-not-object.js | 38 +++++++++++++++++++
 .../delete/context-is-set-object-throws.js    | 20 ++++++++++
 .../context-is-weakmap-object-throws.js       | 20 ++++++++++
 test/built-ins/Map/prototype/delete/delete.js | 21 ++++++++++
 .../delete/does-not-break-iterators.js        | 32 ++++++++++++++++
 test/built-ins/Map/prototype/delete/length.js | 22 +++++++++++
 test/built-ins/Map/prototype/delete/name.js   | 22 +++++++++++
 .../Map/prototype/delete/returns-false.js     | 23 +++++++++++
 .../delete/returns-true-for-deleted-entry.js  | 24 ++++++++++++
 10 files changed, 245 insertions(+)
 create mode 100644 test/built-ins/Map/prototype/delete/context-is-not-map-object.js
 create mode 100644 test/built-ins/Map/prototype/delete/context-is-not-object.js
 create mode 100644 test/built-ins/Map/prototype/delete/context-is-set-object-throws.js
 create mode 100644 test/built-ins/Map/prototype/delete/context-is-weakmap-object-throws.js
 create mode 100644 test/built-ins/Map/prototype/delete/delete.js
 create mode 100644 test/built-ins/Map/prototype/delete/does-not-break-iterators.js
 create mode 100644 test/built-ins/Map/prototype/delete/length.js
 create mode 100644 test/built-ins/Map/prototype/delete/name.js
 create mode 100644 test/built-ins/Map/prototype/delete/returns-false.js
 create mode 100644 test/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.js

diff --git a/test/built-ins/Map/prototype/delete/context-is-not-map-object.js b/test/built-ins/Map/prototype/delete/context-is-not-map-object.js
new file mode 100644
index 0000000000..db993074e7
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/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.3
+description: >
+  Throws a TypeError if `this` does not have a [[MapData]] internal slot.
+info: >
+  Map.prototype.delete ( key )
+
+  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.delete.call({}, 'attr');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.delete.call([], 'attr');
+});
diff --git a/test/built-ins/Map/prototype/delete/context-is-not-object.js b/test/built-ins/Map/prototype/delete/context-is-not-object.js
new file mode 100644
index 0000000000..fe341ce526
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/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.3
+description: >
+  Throws a TypeError if `this` is not an Object.
+info: >
+  Map.prototype.delete ( 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.delete.call(1, 'attr');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.delete.call(true, 'attr');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.delete.call('', 'attr');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.delete.call(null, 'attr');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.delete.call(undefined, 'attr');
+});
+
+assert.throws(TypeError, function() {
+  Map.prototype.delete.call(Symbol(), 'attr');
+});
diff --git a/test/built-ins/Map/prototype/delete/context-is-set-object-throws.js b/test/built-ins/Map/prototype/delete/context-is-set-object-throws.js
new file mode 100644
index 0000000000..a9a38850e5
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/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.3
+description: >
+  Throws a TypeError if `this` is a Set object.
+info: >
+  Map.prototype.delete ( key )
+
+  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.delete.call(new Set(), 'attr');
+});
diff --git a/test/built-ins/Map/prototype/delete/context-is-weakmap-object-throws.js b/test/built-ins/Map/prototype/delete/context-is-weakmap-object-throws.js
new file mode 100644
index 0000000000..bda619f570
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/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.3
+description: >
+  Throws a TypeError if `this` is a WeakMap object.
+info: >
+  Map.prototype.delete ( key )
+
+  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.delete.call(new WeakMap(), 'attr');
+});
diff --git a/test/built-ins/Map/prototype/delete/delete.js b/test/built-ins/Map/prototype/delete/delete.js
new file mode 100644
index 0000000000..4bf8688efa
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/delete.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.3
+description: >
+    Map.prototype.delete ( )
+
+    17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+    typeof Map.prototype.delete,
+    'function',
+    'typeof Map.prototype.delete is "function"'
+);
+
+verifyNotEnumerable(Map.prototype, 'delete');
+verifyWritable(Map.prototype, 'delete');
+verifyConfigurable(Map.prototype, 'delete');
diff --git a/test/built-ins/Map/prototype/delete/does-not-break-iterators.js b/test/built-ins/Map/prototype/delete/does-not-break-iterators.js
new file mode 100644
index 0000000000..35c09f6594
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/does-not-break-iterators.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.3
+description: >
+  Deleting an entry does not break a [[MapData]] List.
+info: >
+  Map.prototype.delete ( 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, then
+      i. Set p.[[key]] to empty.
+      ii. Set p.[[value]] to empty.
+      iii. Return true.
+  ...
+---*/
+
+var m = new Map([['a',1], ['b', 2], ['c', 3]]);
+var e = m.entries();
+
+e.next();
+m.delete('b');
+
+var n = e.next();
+
+assert.sameValue(n.value[0], 'c');
+assert.sameValue(n.value[1], 3);
+
+n = e.next();
+assert.sameValue(n.value, undefined);
+assert.sameValue(n.done, true);
diff --git a/test/built-ins/Map/prototype/delete/length.js b/test/built-ins/Map/prototype/delete/length.js
new file mode 100644
index 0000000000..7ec03d5867
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/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.3
+description: >
+  Map.prototype.delete.length value and descriptor.
+info: >
+  Map.prototype.delete ( key )
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Map.prototype.delete.length, 1,
+  'The value of `Map.prototype.delete.length` is `1`'
+);
+
+verifyNotEnumerable(Map.prototype.delete, 'length');
+verifyNotWritable(Map.prototype.delete, 'length');
+verifyConfigurable(Map.prototype.delete, 'length');
diff --git a/test/built-ins/Map/prototype/delete/name.js b/test/built-ins/Map/prototype/delete/name.js
new file mode 100644
index 0000000000..b82efa02a7
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/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.3
+description: >
+  Map.prototype.delete.name value and descriptor.
+info: >
+  Map.prototype.delete ( key )
+
+  17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+  Map.prototype.delete.name, 'delete',
+  'The value of `Map.prototype.delete.name` is `"delete"`'
+);
+
+verifyNotEnumerable(Map.prototype.delete, 'name');
+verifyNotWritable(Map.prototype.delete, 'name');
+verifyConfigurable(Map.prototype.delete, 'name');
diff --git a/test/built-ins/Map/prototype/delete/returns-false.js b/test/built-ins/Map/prototype/delete/returns-false.js
new file mode 100644
index 0000000000..4152d58c23
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/returns-false.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.3
+description: >
+  Returns false when it does not delete an entry.
+info: >
+  Map.prototype.delete ( 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, then
+      ...
+      iii. Return true.
+  6. Return false.
+---*/
+
+var m = new Map([['a',1], ['b', 2]]);
+
+assert.sameValue(m.delete('not-in-the-map'), false);
+
+m.delete('a');
+assert.sameValue(m.delete('a'), false);
diff --git a/test/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.js b/test/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.js
new file mode 100644
index 0000000000..79c1e138f3
--- /dev/null
+++ b/test/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.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.3
+description: >
+  Returns true when deletes an entry.
+info: >
+  Map.prototype.delete ( 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, then
+      i. Set p.[[key]] to empty.
+      ii. Set p.[[value]] to empty.
+      iii. Return true.
+  ...
+---*/
+
+var m = new Map([['a',1], ['b', 2]]);
+
+var result = m.delete('a');
+
+assert(result);
+assert.sameValue(m.size, 1);
-- 
GitLab