// supported internally but required for Harmony sets and maps.
var undefined_sentinel = {};
+
+// Map and Set uses SameValueZero which means that +0 and -0 should be treated
+// as the same value.
+function NormalizeKey(key) {
+ if (IS_UNDEFINED(key)) {
+ return undefined_sentinel;
+ }
+
+ if (key === 0) {
+ return 0;
+ }
+
+ return key;
+}
+
+
// -------------------------------------------------------------------
// Harmony Set
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.add', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
- return %SetAdd(this, key);
+ return %SetAdd(this, NormalizeKey(key));
}
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.has', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
- return %SetHas(this, key);
+ return %SetHas(this, NormalizeKey(key));
}
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.delete', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
+ key = NormalizeKey(key);
if (%SetHas(this, key)) {
%SetDelete(this, key);
return true;
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.get', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
- return %MapGet(this, key);
+ return %MapGet(this, NormalizeKey(key));
}
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.set', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
- return %MapSet(this, key, value);
+ return %MapSet(this, NormalizeKey(key), value);
}
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.has', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
- return %MapHas(this, key);
+ return %MapHas(this, NormalizeKey(key));
}
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.delete', this]);
}
- if (IS_UNDEFINED(key)) {
- key = undefined_sentinel;
- }
- return %MapDelete(this, key);
+ return %MapDelete(this, NormalizeKey(key));
}