From 74665f055879fdc2d585007013bfd3ec1aa0076c Mon Sep 17 00:00:00 2001 From: Leonardo Balter <leonardo.balter@gmail.com> Date: Wed, 1 Jul 2015 15:31:15 -0400 Subject: [PATCH] WeakMap.prototype.set --- .../WeakMap/prototype/set/adds-element.js | 27 ++++++++++++++ ...ot-have-weakmapdata-internal-slot-array.js | 24 ++++++++++++ ...-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 ++++++++++++ .../prototype/set/key-not-object-throw.js | 37 +++++++++++++++++++ .../built-ins/WeakMap/prototype/set/length.js | 21 +++++++++++ test/built-ins/WeakMap/prototype/set/name.js | 21 +++++++++++ .../returns-this-when-ignoring-duplicate.js | 22 +++++++++++ .../WeakMap/prototype/set/returns-this.js | 17 +++++++++ test/built-ins/WeakMap/prototype/set/set.js | 22 +++++++++++ .../set/this-not-object-throw-boolean.js | 20 ++++++++++ .../set/this-not-object-throw-null.js | 20 ++++++++++ .../set/this-not-object-throw-number.js | 20 ++++++++++ .../set/this-not-object-throw-string.js | 20 ++++++++++ .../set/this-not-object-throw-symbol.js | 21 +++++++++++ .../set/this-not-object-throw-undefined.js | 20 ++++++++++ 18 files changed, 406 insertions(+) create mode 100644 test/built-ins/WeakMap/prototype/set/adds-element.js create mode 100644 test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js create mode 100644 test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js create mode 100644 test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js create mode 100644 test/built-ins/WeakMap/prototype/set/key-not-object-throw.js create mode 100644 test/built-ins/WeakMap/prototype/set/length.js create mode 100644 test/built-ins/WeakMap/prototype/set/name.js create mode 100644 test/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js create mode 100644 test/built-ins/WeakMap/prototype/set/returns-this.js create mode 100644 test/built-ins/WeakMap/prototype/set/set.js create mode 100644 test/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.js create mode 100644 test/built-ins/WeakMap/prototype/set/this-not-object-throw-null.js create mode 100644 test/built-ins/WeakMap/prototype/set/this-not-object-throw-number.js create mode 100644 test/built-ins/WeakMap/prototype/set/this-not-object-throw-string.js create mode 100644 test/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.js create mode 100644 test/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.js diff --git a/test/built-ins/WeakMap/prototype/set/adds-element.js b/test/built-ins/WeakMap/prototype/set/adds-element.js new file mode 100644 index 0000000000..0b0d86f63e --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/adds-element.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.3.3.5 +description: > + Appends value as the last element of entries. +info: > + WeakMap.prototype.set ( key, value ) + + ... + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + ... +---*/ + +var map = new WeakMap(); +var foo = {}; +var bar = {}; +var baz = {}; + +map.set(foo, 1); +map.set(bar, 2); +map.set(baz, 3); + +assert(map.has(foo)); +assert(map.has(bar)); +assert(map.has(baz)); diff --git a/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js b/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js new file mode 100644 index 0000000000..b98e11d2fd --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.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.5 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call([], {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call([], {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js b/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..b17dbc7f63 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(new Map(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(new Map(), {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js b/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js new file mode 100644 index 0000000000..5adc57bc59 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call({}, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call({}, {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js b/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..0ef36a5937 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(new Set(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(new Set(), {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js b/test/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js new file mode 100644 index 0000000000..59d4308dde --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(WeakMap.prototype, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(WeakMap.prototype, {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/key-not-object-throw.js b/test/built-ins/WeakMap/prototype/set/key-not-object-throw.js new file mode 100644 index 0000000000..4b4031d1c5 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/key-not-object-throw.js @@ -0,0 +1,37 @@ +// 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.5 +description: Throws TypeError if `key` is not Object. +info: > + WeakMap.prototype.set ( key, value ) + + 5. If Type(key) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var s = new WeakMap(); + +assert.throws(TypeError, function() { + s.set(1, 1); +}); + +assert.throws(TypeError, function() { + s.set(false, 1); +}); + +assert.throws(TypeError, function() { + s.set(undefined, 1); +}); + +assert.throws(TypeError, function() { + s.set('string', 1); +}); + +assert.throws(TypeError, function() { + s.set(null, 1); +}); + +assert.throws(TypeError, function() { + s.set(Symbol(), 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/length.js b/test/built-ins/WeakMap/prototype/set/length.js new file mode 100644 index 0000000000..0d687e51f2 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/length.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.5 +description: WeakMap.prototype.set.length descriptor +info: > + WeakMap.prototype.set ( key, value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.set.length, 2, + 'The value of `WeakMap.prototype.set.length` is `2`' +); + +verifyNotEnumerable(WeakMap.prototype.set, 'length'); +verifyNotWritable(WeakMap.prototype.set, 'length'); +verifyConfigurable(WeakMap.prototype.set, 'length'); diff --git a/test/built-ins/WeakMap/prototype/set/name.js b/test/built-ins/WeakMap/prototype/set/name.js new file mode 100644 index 0000000000..9c4f63080f --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/name.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.5 +description: WeakMap.prototype.set.name descriptor +info: > + WeakMap.prototype.set ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.set.name, 'set', + 'The value of WeakMap.prototype.set.name is "set"' +); + +verifyNotEnumerable(WeakMap.prototype.set, 'name'); +verifyNotWritable(WeakMap.prototype.set, 'name'); +verifyConfigurable(WeakMap.prototype.set, 'name'); diff --git a/test/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js b/test/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js new file mode 100644 index 0000000000..b722125046 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.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.5 +description: Returns `this` when new value is duplicate. +info: > + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + ... + 6. 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.[[value]] to value. + ii. Return M. + ... +---*/ + +var foo = {}; +var map = new WeakMap([[foo, 1]]); + +assert.sameValue(map.set(foo, 1), map, '`map.set(foo, 1)` returns `map`'); diff --git a/test/built-ins/WeakMap/prototype/set/returns-this.js b/test/built-ins/WeakMap/prototype/set/returns-this.js new file mode 100644 index 0000000000..d92c5fc801 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/returns-this.js @@ -0,0 +1,17 @@ +// 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.5 +description: Returns `this` after setting a new value. +info: > + WeakMap.prototype.set ( key, value ) + + 1. Let M be this value. + ... + 9. Return M. + +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.set({}, 1), map, '`map.set({}, 1)` returns `map`'); diff --git a/test/built-ins/WeakMap/prototype/set/set.js b/test/built-ins/WeakMap/prototype/set/set.js new file mode 100644 index 0000000000..173b3e0ebf --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/set.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.5 +description: WeakMap.prototype.set property descriptor +info: > + WeakMap.prototype.set ( key, value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.set, + 'function', + 'typeof WeakMap.prototype.set is "function"' +); + +verifyNotEnumerable(WeakMap.prototype, 'set'); +verifyWritable(WeakMap.prototype, 'set'); +verifyConfigurable(WeakMap.prototype, 'set'); diff --git a/test/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.js b/test/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.js new file mode 100644 index 0000000000..e36b6201e7 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.set ( key, 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.set.call(false, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(false, {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/this-not-object-throw-null.js b/test/built-ins/WeakMap/prototype/set/this-not-object-throw-null.js new file mode 100644 index 0000000000..dba5205606 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.set ( key, 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.set.call(null, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(null, {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/this-not-object-throw-number.js b/test/built-ins/WeakMap/prototype/set/this-not-object-throw-number.js new file mode 100644 index 0000000000..e4745ca50e --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.set ( key, 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.set.call(0, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(0, {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/this-not-object-throw-string.js b/test/built-ins/WeakMap/prototype/set/this-not-object-throw-string.js new file mode 100644 index 0000000000..8764b24258 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.set ( key, 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.set.call('', {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call('', {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.js b/test/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.js new file mode 100644 index 0000000000..c7f1cfe453 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.set ( key, 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.set.call(Symbol(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(Symbol(), {}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.js b/test/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.js new file mode 100644 index 0000000000..4c8d0fdfff --- /dev/null +++ b/test/built-ins/WeakMap/prototype/set/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.5 +description: Throws TypeError if `this` is not Object. +info: > + WeakMap.prototype.set ( key, 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.set.call(undefined, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(undefined, {}, 1); +}); -- GitLab