OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 4947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4958 object->Print(); | 4958 object->Print(); |
4959 } | 4959 } |
4960 #endif | 4960 #endif |
4961 | 4961 |
4962 ASSERT(object->HasDictionaryElements() || | 4962 ASSERT(object->HasDictionaryElements() || |
4963 object->HasDictionaryArgumentsElements()); | 4963 object->HasDictionaryArgumentsElements()); |
4964 return dictionary; | 4964 return dictionary; |
4965 } | 4965 } |
4966 | 4966 |
4967 | 4967 |
4968 Smi* JSReceiver::GenerateIdentityHash() { | 4968 static Smi* GenerateIdentityHash(Isolate* isolate) { |
4969 Isolate* isolate = GetIsolate(); | |
4970 | |
4971 int hash_value; | 4969 int hash_value; |
4972 int attempts = 0; | 4970 int attempts = 0; |
4973 do { | 4971 do { |
4974 // Generate a random 32-bit hash value but limit range to fit | 4972 // Generate a random 32-bit hash value but limit range to fit |
4975 // within a smi. | 4973 // within a smi. |
4976 hash_value = isolate->random_number_generator()->NextInt() & Smi::kMaxValue; | 4974 hash_value = isolate->random_number_generator()->NextInt() & Smi::kMaxValue; |
4977 attempts++; | 4975 attempts++; |
4978 } while (hash_value == 0 && attempts < 30); | 4976 } while (hash_value == 0 && attempts < 30); |
4979 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 | 4977 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 |
4980 | 4978 |
4981 return Smi::FromInt(hash_value); | 4979 return Smi::FromInt(hash_value); |
4982 } | 4980 } |
4983 | 4981 |
4984 | 4982 |
4985 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { | 4983 void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { |
4984 ASSERT(!object->IsJSGlobalProxy()); | |
4986 Isolate* isolate = object->GetIsolate(); | 4985 Isolate* isolate = object->GetIsolate(); |
4987 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); | 4986 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); |
4988 } | 4987 } |
4989 | 4988 |
4990 | 4989 |
4990 template<typename ProxyType> | |
4991 static Handle<Object> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { | |
4992 Isolate* isolate = proxy->GetIsolate(); | |
4993 | |
4994 Handle<Object> hash(proxy->hash(), isolate); | |
4995 if (hash->IsSmi()) | |
Toon Verwaest
2014/04/28 14:32:50
Either put on single line or use { }
adamk
2014/04/28 18:44:50
Done. This was pre-existing code, fwiw.
| |
4996 return hash; | |
4997 | |
4998 hash = handle(GenerateIdentityHash(isolate), isolate); | |
4999 proxy->set_hash(*hash); | |
5000 return hash; | |
5001 } | |
5002 | |
5003 | |
4991 Object* JSObject::GetIdentityHash() { | 5004 Object* JSObject::GetIdentityHash() { |
5005 if (IsJSGlobalProxy()) { | |
5006 return JSGlobalProxy::cast(this)->hash(); | |
5007 } | |
4992 Object* stored_value = GetHiddenProperty(GetHeap()->identity_hash_string()); | 5008 Object* stored_value = GetHiddenProperty(GetHeap()->identity_hash_string()); |
4993 return stored_value->IsSmi() ? stored_value : GetHeap()->undefined_value(); | 5009 return stored_value->IsSmi() ? stored_value : GetHeap()->undefined_value(); |
4994 } | 5010 } |
4995 | 5011 |
4996 | 5012 |
4997 Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { | 5013 Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { |
4998 Handle<Object> hash(object->GetIdentityHash(), object->GetIsolate()); | 5014 if (object->IsJSGlobalProxy()) { |
5015 return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); | |
5016 } | |
5017 | |
5018 Isolate* isolate = object->GetIsolate(); | |
5019 | |
5020 Handle<Object> hash(object->GetIdentityHash(), isolate); | |
4999 if (hash->IsSmi()) | 5021 if (hash->IsSmi()) |
Toon Verwaest
2014/04/28 14:32:50
Same as above
adamk
2014/04/28 18:44:50
Done.
| |
5000 return hash; | 5022 return hash; |
5001 | 5023 |
5002 Isolate* isolate = object->GetIsolate(); | 5024 hash = handle(GenerateIdentityHash(isolate), isolate); |
5003 | 5025 SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash); |
5004 hash = handle(object->GenerateIdentityHash(), isolate); | |
5005 Handle<Object> result = SetHiddenProperty(object, | |
5006 isolate->factory()->identity_hash_string(), hash); | |
5007 | |
5008 if (result->IsUndefined()) { | |
5009 // Trying to get hash of detached proxy. | |
5010 return handle(Smi::FromInt(0), isolate); | |
5011 } | |
5012 | |
5013 return hash; | 5026 return hash; |
5014 } | 5027 } |
5015 | 5028 |
5016 | 5029 |
5017 Object* JSProxy::GetIdentityHash() { | 5030 Object* JSProxy::GetIdentityHash() { |
5018 return this->hash(); | 5031 return this->hash(); |
5019 } | 5032 } |
5020 | 5033 |
5021 | 5034 |
5022 Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { | 5035 Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) { |
5023 Isolate* isolate = proxy->GetIsolate(); | 5036 return GetOrCreateIdentityHashHelper(proxy); |
5024 | |
5025 Handle<Object> hash(proxy->GetIdentityHash(), isolate); | |
5026 if (hash->IsSmi()) | |
5027 return hash; | |
5028 | |
5029 hash = handle(proxy->GenerateIdentityHash(), isolate); | |
5030 proxy->set_hash(*hash); | |
5031 return hash; | |
5032 } | 5037 } |
5033 | 5038 |
5034 | 5039 |
5035 Object* JSObject::GetHiddenProperty(Name* key) { | 5040 Object* JSObject::GetHiddenProperty(Name* key) { |
5036 ASSERT(key->IsUniqueName()); | 5041 ASSERT(key->IsUniqueName()); |
5037 if (IsJSGlobalProxy()) { | 5042 if (IsJSGlobalProxy()) { |
5043 // JSGlobalProxies store their hash internally. | |
5044 ASSERT(key != GetHeap()->identity_hash_string()); | |
5038 // For a proxy, use the prototype as target object. | 5045 // For a proxy, use the prototype as target object. |
5039 Object* proxy_parent = GetPrototype(); | 5046 Object* proxy_parent = GetPrototype(); |
5040 // If the proxy is detached, return undefined. | 5047 // If the proxy is detached, return undefined. |
5041 if (proxy_parent->IsNull()) return GetHeap()->the_hole_value(); | 5048 if (proxy_parent->IsNull()) return GetHeap()->the_hole_value(); |
5042 ASSERT(proxy_parent->IsJSGlobalObject()); | 5049 ASSERT(proxy_parent->IsJSGlobalObject()); |
5043 return JSObject::cast(proxy_parent)->GetHiddenProperty(key); | 5050 return JSObject::cast(proxy_parent)->GetHiddenProperty(key); |
5044 } | 5051 } |
5045 ASSERT(!IsJSGlobalProxy()); | 5052 ASSERT(!IsJSGlobalProxy()); |
5046 Object* inline_value = GetHiddenPropertiesHashTable(); | 5053 Object* inline_value = GetHiddenPropertiesHashTable(); |
5047 | 5054 |
(...skipping 14 matching lines...) Expand all Loading... | |
5062 } | 5069 } |
5063 | 5070 |
5064 | 5071 |
5065 Handle<Object> JSObject::SetHiddenProperty(Handle<JSObject> object, | 5072 Handle<Object> JSObject::SetHiddenProperty(Handle<JSObject> object, |
5066 Handle<Name> key, | 5073 Handle<Name> key, |
5067 Handle<Object> value) { | 5074 Handle<Object> value) { |
5068 Isolate* isolate = object->GetIsolate(); | 5075 Isolate* isolate = object->GetIsolate(); |
5069 | 5076 |
5070 ASSERT(key->IsUniqueName()); | 5077 ASSERT(key->IsUniqueName()); |
5071 if (object->IsJSGlobalProxy()) { | 5078 if (object->IsJSGlobalProxy()) { |
5079 // JSGlobalProxies store their hash internally. | |
5080 ASSERT(*key != *isolate->factory()->identity_hash_string()); | |
5072 // For a proxy, use the prototype as target object. | 5081 // For a proxy, use the prototype as target object. |
5073 Handle<Object> proxy_parent(object->GetPrototype(), isolate); | 5082 Handle<Object> proxy_parent(object->GetPrototype(), isolate); |
5074 // If the proxy is detached, return undefined. | 5083 // If the proxy is detached, return undefined. |
5075 if (proxy_parent->IsNull()) return isolate->factory()->undefined_value(); | 5084 if (proxy_parent->IsNull()) return isolate->factory()->undefined_value(); |
5076 ASSERT(proxy_parent->IsJSGlobalObject()); | 5085 ASSERT(proxy_parent->IsJSGlobalObject()); |
5077 return SetHiddenProperty(Handle<JSObject>::cast(proxy_parent), key, value); | 5086 return SetHiddenProperty(Handle<JSObject>::cast(proxy_parent), key, value); |
5078 } | 5087 } |
5079 ASSERT(!object->IsJSGlobalProxy()); | 5088 ASSERT(!object->IsJSGlobalProxy()); |
5080 | 5089 |
5081 Handle<Object> inline_value(object->GetHiddenPropertiesHashTable(), isolate); | 5090 Handle<Object> inline_value(object->GetHiddenPropertiesHashTable(), isolate); |
(...skipping 12350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17432 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17441 #define ERROR_MESSAGES_TEXTS(C, T) T, |
17433 static const char* error_messages_[] = { | 17442 static const char* error_messages_[] = { |
17434 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17443 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
17435 }; | 17444 }; |
17436 #undef ERROR_MESSAGES_TEXTS | 17445 #undef ERROR_MESSAGES_TEXTS |
17437 return error_messages_[reason]; | 17446 return error_messages_[reason]; |
17438 } | 17447 } |
17439 | 17448 |
17440 | 17449 |
17441 } } // namespace v8::internal | 17450 } } // namespace v8::internal |
OLD | NEW |