Since V8 is open source, you go to the source:
Here's GetHash (): https://github.com/v8/v8/blob/master/src/objects.cc#L903
And here are some of the hash functions for different types: https://github.com/v8/v8-git-mirror/blob/bda7fb22465fc36d99b4053f0ef60cfaa8441209/src/utils.h#L347
And this is like calculating the basic hashes for strings: https://code.google.com/p/v8/source/browse/trunk/src/objects.cc?spec=svn6&r=6#3574
uint32_t String::ComputeHashCode(unibrow::CharacterStream* buffer, int length) { // Large string (please note large strings cannot be an array index). if (length > kMaxMediumStringSize) return HashField(length, false); // Note: the Jenkins one-at-a-time hash function uint32_t hash = 0; while (buffer->has_more()) { uc32 r = buffer->GetNext(); hash += r; hash += (hash << 10); hash ^= (hash >> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); // Short string. if (length <= kMaxShortStringSize) { // Make hash value consistent with value returned from String::Hash. buffer->Rewind(); uint32_t index; hash = HashField(hash, ComputeArrayIndex(buffer, &index, length)); hash = (hash & 0x00FFFFFF) | (length << kShortLengthShift); return hash; } // Medium string (please note medium strings cannot be an array index). ASSERT(length <= kMaxMediumStringSize); // Make hash value consistent with value returned from String::Hash. hash = HashField(hash, false); hash = (hash & 0x0000FFFF) | (length << kMediumLengthShift); return hash; }
It is probably worth mentioning that V8 approaches a large length in order to avoid using a hash table for object properties when possible, preferring to compile well-known property references into direct index links, rather than looking for time hash requests for performance (although it is only sometimes - it depends on the code).
source share