Index: src/api.cc |
=================================================================== |
--- src/api.cc (revision 3056) |
+++ src/api.cc (working copy) |
@@ -2578,7 +2578,16 @@ |
void v8::Object::SetPointerInInternalField(int index, void* value) { |
- SetInternalField(index, External::Wrap(value)); |
+ i::Object* as_object = reinterpret_cast<i::Object*>(value); |
+ if (as_object->IsSmi()) { |
+ Utils::OpenHandle(this)->SetInternalField(index, as_object); |
+ return; |
+ } |
+ HandleScope scope; |
+ i::Handle<i::Proxy> proxy = |
+ i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); |
+ if (!proxy.is_null()) |
+ Utils::OpenHandle(this)->SetInternalField(index, *proxy); |
} |
@@ -2839,36 +2848,39 @@ |
} |
-static const intptr_t kAlignedPointerMask = 3; |
- |
Local<Value> v8::External::Wrap(void* data) { |
STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
LOG_API("External::Wrap"); |
EnsureInitialized("v8::External::Wrap()"); |
ENTER_V8; |
- if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) { |
- uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data); |
- intptr_t data_value = |
- static_cast<intptr_t>(data_ptr >> i::Internals::kAlignedPointerShift); |
- STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value)); |
- if (i::Smi::IsValid(data_value)) { |
- i::Handle<i::Object> obj(i::Smi::FromIntptr(data_value)); |
- return Utils::ToLocal(obj); |
- } |
+ i::Object* as_object = reinterpret_cast<i::Object*>(data); |
+ if (as_object->IsSmi()) { |
+ return Utils::ToLocal(i::Handle<i::Object>(as_object)); |
} |
return ExternalNewImpl(data); |
} |
+void* v8::Object::SlowGetPointerFromInternalField(int index) { |
+ i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
+ i::Object* value = obj->GetInternalField(index); |
+ if (value->IsSmi()) { |
+ return value; |
+ } else if (value->IsProxy()) { |
+ return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); |
+ } else { |
+ return NULL; |
+ } |
+} |
+ |
+ |
void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
if (IsDeadCheck("v8::External::Unwrap()")) return 0; |
i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
void* result; |
if (obj->IsSmi()) { |
// The external value was an aligned pointer. |
- uintptr_t value = static_cast<uintptr_t>( |
- i::Smi::cast(*obj)->value()) << i::Internals::kAlignedPointerShift; |
- result = reinterpret_cast<void*>(value); |
+ result = *obj; |
} else if (obj->IsProxy()) { |
result = ExternalValueImpl(obj); |
} else { |