OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 "Writing internal field out of bounds")) { | 2571 "Writing internal field out of bounds")) { |
2572 return; | 2572 return; |
2573 } | 2573 } |
2574 ENTER_V8; | 2574 ENTER_V8; |
2575 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 2575 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
2576 obj->SetInternalField(index, *val); | 2576 obj->SetInternalField(index, *val); |
2577 } | 2577 } |
2578 | 2578 |
2579 | 2579 |
2580 void v8::Object::SetPointerInInternalField(int index, void* value) { | 2580 void v8::Object::SetPointerInInternalField(int index, void* value) { |
2581 SetInternalField(index, External::Wrap(value)); | 2581 i::Object* as_object = reinterpret_cast<i::Object*>(value); |
| 2582 if (as_object->IsSmi()) { |
| 2583 Utils::OpenHandle(this)->SetInternalField(index, as_object); |
| 2584 return; |
| 2585 } |
| 2586 HandleScope scope; |
| 2587 i::Handle<i::Proxy> proxy = |
| 2588 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); |
| 2589 if (!proxy.is_null()) |
| 2590 Utils::OpenHandle(this)->SetInternalField(index, *proxy); |
2582 } | 2591 } |
2583 | 2592 |
2584 | 2593 |
2585 // --- E n v i r o n m e n t --- | 2594 // --- E n v i r o n m e n t --- |
2586 | 2595 |
2587 bool v8::V8::Initialize() { | 2596 bool v8::V8::Initialize() { |
2588 if (i::V8::IsRunning()) return true; | 2597 if (i::V8::IsRunning()) return true; |
2589 ENTER_V8; | 2598 ENTER_V8; |
2590 HandleScope scope; | 2599 HandleScope scope; |
2591 if (i::Snapshot::Initialize()) { | 2600 if (i::Snapshot::Initialize()) { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2832 | 2841 |
2833 static Local<External> ExternalNewImpl(void* data) { | 2842 static Local<External> ExternalNewImpl(void* data) { |
2834 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data))); | 2843 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data))); |
2835 } | 2844 } |
2836 | 2845 |
2837 static void* ExternalValueImpl(i::Handle<i::Object> obj) { | 2846 static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
2838 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); | 2847 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); |
2839 } | 2848 } |
2840 | 2849 |
2841 | 2850 |
2842 static const intptr_t kAlignedPointerMask = 3; | |
2843 | |
2844 Local<Value> v8::External::Wrap(void* data) { | 2851 Local<Value> v8::External::Wrap(void* data) { |
2845 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); | 2852 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
2846 LOG_API("External::Wrap"); | 2853 LOG_API("External::Wrap"); |
2847 EnsureInitialized("v8::External::Wrap()"); | 2854 EnsureInitialized("v8::External::Wrap()"); |
2848 ENTER_V8; | 2855 ENTER_V8; |
2849 if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) { | 2856 i::Object* as_object = reinterpret_cast<i::Object*>(data); |
2850 uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data); | 2857 if (as_object->IsSmi()) { |
2851 intptr_t data_value = | 2858 return Utils::ToLocal(i::Handle<i::Object>(as_object)); |
2852 static_cast<intptr_t>(data_ptr >> i::Internals::kAlignedPointerShift); | |
2853 STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value)); | |
2854 if (i::Smi::IsValid(data_value)) { | |
2855 i::Handle<i::Object> obj(i::Smi::FromIntptr(data_value)); | |
2856 return Utils::ToLocal(obj); | |
2857 } | |
2858 } | 2859 } |
2859 return ExternalNewImpl(data); | 2860 return ExternalNewImpl(data); |
2860 } | 2861 } |
2861 | 2862 |
2862 | 2863 |
| 2864 void* v8::Object::SlowGetPointerFromInternalField(int index) { |
| 2865 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 2866 i::Object* value = obj->GetInternalField(index); |
| 2867 if (value->IsSmi()) { |
| 2868 return value; |
| 2869 } else if (value->IsProxy()) { |
| 2870 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); |
| 2871 } else { |
| 2872 return NULL; |
| 2873 } |
| 2874 } |
| 2875 |
| 2876 |
2863 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { | 2877 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
2864 if (IsDeadCheck("v8::External::Unwrap()")) return 0; | 2878 if (IsDeadCheck("v8::External::Unwrap()")) return 0; |
2865 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); | 2879 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
2866 void* result; | 2880 void* result; |
2867 if (obj->IsSmi()) { | 2881 if (obj->IsSmi()) { |
2868 // The external value was an aligned pointer. | 2882 // The external value was an aligned pointer. |
2869 uintptr_t value = static_cast<uintptr_t>( | 2883 result = *obj; |
2870 i::Smi::cast(*obj)->value()) << i::Internals::kAlignedPointerShift; | |
2871 result = reinterpret_cast<void*>(value); | |
2872 } else if (obj->IsProxy()) { | 2884 } else if (obj->IsProxy()) { |
2873 result = ExternalValueImpl(obj); | 2885 result = ExternalValueImpl(obj); |
2874 } else { | 2886 } else { |
2875 result = NULL; | 2887 result = NULL; |
2876 } | 2888 } |
2877 ASSERT_EQ(result, QuickUnwrap(wrapper)); | 2889 ASSERT_EQ(result, QuickUnwrap(wrapper)); |
2878 return result; | 2890 return result; |
2879 } | 2891 } |
2880 | 2892 |
2881 | 2893 |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3768 | 3780 |
3769 | 3781 |
3770 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 3782 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
3771 HandleScopeImplementer* thread_local = | 3783 HandleScopeImplementer* thread_local = |
3772 reinterpret_cast<HandleScopeImplementer*>(storage); | 3784 reinterpret_cast<HandleScopeImplementer*>(storage); |
3773 thread_local->IterateThis(v); | 3785 thread_local->IterateThis(v); |
3774 return storage + ArchiveSpacePerThread(); | 3786 return storage + ArchiveSpacePerThread(); |
3775 } | 3787 } |
3776 | 3788 |
3777 } } // namespace v8::internal | 3789 } } // namespace v8::internal |
OLD | NEW |