| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 3248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3259 "v8::Object::SetInternalField()", | 3259 "v8::Object::SetInternalField()", |
| 3260 "Writing internal field out of bounds")) { | 3260 "Writing internal field out of bounds")) { |
| 3261 return; | 3261 return; |
| 3262 } | 3262 } |
| 3263 ENTER_V8; | 3263 ENTER_V8; |
| 3264 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 3264 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 3265 obj->SetInternalField(index, *val); | 3265 obj->SetInternalField(index, *val); |
| 3266 } | 3266 } |
| 3267 | 3267 |
| 3268 | 3268 |
| 3269 static bool CanBeEncodedAsSmi(void* ptr) { |
| 3270 const intptr_t address = reinterpret_cast<intptr_t>(ptr); |
| 3271 return ((address & i::kEncodablePointerMask) == 0); |
| 3272 } |
| 3273 |
| 3274 |
| 3275 static i::Smi* EncodeAsSmi(void* ptr) { |
| 3276 ASSERT(CanBeEncodedAsSmi(ptr)); |
| 3277 const intptr_t address = reinterpret_cast<intptr_t>(ptr); |
| 3278 i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift); |
| 3279 ASSERT(i::Internals::HasSmiTag(result)); |
| 3280 ASSERT_EQ(result, i::Smi::FromInt(result->value())); |
| 3281 ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result)); |
| 3282 return result; |
| 3283 } |
| 3284 |
| 3285 |
| 3269 void v8::Object::SetPointerInInternalField(int index, void* value) { | 3286 void v8::Object::SetPointerInInternalField(int index, void* value) { |
| 3270 ENTER_V8; | 3287 ENTER_V8; |
| 3271 i::Object* as_object = reinterpret_cast<i::Object*>(value); | 3288 if (CanBeEncodedAsSmi(value)) { |
| 3272 if (as_object->IsSmi()) { | 3289 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); |
| 3273 Utils::OpenHandle(this)->SetInternalField(index, as_object); | 3290 } else { |
| 3274 return; | 3291 HandleScope scope; |
| 3292 i::Handle<i::Proxy> proxy = |
| 3293 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); |
| 3294 if (!proxy.is_null()) |
| 3295 Utils::OpenHandle(this)->SetInternalField(index, *proxy); |
| 3275 } | 3296 } |
| 3276 HandleScope scope; | 3297 ASSERT_EQ(value, GetPointerFromInternalField(index)); |
| 3277 i::Handle<i::Proxy> proxy = | |
| 3278 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); | |
| 3279 if (!proxy.is_null()) | |
| 3280 Utils::OpenHandle(this)->SetInternalField(index, *proxy); | |
| 3281 } | 3298 } |
| 3282 | 3299 |
| 3283 | 3300 |
| 3284 // --- E n v i r o n m e n t --- | 3301 // --- E n v i r o n m e n t --- |
| 3285 | 3302 |
| 3286 bool v8::V8::Initialize() { | 3303 bool v8::V8::Initialize() { |
| 3287 if (i::V8::IsRunning()) return true; | 3304 if (i::V8::IsRunning()) return true; |
| 3288 HandleScope scope; | 3305 HandleScope scope; |
| 3289 if (i::Snapshot::Initialize()) return true; | 3306 if (i::Snapshot::Initialize()) return true; |
| 3290 return i::V8::Initialize(NULL); | 3307 return i::V8::Initialize(NULL); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3555 static void* ExternalValueImpl(i::Handle<i::Object> obj) { | 3572 static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
| 3556 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); | 3573 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); |
| 3557 } | 3574 } |
| 3558 | 3575 |
| 3559 | 3576 |
| 3560 Local<Value> v8::External::Wrap(void* data) { | 3577 Local<Value> v8::External::Wrap(void* data) { |
| 3561 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); | 3578 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
| 3562 LOG_API("External::Wrap"); | 3579 LOG_API("External::Wrap"); |
| 3563 EnsureInitialized("v8::External::Wrap()"); | 3580 EnsureInitialized("v8::External::Wrap()"); |
| 3564 ENTER_V8; | 3581 ENTER_V8; |
| 3565 i::Object* as_object = reinterpret_cast<i::Object*>(data); | 3582 |
| 3566 if (as_object->IsSmi()) { | 3583 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) |
| 3567 return Utils::ToLocal(i::Handle<i::Object>(as_object)); | 3584 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) |
| 3568 } | 3585 : v8::Local<v8::Value>(ExternalNewImpl(data)); |
| 3569 return ExternalNewImpl(data); | 3586 |
| 3587 ASSERT_EQ(data, Unwrap(result)); |
| 3588 return result; |
| 3570 } | 3589 } |
| 3571 | 3590 |
| 3572 | 3591 |
| 3573 void* v8::Object::SlowGetPointerFromInternalField(int index) { | 3592 void* v8::Object::SlowGetPointerFromInternalField(int index) { |
| 3574 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | 3593 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3575 i::Object* value = obj->GetInternalField(index); | 3594 i::Object* value = obj->GetInternalField(index); |
| 3576 if (value->IsSmi()) { | 3595 if (value->IsSmi()) { |
| 3577 return value; | 3596 return i::Internals::GetExternalPointerFromSmi(value); |
| 3578 } else if (value->IsProxy()) { | 3597 } else if (value->IsProxy()) { |
| 3579 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); | 3598 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); |
| 3580 } else { | 3599 } else { |
| 3581 return NULL; | 3600 return NULL; |
| 3582 } | 3601 } |
| 3583 } | 3602 } |
| 3584 | 3603 |
| 3585 | 3604 |
| 3586 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { | 3605 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
| 3587 if (IsDeadCheck("v8::External::Unwrap()")) return 0; | 3606 if (IsDeadCheck("v8::External::Unwrap()")) return 0; |
| 3588 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); | 3607 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
| 3589 void* result; | 3608 void* result; |
| 3590 if (obj->IsSmi()) { | 3609 if (obj->IsSmi()) { |
| 3591 // The external value was an aligned pointer. | 3610 result = i::Internals::GetExternalPointerFromSmi(*obj); |
| 3592 result = *obj; | |
| 3593 } else if (obj->IsProxy()) { | 3611 } else if (obj->IsProxy()) { |
| 3594 result = ExternalValueImpl(obj); | 3612 result = ExternalValueImpl(obj); |
| 3595 } else { | 3613 } else { |
| 3596 result = NULL; | 3614 result = NULL; |
| 3597 } | 3615 } |
| 3598 ASSERT_EQ(result, QuickUnwrap(wrapper)); | 3616 ASSERT_EQ(result, QuickUnwrap(wrapper)); |
| 3599 return result; | 3617 return result; |
| 3600 } | 3618 } |
| 3601 | 3619 |
| 3602 | 3620 |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5138 | 5156 |
| 5139 | 5157 |
| 5140 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5158 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 5141 HandleScopeImplementer* thread_local = | 5159 HandleScopeImplementer* thread_local = |
| 5142 reinterpret_cast<HandleScopeImplementer*>(storage); | 5160 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 5143 thread_local->IterateThis(v); | 5161 thread_local->IterateThis(v); |
| 5144 return storage + ArchiveSpacePerThread(); | 5162 return storage + ArchiveSpacePerThread(); |
| 5145 } | 5163 } |
| 5146 | 5164 |
| 5147 } } // namespace v8::internal | 5165 } } // namespace v8::internal |
| OLD | NEW |