Commit 5ce364d8 authored by dcarney's avatar dcarney Committed by Commit bot

new api for adding indexed interceptors

R=svenpanne@chromium.org

BUG=

Review URL: https://codereview.chromium.org/765883003

Cr-Commit-Position: refs/heads/master@{#25688}
parent a9f692ec
......@@ -3876,6 +3876,31 @@ struct NamedPropertyHandlerConfiguration {
};
struct IndexedPropertyHandlerConfiguration {
IndexedPropertyHandlerConfiguration(
/** Note: getter is required **/
IndexedPropertyGetterCallback getter = 0,
IndexedPropertySetterCallback setter = 0,
IndexedPropertyQueryCallback query = 0,
IndexedPropertyDeleterCallback deleter = 0,
IndexedPropertyEnumeratorCallback enumerator = 0,
Handle<Value> data = Handle<Value>())
: getter(getter),
setter(setter),
query(query),
deleter(deleter),
enumerator(enumerator),
data(data) {}
IndexedPropertyGetterCallback getter;
IndexedPropertySetterCallback setter;
IndexedPropertyQueryCallback query;
IndexedPropertyDeleterCallback deleter;
IndexedPropertyEnumeratorCallback enumerator;
Handle<Value> data;
};
/**
* An ObjectTemplate is used to create objects at runtime.
*
......@@ -3958,6 +3983,7 @@ class V8_EXPORT ObjectTemplate : public Template {
* \param data A piece of data that will be passed to the callbacks
* whenever they are invoked.
*/
// TODO(dcarney): deprecate
void SetNamedPropertyHandler(
NamedPropertyGetterCallback getter,
NamedPropertySetterCallback setter = 0,
......@@ -3983,14 +4009,18 @@ class V8_EXPORT ObjectTemplate : public Template {
* \param data A piece of data that will be passed to the callbacks
* whenever they are invoked.
*/
void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
// TODO(dcarney): deprecate
void SetIndexedPropertyHandler(
IndexedPropertyGetterCallback getter,
IndexedPropertySetterCallback setter = 0,
IndexedPropertyQueryCallback query = 0,
IndexedPropertyDeleterCallback deleter = 0,
IndexedPropertyEnumeratorCallback enumerator = 0,
Handle<Value> data = Handle<Value>());
Handle<Value> data = Handle<Value>()) {
SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
deleter, enumerator, data));
}
/**
* Sets the callback to be used when calling instances created from
* this template as a function. If no callback is set, instances
......
......@@ -1335,13 +1335,8 @@ void ObjectTemplate::SetAccessCheckCallbacks(
}
void ObjectTemplate::SetIndexedPropertyHandler(
IndexedPropertyGetterCallback getter,
IndexedPropertySetterCallback setter,
IndexedPropertyQueryCallback query,
IndexedPropertyDeleterCallback remover,
IndexedPropertyEnumeratorCallback enumerator,
Handle<Value> data) {
void ObjectTemplate::SetHandler(
const IndexedPropertyHandlerConfiguration& config) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
......@@ -1354,13 +1349,16 @@ void ObjectTemplate::SetIndexedPropertyHandler(
i::Handle<i::InterceptorInfo> obj =
i::Handle<i::InterceptorInfo>::cast(struct_obj);
if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
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_flags(0);
v8::Local<v8::Value> data = config.data;
if (data.IsEmpty()) {
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
......
This diff is collapsed.
......@@ -4394,11 +4394,8 @@ TEST(InterceptorPropertyMirror) {
// Create object with indexed interceptor.
v8::Handle<v8::ObjectTemplate> indexed = v8::ObjectTemplate::New(isolate);
indexed->SetIndexedPropertyHandler(IndexedGetter,
NULL,
NULL,
NULL,
IndexedEnum);
indexed->SetHandler(v8::IndexedPropertyHandlerConfiguration(
IndexedGetter, NULL, NULL, NULL, IndexedEnum));
env->Global()->Set(
v8::String::NewFromUtf8(isolate, "intercepted_indexed"),
indexed->NewInstance());
......@@ -4407,7 +4404,8 @@ TEST(InterceptorPropertyMirror) {
v8::Handle<v8::ObjectTemplate> both = v8::ObjectTemplate::New(isolate);
both->SetHandler(v8::NamedPropertyHandlerConfiguration(
NamedGetter, NULL, NULL, NULL, NamedEnum));
both->SetIndexedPropertyHandler(IndexedGetter, NULL, NULL, NULL, IndexedEnum);
both->SetHandler(v8::IndexedPropertyHandlerConfiguration(
IndexedGetter, NULL, NULL, NULL, IndexedEnum));
env->Global()->Set(
v8::String::NewFromUtf8(isolate, "intercepted_both"),
both->NewInstance());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment