OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3078 return Utils::ToLocal(i::Handle<i::Context>(context)); | 3078 return Utils::ToLocal(i::Handle<i::Context>(context)); |
3079 } | 3079 } |
3080 | 3080 |
3081 | 3081 |
3082 int v8::Object::GetIdentityHash() { | 3082 int v8::Object::GetIdentityHash() { |
3083 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3083 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3084 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); | 3084 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
3085 ENTER_V8(isolate); | 3085 ENTER_V8(isolate); |
3086 i::HandleScope scope(isolate); | 3086 i::HandleScope scope(isolate); |
3087 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3087 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3088 return i::GetIdentityHash(self)->value(); | 3088 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true)); |
| 3089 if (!hidden_props_obj->IsJSObject()) { |
| 3090 // We failed to create hidden properties. That's a detached |
| 3091 // global proxy. |
| 3092 ASSERT(hidden_props_obj->IsUndefined()); |
| 3093 return 0; |
| 3094 } |
| 3095 i::Handle<i::JSObject> hidden_props = |
| 3096 i::Handle<i::JSObject>::cast(hidden_props_obj); |
| 3097 i::Handle<i::String> hash_symbol = isolate->factory()->identity_hash_symbol(); |
| 3098 if (hidden_props->HasLocalProperty(*hash_symbol)) { |
| 3099 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol); |
| 3100 CHECK(!hash.is_null()); |
| 3101 CHECK(hash->IsSmi()); |
| 3102 return i::Smi::cast(*hash)->value(); |
| 3103 } |
| 3104 |
| 3105 int hash_value; |
| 3106 int attempts = 0; |
| 3107 do { |
| 3108 // Generate a random 32-bit hash value but limit range to fit |
| 3109 // within a smi. |
| 3110 hash_value = i::V8::Random(self->GetIsolate()) & i::Smi::kMaxValue; |
| 3111 attempts++; |
| 3112 } while (hash_value == 0 && attempts < 30); |
| 3113 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 |
| 3114 CHECK(!i::SetLocalPropertyIgnoreAttributes( |
| 3115 hidden_props, |
| 3116 hash_symbol, |
| 3117 i::Handle<i::Object>(i::Smi::FromInt(hash_value)), |
| 3118 static_cast<PropertyAttributes>(None)).is_null()); |
| 3119 |
| 3120 return hash_value; |
3089 } | 3121 } |
3090 | 3122 |
3091 | 3123 |
3092 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, | 3124 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
3093 v8::Handle<v8::Value> value) { | 3125 v8::Handle<v8::Value> value) { |
3094 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3126 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3095 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); | 3127 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
3096 ENTER_V8(isolate); | 3128 ENTER_V8(isolate); |
3097 i::HandleScope scope(isolate); | 3129 i::HandleScope scope(isolate); |
3098 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3130 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
(...skipping 2759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5858 | 5890 |
5859 | 5891 |
5860 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5892 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
5861 HandleScopeImplementer* scope_implementer = | 5893 HandleScopeImplementer* scope_implementer = |
5862 reinterpret_cast<HandleScopeImplementer*>(storage); | 5894 reinterpret_cast<HandleScopeImplementer*>(storage); |
5863 scope_implementer->IterateThis(v); | 5895 scope_implementer->IterateThis(v); |
5864 return storage + ArchiveSpacePerThread(); | 5896 return storage + ArchiveSpacePerThread(); |
5865 } | 5897 } |
5866 | 5898 |
5867 } } // namespace v8::internal | 5899 } } // namespace v8::internal |
OLD | NEW |