summaryrefslogtreecommitdiff
path: root/test/built-ins/WeakMap
diff options
context:
space:
mode:
authorLeonardo Balter <leonardo.balter@gmail.com>2015-07-01 14:46:15 -0400
committerLeonardo Balter <leonardo.balter@gmail.com>2015-07-10 14:31:26 -0400
commit7acd163264db86b390c80b5b85bcf343e2718bfd (patch)
treed99e1d6b10ab46caa3c1bd9cd98c74dcd031556b /test/built-ins/WeakMap
parente44e0c176273dd6e2145bd18cd8365e35c0e2dd1 (diff)
downloadqtdeclarative-testsuites-7acd163264db86b390c80b5b85bcf343e2718bfd.tar.gz
WeakMap.prototype.get
Diffstat (limited to 'test/built-ins/WeakMap')
-rw-r--r--test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js24
-rw-r--r--test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js24
-rw-r--r--test/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js31
-rw-r--r--test/built-ins/WeakMap/prototype/get/get.js22
-rw-r--r--test/built-ins/WeakMap/prototype/get/length.js22
-rw-r--r--test/built-ins/WeakMap/prototype/get/name.js22
-rw-r--r--test/built-ins/WeakMap/prototype/get/returns-undefined-key-is-not-object.js41
-rw-r--r--test/built-ins/WeakMap/prototype/get/returns-undefined.js37
-rw-r--r--test/built-ins/WeakMap/prototype/get/returns-value.js31
-rw-r--r--test/built-ins/WeakMap/prototype/get/this-not-object-throw.js43
10 files changed, 297 insertions, 0 deletions
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 000000000..1bbc12bcc
--- /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 000000000..a317baf68
--- /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 000000000..aebef8756
--- /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 000000000..e2610284d
--- /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 000000000..48ed357af
--- /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 000000000..28ed494c1
--- /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 000000000..078526975
--- /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 000000000..ff3b22cd6
--- /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 000000000..143e64121
--- /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 000000000..7113ae22f
--- /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, {});
+});