From 7acd163264db86b390c80b5b85bcf343e2718bfd Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 1 Jul 2015 14:46:15 -0400 Subject: [PATCH] WeakMap.prototype.get --- ...-not-have-weakmapdata-internal-slot-map.js | 24 +++++++++++ ...-not-have-weakmapdata-internal-slot-set.js | 24 +++++++++++ ...does-not-have-weakmapdata-internal-slot.js | 31 +++++++++++++ test/built-ins/WeakMap/prototype/get/get.js | 22 ++++++++++ .../built-ins/WeakMap/prototype/get/length.js | 22 ++++++++++ test/built-ins/WeakMap/prototype/get/name.js | 22 ++++++++++ .../returns-undefined-key-is-not-object.js | 41 ++++++++++++++++++ .../prototype/get/returns-undefined.js | 37 ++++++++++++++++ .../WeakMap/prototype/get/returns-value.js | 31 +++++++++++++ .../prototype/get/this-not-object-throw.js | 43 +++++++++++++++++++ 10 files changed, 297 insertions(+) create mode 100644 test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js create mode 100644 test/built-ins/WeakMap/prototype/get/get.js create mode 100644 test/built-ins/WeakMap/prototype/get/length.js create mode 100644 test/built-ins/WeakMap/prototype/get/name.js create mode 100644 test/built-ins/WeakMap/prototype/get/returns-undefined-key-is-not-object.js create mode 100644 test/built-ins/WeakMap/prototype/get/returns-undefined.js create mode 100644 test/built-ins/WeakMap/prototype/get/returns-value.js create mode 100644 test/built-ins/WeakMap/prototype/get/this-not-object-throw.js diff --git a/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js b/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..1bbc12bcc2 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/get/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.3 +description: > + Throws a TypeError if `this` is a Map object. +info: > + WeakMap.prototype.get ( key ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(new Map(), 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.get.call(new Map(), 1); +}); diff --git a/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js b/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..a317baf680 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/get/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.3 +description: > + Throws a TypeError if `this` is a Set object. +info: > + WeakMap.prototype.get ( key ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(new Set(), 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.get.call(new Set(), 1); +}); diff --git a/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js b/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js new file mode 100644 index 0000000000..aebef87569 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.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.3 +description: > + Throws a TypeError if `this` does not have a [[WeakMapData]] internal slot. +info: > + WeakMap.prototype.get ( key ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ +var map = new WeakMap(); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call([], 1); +}); + +assert.throws(TypeError, function() { + map.get.call([], 1); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call({}, 1); +}); + +assert.throws(TypeError, function() { + map.get.call({}, 1); +}); diff --git a/test/built-ins/WeakMap/prototype/get/get.js b/test/built-ins/WeakMap/prototype/get/get.js new file mode 100644 index 0000000000..e2610284de --- /dev/null +++ b/test/built-ins/WeakMap/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.3.3.3 +description: > + Property type and descriptor. +info: > + WeakMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.get, + 'function', + '`typeof WeakMap.prototype.get` is `function`' +); + +verifyNotEnumerable(WeakMap.prototype, 'get'); +verifyWritable(WeakMap.prototype, 'get'); +verifyConfigurable(WeakMap.prototype, 'get'); diff --git a/test/built-ins/WeakMap/prototype/get/length.js b/test/built-ins/WeakMap/prototype/get/length.js new file mode 100644 index 0000000000..48ed357af2 --- /dev/null +++ b/test/built-ins/WeakMap/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.3.3.3 +description: > + WeakMap.prototype.get.length value and descriptor. +info: > + WeakMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.get.length, 1, + 'The value of `WeakMap.prototype.get.length` is `1`' +); + +verifyNotEnumerable(WeakMap.prototype.get, 'length'); +verifyNotWritable(WeakMap.prototype.get, 'length'); +verifyConfigurable(WeakMap.prototype.get, 'length'); diff --git a/test/built-ins/WeakMap/prototype/get/name.js b/test/built-ins/WeakMap/prototype/get/name.js new file mode 100644 index 0000000000..28ed494c1e --- /dev/null +++ b/test/built-ins/WeakMap/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.3.3.3 +description: > + WeakMap.prototype.get.name value and descriptor. +info: > + WeakMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.get.name, 'get', + 'The value of `WeakMap.prototype.get.name` is `"get"`' +); + +verifyNotEnumerable(WeakMap.prototype.get, 'name'); +verifyNotWritable(WeakMap.prototype.get, 'name'); +verifyConfigurable(WeakMap.prototype.get, 'name'); diff --git a/test/built-ins/WeakMap/prototype/get/returns-undefined-key-is-not-object.js b/test/built-ins/WeakMap/prototype/get/returns-undefined-key-is-not-object.js new file mode 100644 index 0000000000..0785269756 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/get/returns-undefined-key-is-not-object.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.3.3.3 +description: > + Returns undefined when key is not an Object. +info: > + WeakMap.prototype.get ( key ) + + ... + 4. Let entries be the List that is the value of M’s [[WeakMapData]] internal + slot. + 5. If Type(key) is not Object, return undefined. + ... +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.get(null), undefined, 'Returns undefined if key is null'); + +assert.sameValue(map.get(NaN), undefined, 'Returns undefined if key is NaN'); + +assert.sameValue( + map.get('foo'), undefined, + 'Returns undefined if key is a String' +); + +assert.sameValue( + map.get(1), undefined, + 'Returns undefined if key is a Number' +); + +assert.sameValue( + map.get(undefined), undefined, + 'Returns undefined if key is undefined' +); + +assert.sameValue( + map.get(Symbol()), undefined, + 'Returns undefined if key is a Symbol' +); diff --git a/test/built-ins/WeakMap/prototype/get/returns-undefined.js b/test/built-ins/WeakMap/prototype/get/returns-undefined.js new file mode 100644 index 0000000000..ff3b22cd6a --- /dev/null +++ b/test/built-ins/WeakMap/prototype/get/returns-undefined.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.3 +description: > + Returns undefined when key is not on the WeakMap object. +info: > + WeakMap.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[WeakMapData]] internal + slot. + 5. If Type(key) is not Object, return undefined. + 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, return + p.[[value]]. + 7. Return undefined. + ... +---*/ + +var map = new WeakMap(); +var key = {}; + +assert.sameValue( + map.get(key), undefined, + 'returns undefined if key is not on the weakmap' +); + +map.set(key, 1); +map.set({}, 2); +map.delete(key); +map.set({}, 3); + +assert.sameValue( + map.get(key), undefined, + 'returns undefined if key was deleted' +); diff --git a/test/built-ins/WeakMap/prototype/get/returns-value.js b/test/built-ins/WeakMap/prototype/get/returns-value.js new file mode 100644 index 0000000000..143e641219 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/get/returns-value.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.3 +description: > + Returns the value from the specified key +info: > + WeakMap.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[WeakMapData]] internal + slot. + 5. If Type(key) is not Object, return undefined. + 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, return + p.[[value]]. + ... +---*/ + +var foo = {}; +var bar = {}; +var baz = []; +var map = new WeakMap([[foo,0]]); + +assert.sameValue(map.get(foo), 0); + +map.set(bar, 1); +assert.sameValue(map.get(bar), 1); + +map.set(baz, 2); +assert.sameValue(map.get(baz), 2); diff --git a/test/built-ins/WeakMap/prototype/get/this-not-object-throw.js b/test/built-ins/WeakMap/prototype/get/this-not-object-throw.js new file mode 100644 index 0000000000..7113ae22f2 --- /dev/null +++ b/test/built-ins/WeakMap/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.3.3.3 +description: > + Throws a TypeError if `this` value is not an Object. +info: > + WeakMap.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() { + WeakMap.prototype.get.call(false, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(1, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call('', {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(undefined, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(null, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(Symbol(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.get.call(false, {}); +});