Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index d6ed8aee2f74b3c50e5e3f78f287b974a83326f2..38daf6646b89e90e79bd1fae9d6bf3f58d46e4c7 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -767,6 +767,15 @@ int TypeSwitch::match(v8::Handle<Value> value) { |
} |
+template<typename T, typename V> |
+static void SetFieldWrapped(void (T::*setter) (i::Object*, i::WriteBarrierMode), |
Erik Corry
2010/09/23 07:53:28
This doesn't lint, but presumably removing the dou
|
+ i::Handle<T> a, |
+ V value) { |
+ i::Handle<i::Object> proxy = FromCData(value); |
Vitaly Repeshko
2010/09/21 21:19:59
Isn't it true that by the time handle is created
|
+ ((*a)->*setter)(*proxy, i::UPDATE_WRITE_BARRIER); |
Erik Corry
2010/09/23 07:53:28
I don't like pointer-to-method, and I don't like h
|
+} |
+ |
+ |
void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
v8::Handle<Value> data) { |
if (IsDeadCheck("v8::FunctionTemplate::SetCallHandler()")) return; |
@@ -776,7 +785,7 @@ void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE); |
i::Handle<i::CallHandlerInfo> obj = |
i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
- obj->set_callback(*FromCData(callback)); |
+ SetFieldWrapped(&i::CallHandlerInfo::set_callback, obj, callback); |
if (data.IsEmpty()) data = v8::Undefined(); |
obj->set_data(*Utils::OpenHandle(*data)); |
Utils::OpenHandle(this)->set_call_code(*obj); |
@@ -792,8 +801,8 @@ static i::Handle<i::AccessorInfo> MakeAccessorInfo( |
v8::PropertyAttribute attributes) { |
i::Handle<i::AccessorInfo> obj = i::Factory::NewAccessorInfo(); |
ASSERT(getter != NULL); |
- obj->set_getter(*FromCData(getter)); |
- obj->set_setter(*FromCData(setter)); |
+ SetFieldWrapped(&i::AccessorInfo::set_getter, obj, getter); |
+ SetFieldWrapped(&i::AccessorInfo::set_setter, obj, setter); |
if (data.IsEmpty()) data = v8::Undefined(); |
obj->set_data(*Utils::OpenHandle(*data)); |
obj->set_name(*Utils::OpenHandle(*name)); |
@@ -877,11 +886,27 @@ void FunctionTemplate::SetNamedInstancePropertyHandler( |
i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE); |
i::Handle<i::InterceptorInfo> obj = |
i::Handle<i::InterceptorInfo>::cast(struct_obj); |
- if (getter != 0) obj->set_getter(*FromCData(getter)); |
- if (setter != 0) obj->set_setter(*FromCData(setter)); |
- if (query != 0) obj->set_query(*FromCData(query)); |
- if (remover != 0) obj->set_deleter(*FromCData(remover)); |
- if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator)); |
+ |
+ if (getter != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_getter, obj, getter); |
+ } |
+ |
+ if (setter != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_setter, obj, setter); |
+ } |
+ |
+ if (query != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_query, obj, query); |
+ } |
+ |
+ if (remover != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_deleter, obj, remover); |
+ } |
+ |
+ if (enumerator != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_enumerator, obj, enumerator); |
+ } |
+ |
if (data.IsEmpty()) data = v8::Undefined(); |
obj->set_data(*Utils::OpenHandle(*data)); |
Utils::OpenHandle(this)->set_named_property_handler(*obj); |
@@ -905,11 +930,27 @@ void FunctionTemplate::SetIndexedInstancePropertyHandler( |
i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE); |
i::Handle<i::InterceptorInfo> obj = |
i::Handle<i::InterceptorInfo>::cast(struct_obj); |
- if (getter != 0) obj->set_getter(*FromCData(getter)); |
- if (setter != 0) obj->set_setter(*FromCData(setter)); |
- if (query != 0) obj->set_query(*FromCData(query)); |
- if (remover != 0) obj->set_deleter(*FromCData(remover)); |
- if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator)); |
+ |
+ if (getter != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_getter, obj, getter); |
+ } |
+ |
+ if (setter != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_setter, obj, setter); |
+ } |
+ |
+ if (query != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_query, obj, query); |
+ } |
+ |
+ if (remover != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_deleter, obj, remover); |
+ } |
+ |
+ if (enumerator != 0) { |
+ SetFieldWrapped(&i::InterceptorInfo::set_enumerator, obj, enumerator); |
+ } |
+ |
if (data.IsEmpty()) data = v8::Undefined(); |
obj->set_data(*Utils::OpenHandle(*data)); |
Utils::OpenHandle(this)->set_indexed_property_handler(*obj); |
@@ -928,7 +969,7 @@ void FunctionTemplate::SetInstanceCallAsFunctionHandler( |
i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE); |
i::Handle<i::CallHandlerInfo> obj = |
i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
- obj->set_callback(*FromCData(callback)); |
+ SetFieldWrapped(&i::CallHandlerInfo::set_callback, obj, callback); |
if (data.IsEmpty()) data = v8::Undefined(); |
obj->set_data(*Utils::OpenHandle(*data)); |
Utils::OpenHandle(this)->set_instance_call_handler(*obj); |
@@ -1043,8 +1084,15 @@ void ObjectTemplate::SetAccessCheckCallbacks( |
i::Factory::NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
i::Handle<i::AccessCheckInfo> info = |
i::Handle<i::AccessCheckInfo>::cast(struct_info); |
- info->set_named_callback(*FromCData(named_callback)); |
- info->set_indexed_callback(*FromCData(indexed_callback)); |
+ |
+ SetFieldWrapped(&i::AccessCheckInfo::set_named_callback, |
+ info, |
+ named_callback); |
+ |
+ SetFieldWrapped(&i::AccessCheckInfo::set_indexed_callback, |
+ info, |
+ indexed_callback); |
+ |
if (data.IsEmpty()) data = v8::Undefined(); |
info->set_data(*Utils::OpenHandle(*data)); |