Bug 645416, part 7 - Support symbols as Map keys. r=terrence.
authorJason Orendorff <jorendorff@mozilla.com>
Mon, 23 Jun 2014 10:56:48 -0500
changeset 190274 cdf258b25a12c688a7821f6351dd06ea6d99b93f
parent 190273 e08a6942e21cbd09bd9a976f76115386e4b48fb9
child 190275 0513197d722ecddd0b7a3f3a8a4caa7b6bc9f39f
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersterrence
bugs645416
milestone33.0a1
Bug 645416, part 7 - Support symbols as Map keys. r=terrence.
js/src/builtin/MapObject.cpp
js/src/tests/ecma_6/Map/symbols.js
js/src/tests/ecma_6/Set/symbols.js
js/src/tests/ecma_6/WeakMap/browser.js
js/src/tests/ecma_6/WeakMap/shell.js
js/src/tests/ecma_6/WeakMap/symbols.js
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -792,18 +792,18 @@ HashableValue::setValue(JSContext *cx, H
             value = DoubleNaNValue();
         } else {
             value = v;
         }
     } else {
         value = v;
     }
 
-    JS_ASSERT(value.isUndefined() || value.isNull() || value.isBoolean() ||
-              value.isNumber() || value.isString() || value.isObject());
+    JS_ASSERT(value.isUndefined() || value.isNull() || value.isBoolean() || value.isNumber() ||
+              value.isString() || value.isSymbol() || value.isObject());
     return true;
 }
 
 HashNumber
 HashableValue::hash() const
 {
     // HashableValue::setValue normalizes values so that the SameValue relation
     // on HashableValues is the same as the == relationship on
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Map/symbols.js
@@ -0,0 +1,21 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+var m = new Map;
+
+// Symbols can be Map keys.
+var sym = Symbol();
+m.set(sym, "zero");
+assertEq(m.has(sym), true);
+assertEq(m.get(sym), "zero");
+assertEq(m.has(Symbol()), false);
+assertEq(m.get(Symbol()), undefined);
+assertEq([...m][0][0], sym);
+m.set(sym, "replaced");
+assertEq(m.get(sym), "replaced");
+m.delete(sym);
+assertEq(m.has(sym), false);
+assertEq(m.size, 0);
+
+if (typeof reportCompare === "function")
+  reportCompare(0, 0);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Set/symbols.js
@@ -0,0 +1,20 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+var s = new Set;
+
+// Symbols can be stored in Sets.
+var sym = Symbol();
+s.add(sym);
+assertEq(s.has(sym), true);
+assertEq(s.has(Symbol()), false);
+assertEq([...s][0], sym);
+s.add(sym);
+assertEq(s.has(sym), true);
+assertEq(s.size, 1);
+s.delete(sym);
+assertEq(s.has(sym), false);
+assertEq(s.size, 0);
+
+if (typeof reportCompare === "function")
+  reportCompare(0, 0);
new file mode 100644
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/WeakMap/symbols.js
@@ -0,0 +1,10 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+// Symbols can't be WeakMap keys.
+var m = new WeakMap;
+var sym = Symbol();
+assertThrowsInstanceOf(() => m.set(sym, 0), TypeError);
+
+if (typeof reportCompare === "function")
+  reportCompare(0, 0);