summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js')
-rw-r--r--js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js
new file mode 100644
index 0000000000..a4844b9244
--- /dev/null
+++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js
@@ -0,0 +1,37 @@
+// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options
+// Copyright (C) 2022 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-weakmap.prototype.get
+description: >
+ Returns undefined when a Symbol key is not on the WeakMap object.
+info: |
+ WeakMap.prototype.get ( _key_ )
+ 3. Let _entries_ be the List that is _M_.[[WeakMapData]].
+ 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*.
+ 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do
+ a. If _p_.[[Key]] is not empty and SameValue(_p_.[[Key]], _key_) is *true*,
+ return _p_.[[Value]].
+ 6. Return *undefined*.
+features: [Symbol, WeakMap, symbols-as-weakmap-keys]
+---*/
+
+var map = new WeakMap();
+var key = Symbol('a description');
+
+assert.sameValue(map.get(key), undefined, 'returns undefined for regular symbol on initially empty map');
+assert.sameValue(
+ map.get(Symbol.hasInstance),
+ undefined,
+ 'returns undefined for well-known symbol on initially empty map'
+);
+
+map.set(key, 1);
+map.set(Symbol.hasInstance, 2);
+map.delete(key);
+map.delete(Symbol.hasInstance);
+
+assert.sameValue(map.get(key), undefined, 'returns undefined for deleted regular symbol');
+assert.sameValue(map.get(Symbol.hasInstance), undefined, 'returns undefined for deleted well-known symbol');
+
+reportCompare(0, 0);