diff options
author | fqian@google.com <fqian@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 04:23:06 +0000 |
---|---|---|
committer | fqian@google.com <fqian@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 04:23:06 +0000 |
commit | e0291ec704fd21a4e99e99c60766c768f58ebcb3 (patch) | |
tree | 47c865fd13e418fa30cb9e9cfa482639fb320c12 /webkit | |
parent | eeb77d682957b5a5eb23366d916d51f04cb132d8 (diff) | |
download | chromium_src-e0291ec704fd21a4e99e99c60766c768f58ebcb3.zip chromium_src-e0291ec704fd21a4e99e99c60766c768f58ebcb3.tar.gz chromium_src-e0291ec704fd21a4e99e99c60766c768f58ebcb3.tar.bz2 |
Fix issue 11264
http://code.google.com/p/chromium/issues/detail?id=11264
Integer 0 and -1 have special meaning in HashMap<int, ...>, both cannot be used as key.
Specially filter out these two keys.
Review URL: http://codereview.chromium.org/100242
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/port/bindings/v8/npruntime.cpp | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/webkit/port/bindings/v8/npruntime.cpp b/webkit/port/bindings/v8/npruntime.cpp index 427ea0c..bfcd8ea 100644 --- a/webkit/port/bindings/v8/npruntime.cpp +++ b/webkit/port/bindings/v8/npruntime.cpp @@ -48,23 +48,24 @@ namespace { // construct the map key and for faster comparisons than strcmp. class StringKey { public: - explicit StringKey(const char* str) : _string(str), _length(strlen(str)) {} - StringKey() : _string(0), _length(0) {} + explicit StringKey(const char* str) + : m_string(str), m_length(strlen(str)) {} + StringKey() : m_string(0), m_length(0) {} explicit StringKey(WTF::HashTableDeletedValueType) - : _string(hashTableDeletedValue()), _length(0) { } + : m_string(hashTableDeletedValue()), m_length(0) { } StringKey& operator=(const StringKey& other) { - this->_string = other._string; - this->_length = other._length; + this->m_string = other.m_string; + this->m_length = other.m_length; return *this; } bool isHashTableDeletedValue() const { - return _string == hashTableDeletedValue(); + return m_string == hashTableDeletedValue(); } - const char* _string; - size_t _length; + const char* m_string; + size_t m_length; private: const char* hashTableDeletedValue() const { return reinterpret_cast<const char*>(-1); @@ -72,23 +73,23 @@ class StringKey { }; inline bool operator==(const StringKey& x, const StringKey& y) { - if (x._length != y._length) { + if (x.m_length != y.m_length) { return false; - } else if (x._string == y._string) { + } else if (x.m_string == y.m_string) { return true; } else { ASSERT(!x.isHashTableDeletedValue() && !y.isHashTableDeletedValue()); - return memcmp(x._string, y._string, y._length) == 0; + return memcmp(x.m_string, y.m_string, y.m_length) == 0; } } // Implement WTF::DefaultHash<StringKey>::Hash interface. struct StringKeyHash { static unsigned hash(const StringKey& key) { - // Use the same string hash function as in V8. + // Compute string hash. unsigned hash = 0; - size_t len = key._length; - const char* str = key._string; + size_t len = key.m_length; + const char* str = key.m_string; for (size_t i = 0; i < len; i++) { char c = str[i]; hash += c; @@ -159,7 +160,7 @@ NPIdentifier NPN_GetStringIdentifier(const NPUTF8* name) { if (iter != identMap->end()) return static_cast<NPIdentifier>(iter->second); - size_t nameLen = key._length; + size_t nameLen = key.m_length; // We never release identifiers, so this dictionary will grow. PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>( @@ -168,7 +169,7 @@ NPIdentifier NPN_GetStringIdentifier(const NPUTF8* name) { memcpy(nameStorage, name, nameLen + 1); identifier->isString = true; identifier->value.string = reinterpret_cast<NPUTF8*>(nameStorage); - key._string = nameStorage; + key.m_string = nameStorage; identMap->set(key, identifier); return (NPIdentifier)identifier; } @@ -188,6 +189,19 @@ void NPN_GetStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdentifier NPN_GetIntIdentifier(int32_t intid) { // AutoLock safeLock(IntIdentifierMapLock); + // Special case for -1 and 0, both cannot be used as key in HashMap. + if (intid == 0 || intid == -1) { + static PrivateIdentifier* minusOneOrZeroIds[2]; + PrivateIdentifier* id = minusOneOrZeroIds[intid + 1]; + if (!id) { + id = reinterpret_cast<PrivateIdentifier*>( + malloc(sizeof(PrivateIdentifier))); + id->isString = false; + id->value.number = intid; + minusOneOrZeroIds[intid + 1] = id; + } + return (NPIdentifier)id; + } IntIdentifierMap* identMap = getIntIdentifierMap(); IntIdentifierMap::iterator iter = identMap->find(intid); |