Reviewers: rossberg,

Message:
PTAL.

Description:
Fix Harmony sets and maps to allow undefined as keys.

This uses a global sentinel as a replacement for undefined keys, which
are not supported internally but required for Harmony sets and maps.

[email protected]
BUG=v8:1622
TEST=mjsunit/harmony/collections


Please review this at http://codereview.chromium.org/8439069/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/collection.js
  M test/mjsunit/harmony/collections.js


Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index 4e45885b96d524954110b6a76c0ffc7339036201..12ff893742982aba91776f18c6e7391315cd933e 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -32,6 +32,11 @@ const $WeakMap = global.WeakMap;

 //-------------------------------------------------------------------

+// Global sentinel to be used instead of undefined keys, which are not
+// supported internally but required for Harmony sets and maps.
+var undefined_sentinel = {};
+
+
 function SetConstructor() {
   if (%_IsConstructCall()) {
     %SetInitialize(this);
@@ -42,16 +47,25 @@ function SetConstructor() {


 function SetAdd(key) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   return %SetAdd(this, key);
 }


 function SetHas(key) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   return %SetHas(this, key);
 }


 function SetDelete(key) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   return %SetDelete(this, key);
 }

@@ -66,21 +80,33 @@ function MapConstructor() {


 function MapGet(key) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   return %MapGet(this, key);
 }


 function MapSet(key, value) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   return %MapSet(this, key, value);
 }


 function MapHas(key) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   return !IS_UNDEFINED(%MapGet(this, key));
 }


 function MapDelete(key) {
+  if (IS_UNDEFINED(key)) {
+    key = undefined_sentinel;
+  }
   if (!IS_UNDEFINED(%MapGet(this, key))) {
     %MapSet(this, key, void 0);
     return true;
Index: test/mjsunit/harmony/collections.js
diff --git a/test/mjsunit/harmony/collections.js b/test/mjsunit/harmony/collections.js index d3c6c0f258030474dc717b27997c74c064630870..7e024ebfe86e6639b4d86ecd94e69904848ab087 100644
--- a/test/mjsunit/harmony/collections.js
+++ b/test/mjsunit/harmony/collections.js
@@ -101,7 +101,7 @@ function TestMapBehavior2(m) {
     TestMapping(m, i / 10, new Object);
     TestMapping(m, 'key-' + i, new Object);
   }
-  var keys = [ +0, -0, +Infinity, -Infinity, true, false, null ];
+ var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ];
   for (var i = 0; i < keys.length; i++) {
     TestMapping(m, keys[i], new Object);
   }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to