| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "accessors.h" | 7 #include "accessors.h" |
| 8 #include "allocation-site-scopes.h" | 8 #include "allocation-site-scopes.h" |
| 9 #include "api.h" | 9 #include "api.h" |
| 10 #include "arguments.h" | 10 #include "arguments.h" |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 if (IsOddball()) { | 938 if (IsOddball()) { |
| 939 uint32_t hash = Oddball::cast(this)->to_string()->Hash(); | 939 uint32_t hash = Oddball::cast(this)->to_string()->Hash(); |
| 940 return Smi::FromInt(hash); | 940 return Smi::FromInt(hash); |
| 941 } | 941 } |
| 942 | 942 |
| 943 ASSERT(IsJSReceiver()); | 943 ASSERT(IsJSReceiver()); |
| 944 return JSReceiver::cast(this)->GetIdentityHash(); | 944 return JSReceiver::cast(this)->GetIdentityHash(); |
| 945 } | 945 } |
| 946 | 946 |
| 947 | 947 |
| 948 Handle<Object> Object::GetOrCreateHash(Handle<Object> object, | 948 Handle<Smi> Object::GetOrCreateHash(Isolate* isolate, Handle<Object> object) { |
| 949 Isolate* isolate) { | |
| 950 Handle<Object> hash(object->GetHash(), isolate); | 949 Handle<Object> hash(object->GetHash(), isolate); |
| 951 if (hash->IsSmi()) | 950 if (hash->IsSmi()) return Handle<Smi>::cast(hash); |
| 952 return hash; | |
| 953 | 951 |
| 954 ASSERT(object->IsJSReceiver()); | 952 ASSERT(object->IsJSReceiver()); |
| 955 return JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>::cast(object)); | 953 return JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>::cast(object)); |
| 956 } | 954 } |
| 957 | 955 |
| 958 | 956 |
| 959 bool Object::SameValue(Object* other) { | 957 bool Object::SameValue(Object* other) { |
| 960 if (other == this) return true; | 958 if (other == this) return true; |
| 961 | 959 |
| 962 // The object is either a number, a name, an odd-ball, | 960 // The object is either a number, a name, an odd-ball, |
| (...skipping 4126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5089 | 5087 |
| 5090 | 5088 |
| 5091 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { | 5089 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { |
| 5092 ASSERT(!object->IsJSGlobalProxy()); | 5090 ASSERT(!object->IsJSGlobalProxy()); |
| 5093 Isolate* isolate = object->GetIsolate(); | 5091 Isolate* isolate = object->GetIsolate(); |
| 5094 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); | 5092 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); |
| 5095 } | 5093 } |
| 5096 | 5094 |
| 5097 | 5095 |
| 5098 template<typename ProxyType> | 5096 template<typename ProxyType> |
| 5099 static Handle<Object> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { | 5097 static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { |
| 5100 Isolate* isolate = proxy->GetIsolate(); | 5098 Isolate* isolate = proxy->GetIsolate(); |
| 5101 | 5099 |
| 5102 Handle<Object> hash(proxy->hash(), isolate); | 5100 Handle<Object> maybe_hash(proxy->hash(), isolate); |
| 5103 if (hash->IsSmi()) return hash; | 5101 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5104 | 5102 |
| 5105 hash = handle(GenerateIdentityHash(isolate), isolate); | 5103 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5106 proxy->set_hash(*hash); | 5104 proxy->set_hash(*hash); |
| 5107 return hash; | 5105 return hash; |
| 5108 } | 5106 } |
| 5109 | 5107 |
| 5110 | 5108 |
| 5111 Object* JSObject::GetIdentityHash() { | 5109 Object* JSObject::GetIdentityHash() { |
| 5112 DisallowHeapAllocation no_gc; | 5110 DisallowHeapAllocation no_gc; |
| 5113 Isolate* isolate = GetIsolate(); | 5111 Isolate* isolate = GetIsolate(); |
| 5114 if (IsJSGlobalProxy()) { | 5112 if (IsJSGlobalProxy()) { |
| 5115 return JSGlobalProxy::cast(this)->hash(); | 5113 return JSGlobalProxy::cast(this)->hash(); |
| 5116 } | 5114 } |
| 5117 Object* stored_value = | 5115 Object* stored_value = |
| 5118 GetHiddenProperty(isolate->factory()->identity_hash_string()); | 5116 GetHiddenProperty(isolate->factory()->identity_hash_string()); |
| 5119 return stored_value->IsSmi() | 5117 return stored_value->IsSmi() |
| 5120 ? stored_value | 5118 ? stored_value |
| 5121 : isolate->heap()->undefined_value(); | 5119 : isolate->heap()->undefined_value(); |
| 5122 } | 5120 } |
| 5123 | 5121 |
| 5124 | 5122 |
| 5125 Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { | 5123 Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { |
| 5126 if (object->IsJSGlobalProxy()) { | 5124 if (object->IsJSGlobalProxy()) { |
| 5127 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); | 5125 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); |
| 5128 } | 5126 } |
| 5129 | 5127 |
| 5130 Isolate* isolate = object->GetIsolate(); | 5128 Isolate* isolate = object->GetIsolate(); |
| 5131 | 5129 |
| 5132 Handle<Object> hash(object->GetIdentityHash(), isolate); | 5130 Handle<Object> maybe_hash(object->GetIdentityHash(), isolate); |
| 5133 if (hash->IsSmi()) return hash; | 5131 if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); |
| 5134 | 5132 |
| 5135 hash = handle(GenerateIdentityHash(isolate), isolate); | 5133 Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); |
| 5136 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); | 5134 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); |
| 5137 return hash; | 5135 return hash; |
| 5138 } | 5136 } |
| 5139 | 5137 |
| 5140 | 5138 |
| 5141 Object* JSProxy::GetIdentityHash() { | 5139 Object* JSProxy::GetIdentityHash() { |
| 5142 return this->hash(); | 5140 return this->hash(); |
| 5143 } | 5141 } |
| 5144 | 5142 |
| 5145 | 5143 |
| 5146 Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { | 5144 Handle<Smi> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { |
| 5147 return GetOrCreateIdentityHashHelper(proxy); | 5145 return GetOrCreateIdentityHashHelper(proxy); |
| 5148 } | 5146 } |
| 5149 | 5147 |
| 5150 | 5148 |
| 5151 Object* JSObject::GetHiddenProperty(Handle<Name> key) { | 5149 Object* JSObject::GetHiddenProperty(Handle<Name> key) { |
| 5152 DisallowHeapAllocation no_gc; | 5150 DisallowHeapAllocation no_gc; |
| 5153 ASSERT(key->IsUniqueName()); | 5151 ASSERT(key->IsUniqueName()); |
| 5154 if (IsJSGlobalProxy()) { | 5152 if (IsJSGlobalProxy()) { |
| 5155 // JSGlobalProxies store their hash internally. | 5153 // JSGlobalProxies store their hash internally. |
| 5156 ASSERT(*key != GetHeap()->identity_hash_string()); | 5154 ASSERT(*key != GetHeap()->identity_hash_string()); |
| (...skipping 10945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16102 | 16100 |
| 16103 | 16101 |
| 16104 Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table, | 16102 Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table, |
| 16105 Handle<Object> key, | 16103 Handle<Object> key, |
| 16106 Handle<Object> value) { | 16104 Handle<Object> value) { |
| 16107 ASSERT(table->IsKey(*key)); | 16105 ASSERT(table->IsKey(*key)); |
| 16108 | 16106 |
| 16109 Isolate* isolate = table->GetIsolate(); | 16107 Isolate* isolate = table->GetIsolate(); |
| 16110 | 16108 |
| 16111 // Make sure the key object has an identity hash code. | 16109 // Make sure the key object has an identity hash code. |
| 16112 Handle<Object> hash = Object::GetOrCreateHash(key, isolate); | 16110 Handle<Smi> hash = Object::GetOrCreateHash(isolate, key); |
| 16113 | 16111 |
| 16114 int entry = table->FindEntry(key); | 16112 int entry = table->FindEntry(key); |
| 16115 | 16113 |
| 16116 // Check whether to perform removal operation. | 16114 // Check whether to perform removal operation. |
| 16117 if (value->IsTheHole()) { | 16115 if (value->IsTheHole()) { |
| 16118 if (entry == kNotFound) return table; | 16116 if (entry == kNotFound) return table; |
| 16119 table->RemoveEntry(entry); | 16117 table->RemoveEntry(entry); |
| 16120 return Shrink(table, key); | 16118 return Shrink(table, key); |
| 16121 } | 16119 } |
| 16122 | 16120 |
| 16123 // Key is already in table, just overwrite value. | 16121 // Key is already in table, just overwrite value. |
| 16124 if (entry != kNotFound) { | 16122 if (entry != kNotFound) { |
| 16125 table->set(EntryToIndex(entry) + 1, *value); | 16123 table->set(EntryToIndex(entry) + 1, *value); |
| 16126 return table; | 16124 return table; |
| 16127 } | 16125 } |
| 16128 | 16126 |
| 16129 // Check whether the hash table should be extended. | 16127 // Check whether the hash table should be extended. |
| 16130 table = EnsureCapacity(table, 1, key); | 16128 table = EnsureCapacity(table, 1, key); |
| 16131 table->AddEntry(table->FindInsertionEntry(Handle<Smi>::cast(hash)->value()), | 16129 table->AddEntry(table->FindInsertionEntry(hash->value()), |
| 16132 *key, | 16130 *key, |
| 16133 *value); | 16131 *value); |
| 16134 return table; | 16132 return table; |
| 16135 } | 16133 } |
| 16136 | 16134 |
| 16137 | 16135 |
| 16138 void ObjectHashTable::AddEntry(int entry, Object* key, Object* value) { | 16136 void ObjectHashTable::AddEntry(int entry, Object* key, Object* value) { |
| 16139 set(EntryToIndex(entry), key); | 16137 set(EntryToIndex(entry), key); |
| 16140 set(EntryToIndex(entry) + 1, value); | 16138 set(EntryToIndex(entry) + 1, value); |
| 16141 ElementAdded(); | 16139 ElementAdded(); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16414 return FindEntry(key) != kNotFound; | 16412 return FindEntry(key) != kNotFound; |
| 16415 } | 16413 } |
| 16416 | 16414 |
| 16417 | 16415 |
| 16418 Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table, | 16416 Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table, |
| 16419 Handle<Object> key) { | 16417 Handle<Object> key) { |
| 16420 if (table->FindEntry(key) != kNotFound) return table; | 16418 if (table->FindEntry(key) != kNotFound) return table; |
| 16421 | 16419 |
| 16422 table = EnsureGrowable(table); | 16420 table = EnsureGrowable(table); |
| 16423 | 16421 |
| 16424 Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate()); | 16422 Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key); |
| 16425 int index = table->AddEntry(Smi::cast(*hash)->value()); | 16423 int index = table->AddEntry(hash->value()); |
| 16426 table->set(index, *key); | 16424 table->set(index, *key); |
| 16427 return table; | 16425 return table; |
| 16428 } | 16426 } |
| 16429 | 16427 |
| 16430 | 16428 |
| 16431 Handle<OrderedHashSet> OrderedHashSet::Remove(Handle<OrderedHashSet> table, | 16429 Handle<OrderedHashSet> OrderedHashSet::Remove(Handle<OrderedHashSet> table, |
| 16432 Handle<Object> key) { | 16430 Handle<Object> key) { |
| 16433 int entry = table->FindEntry(key); | 16431 int entry = table->FindEntry(key); |
| 16434 if (entry == kNotFound) return table; | 16432 if (entry == kNotFound) return table; |
| 16435 table->RemoveEntry(entry); | 16433 table->RemoveEntry(entry); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 16456 return Shrink(table); | 16454 return Shrink(table); |
| 16457 } | 16455 } |
| 16458 | 16456 |
| 16459 if (entry != kNotFound) { | 16457 if (entry != kNotFound) { |
| 16460 table->set(table->EntryToIndex(entry) + kValueOffset, *value); | 16458 table->set(table->EntryToIndex(entry) + kValueOffset, *value); |
| 16461 return table; | 16459 return table; |
| 16462 } | 16460 } |
| 16463 | 16461 |
| 16464 table = EnsureGrowable(table); | 16462 table = EnsureGrowable(table); |
| 16465 | 16463 |
| 16466 Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate()); | 16464 Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key); |
| 16467 int index = table->AddEntry(Smi::cast(*hash)->value()); | 16465 int index = table->AddEntry(hash->value()); |
| 16468 table->set(index, *key); | 16466 table->set(index, *key); |
| 16469 table->set(index + kValueOffset, *value); | 16467 table->set(index + kValueOffset, *value); |
| 16470 return table; | 16468 return table; |
| 16471 } | 16469 } |
| 16472 | 16470 |
| 16473 | 16471 |
| 16474 template<class Derived, class TableType> | 16472 template<class Derived, class TableType> |
| 16475 void OrderedHashTableIterator<Derived, TableType>::EntryRemoved(int index) { | 16473 void OrderedHashTableIterator<Derived, TableType>::EntryRemoved(int index) { |
| 16476 int i = this->index()->value(); | 16474 int i = this->index()->value(); |
| 16477 if (index < i) { | 16475 if (index < i) { |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17271 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17269 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 17272 static const char* error_messages_[] = { | 17270 static const char* error_messages_[] = { |
| 17273 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17271 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 17274 }; | 17272 }; |
| 17275 #undef ERROR_MESSAGES_TEXTS | 17273 #undef ERROR_MESSAGES_TEXTS |
| 17276 return error_messages_[reason]; | 17274 return error_messages_[reason]; |
| 17277 } | 17275 } |
| 17278 | 17276 |
| 17279 | 17277 |
| 17280 } } // namespace v8::internal | 17278 } } // namespace v8::internal |
| OLD | NEW |