var $Set = global.Set;
var $Map = global.Map;
-// Global sentinel to be used instead of undefined keys, which are not
-// 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]);
}
- return %SetAdd(this, NormalizeKey(key));
+ return %SetAdd(this, key);
}
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.has', this]);
}
- return %SetHas(this, NormalizeKey(key));
+ return %SetHas(this, key);
}
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.delete', this]);
}
- key = NormalizeKey(key);
if (%SetHas(this, key)) {
%SetDelete(this, key);
return true;
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.get', this]);
}
- return %MapGet(this, NormalizeKey(key));
+ return %MapGet(this, key);
}
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.set', this]);
}
- return %MapSet(this, NormalizeKey(key), value);
+ return %MapSet(this, key, value);
}
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.has', this]);
}
- return %MapHas(this, NormalizeKey(key));
+ return %MapHas(this, key);
}
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.delete', this]);
}
- return %MapDelete(this, NormalizeKey(key));
+ return %MapDelete(this, key);
}
}
+bool Object::SameValueZero(Object* other) {
+ if (other == this) return true;
+
+ // The object is either a number, a name, an odd-ball,
+ // a real JS object, or a Harmony proxy.
+ if (IsNumber() && other->IsNumber()) {
+ double this_value = Number();
+ double other_value = other->Number();
+ // +0 == -0 is true
+ return this_value == other_value
+ || (std::isnan(this_value) && std::isnan(other_value));
+ }
+ if (IsString() && other->IsString()) {
+ return String::cast(this)->Equals(String::cast(other));
+ }
+ return false;
+}
+
+
void Object::ShortPrint(FILE* out) {
HeapStringAllocator allocator;
StringStream accumulator(&allocator);
entry != kNotFound;
entry = ChainAt(entry)) {
Object* candidate = KeyAt(entry);
- if (candidate->SameValue(*key))
+ if (candidate->SameValueZero(*key))
return entry;
}
return kNotFound;
// to implement the Harmony "egal" function.
bool SameValue(Object* other);
+ // Checks whether this object has the same value as the given one.
+ // +0 and -0 are treated equal. Everything else is the same as SameValue.
+ // This function is implemented according to ES6, section 7.2.4 and is used
+ // by ES6 Map and Set.
+ bool SameValueZero(Object* other);
+
// Tries to convert an object to an array index. Returns true and sets
// the output parameter if it succeeds.
inline bool ToArrayIndex(uint32_t* index);
// insertion order. There are Map and Set interfaces (OrderedHashMap
// and OrderedHashTable, below). It is meant to be used by JSMap/JSSet.
//
-// Only Object* keys are supported, with Object::SameValue() used as the
+// Only Object* keys are supported, with Object::SameValueZero() used as the
// equality operator and Object::GetHash() for the hash function.
//
// Based on the "Deterministic Hash Table" as described by Jason Orendorff at