From e44e0c176273dd6e2145bd18cd8365e35c0e2dd1 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 1 Jul 2015 12:15:00 -0400 Subject: [PATCH] WeakMap.prototype.delete --- .../delete/delete-entry-initial-iterable.js | 29 +++++++++++++++++ .../WeakMap/prototype/delete/delete-entry.js | 31 +++++++++++++++++++ .../WeakMap/prototype/delete/delete.js | 23 ++++++++++++++ ...ot-have-weakmapdata-internal-slot-array.js | 23 ++++++++++++++ ...-not-have-weakmapdata-internal-slot-map.js | 24 ++++++++++++++ ...t-have-weakmapdata-internal-slot-object.js | 23 ++++++++++++++ ...-not-have-weakmapdata-internal-slot-set.js | 24 ++++++++++++++ ...mapdata-internal-slot-weakmap-prototype.js | 23 ++++++++++++++ .../WeakMap/prototype/delete/length.js | 22 +++++++++++++ .../WeakMap/prototype/delete/name.js | 22 +++++++++++++ .../returns-false-value-is-not-object.js | 22 +++++++++++++ .../returns-false-when-delete-is-noop.js | 21 +++++++++++++ .../delete/this-not-object-throw-boolean.js | 20 ++++++++++++ .../delete/this-not-object-throw-null.js | 20 ++++++++++++ .../delete/this-not-object-throw-number.js | 20 ++++++++++++ .../delete/this-not-object-throw-string.js | 20 ++++++++++++ .../delete/this-not-object-throw-symbol.js | 21 +++++++++++++ .../delete/this-not-object-throw-undefined.js | 20 ++++++++++++ 18 files changed, 408 insertions(+) create mode 100644 test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js create mode 100644 test/built-ins/WeakMap/prototype/delete/delete-entry.js create mode 100644 test/built-ins/WeakMap/prototype/delete/delete.js create mode 100644 test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.js create mode 100644 test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-object.js create mode 100644 test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js create mode 100644 test/built-ins/WeakMap/prototype/delete/length.js create mode 100644 test/built-ins/WeakMap/prototype/delete/name.js create mode 100644 test/built-ins/WeakMap/prototype/delete/returns-false-value-is-not-object.js create mode 100644 test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.js create mode 100644 test/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.js create mode 100644 test/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.js create mode 100644 test/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.js create mode 100644 test/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.js create mode 100644 test/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.js create mode 100644 test/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.js diff --git a/test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js b/test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.js new file mode 100644 index 0000000000..b5858f5f28 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/delete-entry-initial-iterable.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.3.3.2 +description: > + Delete an entry from initial iterable. +info: > + WeakMap.prototype.delete ( value ) + + ... + 5. Let entries be the List that is the value of M’s [[WeakMapData]] internal + slot. + 6. If Type(key) is not Object, return false. + 7. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, then + i. Set p.[[key]] to empty. + ii. Set p.[[value]] to empty. + iii. Return true. + ... +---*/ + +var foo = {}; +var map = new WeakMap([[foo, 42]]); + +var result = map.delete(foo); + +assert.sameValue(map.has(foo), false); +assert.sameValue(result, true, 'WeakMap#delete returns true'); diff --git a/test/built-ins/WeakMap/prototype/delete/delete-entry.js b/test/built-ins/WeakMap/prototype/delete/delete-entry.js new file mode 100644 index 0000000000..8faa832ff9 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/delete-entry.js @@ -0,0 +1,31 @@ +// 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.3.3.2 +description: > + Delete an entry. +info: > + WeakMap.prototype.delete ( value ) + + ... + 5. Let entries be the List that is the value of M’s [[WeakMapData]] internal + slot. + 6. If Type(key) is not Object, return false. + 7. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, then + i. Set p.[[key]] to empty. + ii. Set p.[[value]] to empty. + iii. Return true. + ... +---*/ + +var foo = {}; +var map = new WeakMap(); + +map.set(foo, 42); + +var result = map.delete(foo); + +assert.sameValue(map.has(foo), false); +assert.sameValue(result, true, 'WeakMap#delete returns true'); diff --git a/test/built-ins/WeakMap/prototype/delete/delete.js b/test/built-ins/WeakMap/prototype/delete/delete.js new file mode 100644 index 0000000000..a75c7af1d5 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/delete.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.3.3.2 +description: > + WeakMap.prototype.delete property descriptor +info: > + WeakMap.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.delete, + 'function', + 'typeof WeakMap.prototype.delete is "function"' +); + +verifyNotEnumerable(WeakMap.prototype, 'delete'); +verifyWritable(WeakMap.prototype, 'delete'); +verifyConfigurable(WeakMap.prototype, 'delete'); diff --git a/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.js b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.js new file mode 100644 index 0000000000..8cc80bf620 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.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.3.3.2 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call([], {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call([], {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.js b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..cb5807eee7 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.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.3.3.2 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(new Map(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(new Map(), {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-object.js b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-object.js new file mode 100644 index 0000000000..94d6dcaed9 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-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.3.3.2 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call({}, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call({}, {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-set.js b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..c523557f91 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-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.3.3.2 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(new Set(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(new Set(), {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js new file mode 100644 index 0000000000..5ed3f33f4d --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.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.3.3.2 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(WeakMap.prototype, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(WeakMap.prototype, {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/length.js b/test/built-ins/WeakMap/prototype/delete/length.js new file mode 100644 index 0000000000..ff5dc74d82 --- /dev/null +++ b/test/built-ins/WeakMap/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.3.3.2 +description: > + WeakMap.prototype.delete.length value and writability. +info: > + WeakMap.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.delete.length, 1, + 'The value of WeakMap.prototype.delete.length is 1' +); + +verifyNotEnumerable(WeakMap.prototype.delete, 'length'); +verifyNotWritable(WeakMap.prototype.delete, 'length'); +verifyConfigurable(WeakMap.prototype.delete, 'length'); diff --git a/test/built-ins/WeakMap/prototype/delete/name.js b/test/built-ins/WeakMap/prototype/delete/name.js new file mode 100644 index 0000000000..31d28f728d --- /dev/null +++ b/test/built-ins/WeakMap/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.3.3.2 +description: > + WeakMap.prototype.delete.name value and writability. +info: > + WeakMap.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.delete.name, 'delete', + 'The value of WeakMap.prototype.delete.name is "delete"' +); + +verifyNotEnumerable(WeakMap.prototype.delete, 'name'); +verifyNotWritable(WeakMap.prototype.delete, 'name'); +verifyConfigurable(WeakMap.prototype.delete, 'name'); diff --git a/test/built-ins/WeakMap/prototype/delete/returns-false-value-is-not-object.js b/test/built-ins/WeakMap/prototype/delete/returns-false-value-is-not-object.js new file mode 100644 index 0000000000..b51ce25883 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/returns-false-value-is-not-object.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.3.3.2 +description: > + Return false if value is not an Object. +info: > + WeakMap.prototype.delete ( value ) + + 5. If Type(key) is not Object, return false. +features: [Symbol] +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.delete(1), false); +assert.sameValue(map.delete(''), false); +assert.sameValue(map.delete(NaN), false); +assert.sameValue(map.delete(null), false); +assert.sameValue(map.delete(undefined), false); +assert.sameValue(map.delete(true), false); +assert.sameValue(map.delete(Symbol()), false); diff --git a/test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.js b/test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.js new file mode 100644 index 0000000000..2e0bee9092 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/returns-false-when-delete-is-noop.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.3.3.2 +description: > + Return false if entry is not in the WeakMap. +info: > + WeakMap.prototype.delete ( value ) + + ... + 7. Return false. + +---*/ + +var map = new WeakMap(); +var foo = {}; +var bar = {}; + +map.set(foo, 42); + +assert.sameValue(map.delete(bar), false); diff --git a/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.js b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.js new file mode 100644 index 0000000000..cdb94487c1 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.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.3.3.2 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(false, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(false, {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.js b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.js new file mode 100644 index 0000000000..0cdb8ae681 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.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.3.3.2 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(null, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(null, {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.js b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.js new file mode 100644 index 0000000000..2143ede79d --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.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.3.3.2 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(0, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(0, {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.js b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.js new file mode 100644 index 0000000000..1ee40def3c --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.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.3.3.2 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call('', {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call('', {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.js b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.js new file mode 100644 index 0000000000..a368da9d6c --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.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.3.3.2 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(Symbol(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(Symbol(), {}); +}); diff --git a/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.js b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.js new file mode 100644 index 0000000000..30317c132d --- /dev/null +++ b/test/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.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.3.3.2 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(undefined, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(undefined, {}); +});