Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index e72abc87de14ecf523fe5d892b694287db3cbc26..131645cbb63684051101274df21dc135a4754876 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -1535,20 +1535,12 @@ void ObjectTemplate::SetAccessor(v8::Local<Name> name, |
signature, i::FLAG_disable_old_api_accessors); |
} |
- |
template <typename Getter, typename Setter, typename Query, typename Deleter, |
typename Enumerator> |
-static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, |
- Getter getter, Setter setter, |
- Query query, Deleter remover, |
- Enumerator enumerator, |
- Local<Value> data, |
- PropertyHandlerFlags flags) { |
- i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate(); |
- ENTER_V8(isolate); |
- i::HandleScope scope(isolate); |
- auto cons = EnsureConstructor(isolate, templ); |
- EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler"); |
+static i::Handle<i::InterceptorInfo> CreateInterceptorInfo( |
+ i::Isolate* isolate, Getter getter, Setter setter, Query query, |
+ Deleter remover, Enumerator enumerator, Local<Value> data, |
+ PropertyHandlerFlags flags) { |
auto obj = i::Handle<i::InterceptorInfo>::cast( |
isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE)); |
obj->set_flags(0); |
@@ -1570,6 +1562,24 @@ static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, |
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
} |
obj->set_data(*Utils::OpenHandle(*data)); |
+ return obj; |
+} |
+ |
+template <typename Getter, typename Setter, typename Query, typename Deleter, |
+ typename Enumerator> |
+static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, |
+ Getter getter, Setter setter, |
+ Query query, Deleter remover, |
+ Enumerator enumerator, |
+ Local<Value> data, |
+ PropertyHandlerFlags flags) { |
+ i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate(); |
+ ENTER_V8(isolate); |
+ i::HandleScope scope(isolate); |
+ auto cons = EnsureConstructor(isolate, templ); |
+ EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler"); |
+ auto obj = CreateInterceptorInfo(isolate, getter, setter, query, remover, |
+ enumerator, data, flags); |
cons->set_named_property_handler(*obj); |
} |
@@ -1616,6 +1626,8 @@ void ObjectTemplate::SetAccessCheckCallback(AccessCheckCallback callback, |
i::Handle<i::AccessCheckInfo>::cast(struct_info); |
SET_FIELD_WRAPPED(info, set_callback, callback); |
+ info->set_named_interceptor(nullptr); |
+ info->set_indexed_interceptor(nullptr); |
if (data.IsEmpty()) { |
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
@@ -1626,32 +1638,54 @@ void ObjectTemplate::SetAccessCheckCallback(AccessCheckCallback callback, |
cons->set_needs_access_check(true); |
} |
-void ObjectTemplate::SetHandler( |
- const IndexedPropertyHandlerConfiguration& config) { |
+void ObjectTemplate::SetAccessCheckCallbackAndHandler( |
+ AccessCheckCallback callback, |
+ const NamedPropertyHandlerConfiguration& named_handler, |
+ const IndexedPropertyHandlerConfiguration& indexed_handler, |
+ Local<Value> data) { |
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
ENTER_V8(isolate); |
i::HandleScope scope(isolate); |
auto cons = EnsureConstructor(isolate, this); |
- EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler"); |
- auto obj = i::Handle<i::InterceptorInfo>::cast( |
- isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE)); |
- obj->set_flags(0); |
+ EnsureNotInstantiated( |
+ cons, "v8::ObjectTemplate::SetAccessCheckCallbackWithHandler"); |
- if (config.getter != 0) SET_FIELD_WRAPPED(obj, set_getter, config.getter); |
- if (config.setter != 0) SET_FIELD_WRAPPED(obj, set_setter, config.setter); |
- if (config.query != 0) SET_FIELD_WRAPPED(obj, set_query, config.query); |
- if (config.deleter != 0) SET_FIELD_WRAPPED(obj, set_deleter, config.deleter); |
- if (config.enumerator != 0) { |
- SET_FIELD_WRAPPED(obj, set_enumerator, config.enumerator); |
- } |
- obj->set_all_can_read(static_cast<int>(config.flags) & |
- static_cast<int>(PropertyHandlerFlags::kAllCanRead)); |
+ i::Handle<i::Struct> struct_info = |
+ isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
+ i::Handle<i::AccessCheckInfo> info = |
+ i::Handle<i::AccessCheckInfo>::cast(struct_info); |
+ |
+ SET_FIELD_WRAPPED(info, set_callback, callback); |
+ auto named_interceptor = CreateInterceptorInfo( |
+ isolate, named_handler.getter, named_handler.setter, named_handler.query, |
+ named_handler.deleter, named_handler.enumerator, named_handler.data, |
+ named_handler.flags); |
+ info->set_named_interceptor(*named_interceptor); |
+ auto indexed_interceptor = CreateInterceptorInfo( |
+ isolate, indexed_handler.getter, indexed_handler.setter, |
+ indexed_handler.query, indexed_handler.deleter, |
+ indexed_handler.enumerator, indexed_handler.data, indexed_handler.flags); |
+ info->set_indexed_interceptor(*indexed_interceptor); |
- v8::Local<v8::Value> data = config.data; |
if (data.IsEmpty()) { |
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
} |
- obj->set_data(*Utils::OpenHandle(*data)); |
+ info->set_data(*Utils::OpenHandle(*data)); |
+ |
+ cons->set_access_check_info(*info); |
+ cons->set_needs_access_check(true); |
+} |
+ |
+void ObjectTemplate::SetHandler( |
+ const IndexedPropertyHandlerConfiguration& config) { |
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
+ ENTER_V8(isolate); |
+ i::HandleScope scope(isolate); |
+ auto cons = EnsureConstructor(isolate, this); |
+ EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler"); |
+ auto obj = CreateInterceptorInfo( |
+ isolate, config.getter, config.setter, config.query, config.deleter, |
+ config.enumerator, config.data, config.flags); |
cons->set_indexed_property_handler(*obj); |
} |