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 3225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3236 "v8::Object::SetInternalField()", | 3236 "v8::Object::SetInternalField()", |
3237 "Writing internal field out of bounds")) { | 3237 "Writing internal field out of bounds")) { |
3238 return; | 3238 return; |
3239 } | 3239 } |
3240 ENTER_V8; | 3240 ENTER_V8; |
3241 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 3241 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
3242 obj->SetInternalField(index, *val); | 3242 obj->SetInternalField(index, *val); |
3243 } | 3243 } |
3244 | 3244 |
3245 | 3245 |
| 3246 static bool CanBeEncodedAsSmi(void* ptr) { |
| 3247 const intptr_t address = reinterpret_cast<intptr_t>(ptr); |
| 3248 return ((address & i::kEncodablePointerMask) == 0); |
| 3249 } |
| 3250 |
| 3251 |
| 3252 static i::Smi* EncodeAsSmi(void* ptr) { |
| 3253 ASSERT(CanBeEncodedAsSmi(ptr)); |
| 3254 const intptr_t address = reinterpret_cast<intptr_t>(ptr); |
| 3255 i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift); |
| 3256 ASSERT(i::Internals::HasSmiTag(result)); |
| 3257 ASSERT_EQ(result, i::Smi::FromInt(result->value())); |
| 3258 ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result)); |
| 3259 return result; |
| 3260 } |
| 3261 |
| 3262 |
3246 void v8::Object::SetPointerInInternalField(int index, void* value) { | 3263 void v8::Object::SetPointerInInternalField(int index, void* value) { |
3247 ENTER_V8; | 3264 ENTER_V8; |
3248 i::Object* as_object = reinterpret_cast<i::Object*>(value); | 3265 if (CanBeEncodedAsSmi(value)) { |
3249 if (as_object->IsSmi()) { | 3266 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); |
3250 Utils::OpenHandle(this)->SetInternalField(index, as_object); | 3267 } else { |
3251 return; | 3268 HandleScope scope; |
| 3269 i::Handle<i::Proxy> proxy = |
| 3270 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); |
| 3271 if (!proxy.is_null()) |
| 3272 Utils::OpenHandle(this)->SetInternalField(index, *proxy); |
3252 } | 3273 } |
3253 HandleScope scope; | 3274 ASSERT_EQ(value, GetPointerFromInternalField(index)); |
3254 i::Handle<i::Proxy> proxy = | |
3255 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); | |
3256 if (!proxy.is_null()) | |
3257 Utils::OpenHandle(this)->SetInternalField(index, *proxy); | |
3258 } | 3275 } |
3259 | 3276 |
3260 | 3277 |
3261 // --- E n v i r o n m e n t --- | 3278 // --- E n v i r o n m e n t --- |
3262 | 3279 |
3263 bool v8::V8::Initialize() { | 3280 bool v8::V8::Initialize() { |
3264 if (i::V8::IsRunning()) return true; | 3281 if (i::V8::IsRunning()) return true; |
3265 ENTER_V8; | 3282 ENTER_V8; |
3266 HandleScope scope; | 3283 HandleScope scope; |
3267 if (i::Snapshot::Initialize()) return true; | 3284 if (i::Snapshot::Initialize()) return true; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3530 static void* ExternalValueImpl(i::Handle<i::Object> obj) { | 3547 static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
3531 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); | 3548 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); |
3532 } | 3549 } |
3533 | 3550 |
3534 | 3551 |
3535 Local<Value> v8::External::Wrap(void* data) { | 3552 Local<Value> v8::External::Wrap(void* data) { |
3536 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); | 3553 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
3537 LOG_API("External::Wrap"); | 3554 LOG_API("External::Wrap"); |
3538 EnsureInitialized("v8::External::Wrap()"); | 3555 EnsureInitialized("v8::External::Wrap()"); |
3539 ENTER_V8; | 3556 ENTER_V8; |
3540 i::Object* as_object = reinterpret_cast<i::Object*>(data); | 3557 |
3541 if (as_object->IsSmi()) { | 3558 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) |
3542 return Utils::ToLocal(i::Handle<i::Object>(as_object)); | 3559 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) |
3543 } | 3560 : v8::Local<v8::Value>(ExternalNewImpl(data)); |
3544 return ExternalNewImpl(data); | 3561 |
| 3562 ASSERT_EQ(data, Unwrap(result)); |
| 3563 return result; |
3545 } | 3564 } |
3546 | 3565 |
3547 | 3566 |
3548 void* v8::Object::SlowGetPointerFromInternalField(int index) { | 3567 void* v8::Object::SlowGetPointerFromInternalField(int index) { |
3549 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | 3568 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
3550 i::Object* value = obj->GetInternalField(index); | 3569 i::Object* value = obj->GetInternalField(index); |
3551 if (value->IsSmi()) { | 3570 if (value->IsSmi()) { |
3552 return value; | 3571 return i::Internals::GetExternalPointerFromSmi(value); |
3553 } else if (value->IsProxy()) { | 3572 } else if (value->IsProxy()) { |
3554 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); | 3573 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); |
3555 } else { | 3574 } else { |
3556 return NULL; | 3575 return NULL; |
3557 } | 3576 } |
3558 } | 3577 } |
3559 | 3578 |
3560 | 3579 |
3561 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { | 3580 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
3562 if (IsDeadCheck("v8::External::Unwrap()")) return 0; | 3581 if (IsDeadCheck("v8::External::Unwrap()")) return 0; |
3563 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); | 3582 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
3564 void* result; | 3583 void* result; |
3565 if (obj->IsSmi()) { | 3584 if (obj->IsSmi()) { |
3566 // The external value was an aligned pointer. | 3585 result = i::Internals::GetExternalPointerFromSmi(*obj); |
3567 result = *obj; | |
3568 } else if (obj->IsProxy()) { | 3586 } else if (obj->IsProxy()) { |
3569 result = ExternalValueImpl(obj); | 3587 result = ExternalValueImpl(obj); |
3570 } else { | 3588 } else { |
3571 result = NULL; | 3589 result = NULL; |
3572 } | 3590 } |
3573 ASSERT_EQ(result, QuickUnwrap(wrapper)); | 3591 ASSERT_EQ(result, QuickUnwrap(wrapper)); |
3574 return result; | 3592 return result; |
3575 } | 3593 } |
3576 | 3594 |
3577 | 3595 |
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5014 | 5032 |
5015 | 5033 |
5016 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5034 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
5017 HandleScopeImplementer* thread_local = | 5035 HandleScopeImplementer* thread_local = |
5018 reinterpret_cast<HandleScopeImplementer*>(storage); | 5036 reinterpret_cast<HandleScopeImplementer*>(storage); |
5019 thread_local->IterateThis(v); | 5037 thread_local->IterateThis(v); |
5020 return storage + ArchiveSpacePerThread(); | 5038 return storage + ArchiveSpacePerThread(); |
5021 } | 5039 } |
5022 | 5040 |
5023 } } // namespace v8::internal | 5041 } } // namespace v8::internal |
OLD | NEW |