| 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 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3185 return Utils::ToLocal(i::Handle<i::Context>(context)); | 3185 return Utils::ToLocal(i::Handle<i::Context>(context)); |
| 3186 } | 3186 } |
| 3187 | 3187 |
| 3188 | 3188 |
| 3189 int v8::Object::GetIdentityHash() { | 3189 int v8::Object::GetIdentityHash() { |
| 3190 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3190 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3191 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); | 3191 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0); |
| 3192 ENTER_V8(isolate); | 3192 ENTER_V8(isolate); |
| 3193 i::HandleScope scope(isolate); | 3193 i::HandleScope scope(isolate); |
| 3194 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3194 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 3195 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true)); | 3195 return i::GetIdentityHash(self)->value(); |
| 3196 if (!hidden_props_obj->IsJSObject()) { | |
| 3197 // We failed to create hidden properties. That's a detached | |
| 3198 // global proxy. | |
| 3199 ASSERT(hidden_props_obj->IsUndefined()); | |
| 3200 return 0; | |
| 3201 } | |
| 3202 i::Handle<i::JSObject> hidden_props = | |
| 3203 i::Handle<i::JSObject>::cast(hidden_props_obj); | |
| 3204 i::Handle<i::String> hash_symbol = isolate->factory()->identity_hash_symbol(); | |
| 3205 if (hidden_props->HasLocalProperty(*hash_symbol)) { | |
| 3206 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol); | |
| 3207 CHECK(!hash.is_null()); | |
| 3208 CHECK(hash->IsSmi()); | |
| 3209 return i::Smi::cast(*hash)->value(); | |
| 3210 } | |
| 3211 | |
| 3212 int hash_value; | |
| 3213 int attempts = 0; | |
| 3214 do { | |
| 3215 // Generate a random 32-bit hash value but limit range to fit | |
| 3216 // within a smi. | |
| 3217 hash_value = i::V8::Random(self->GetIsolate()) & i::Smi::kMaxValue; | |
| 3218 attempts++; | |
| 3219 } while (hash_value == 0 && attempts < 30); | |
| 3220 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 | |
| 3221 CHECK(!i::SetLocalPropertyIgnoreAttributes( | |
| 3222 hidden_props, | |
| 3223 hash_symbol, | |
| 3224 i::Handle<i::Object>(i::Smi::FromInt(hash_value)), | |
| 3225 static_cast<PropertyAttributes>(None)).is_null()); | |
| 3226 | |
| 3227 return hash_value; | |
| 3228 } | 3196 } |
| 3229 | 3197 |
| 3230 | 3198 |
| 3231 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, | 3199 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 3232 v8::Handle<v8::Value> value) { | 3200 v8::Handle<v8::Value> value) { |
| 3233 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3201 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3234 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); | 3202 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false); |
| 3235 ENTER_V8(isolate); | 3203 ENTER_V8(isolate); |
| 3236 i::HandleScope scope(isolate); | 3204 i::HandleScope scope(isolate); |
| 3237 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3205 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| (...skipping 2825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6063 | 6031 |
| 6064 | 6032 |
| 6065 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 6033 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 6066 HandleScopeImplementer* scope_implementer = | 6034 HandleScopeImplementer* scope_implementer = |
| 6067 reinterpret_cast<HandleScopeImplementer*>(storage); | 6035 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 6068 scope_implementer->IterateThis(v); | 6036 scope_implementer->IterateThis(v); |
| 6069 return storage + ArchiveSpacePerThread(); | 6037 return storage + ArchiveSpacePerThread(); |
| 6070 } | 6038 } |
| 6071 | 6039 |
| 6072 } } // namespace v8::internal | 6040 } } // namespace v8::internal |
| OLD | NEW |