[api] Mark SetNamedPropertyHandler as soon to be deprecated
Eventually we should migrate to new new-style callbacks which take Names instead of Strings as first arguments everywhere. Internally we don't really handler NamedPropertyCallbackXX differently from the newer GenericNamedPropertyCallbackXX. Bug: v8:7109 Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I827182f447427c222d5144f1a3e27bf543226e51 Reviewed-on: https://chromium-review.googlesource.com/803340 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Camillo Bruni <cbruni@chromium.org> Cr-Commit-Position: refs/heads/master@{#49824}
This commit is contained in:
parent
adcd4a69f9
commit
5275c3c41c
20
include/v8.h
20
include/v8.h
@ -5468,7 +5468,8 @@ typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
|
||||
* v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
|
||||
* instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"),
|
||||
* InstanceAccessorCallback);
|
||||
* instance_t->SetNamedPropertyHandler(PropertyHandlerCallback);
|
||||
* instance_t->SetHandler(
|
||||
* NamedPropertyHandlerConfiguration(PropertyHandlerCallback));
|
||||
* instance_t->Set(String::NewFromUtf8(isolate, "instance_property"),
|
||||
* Number::New(isolate, 3));
|
||||
*
|
||||
@ -5866,13 +5867,16 @@ 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,
|
||||
NamedPropertyQueryCallback query = 0,
|
||||
NamedPropertyDeleterCallback deleter = 0,
|
||||
NamedPropertyEnumeratorCallback enumerator = 0,
|
||||
Local<Value> data = Local<Value>());
|
||||
V8_DEPRECATE_SOON(
|
||||
"Use SetHandler(const NamedPropertyHandlerConfiguration) "
|
||||
"with the kOnlyInterceptStrings flag set.",
|
||||
void SetNamedPropertyHandler(
|
||||
NamedPropertyGetterCallback getter,
|
||||
NamedPropertySetterCallback setter = 0,
|
||||
NamedPropertyQueryCallback query = 0,
|
||||
NamedPropertyDeleterCallback deleter = 0,
|
||||
NamedPropertyEnumeratorCallback enumerator = 0,
|
||||
Local<Value> data = Local<Value>()));
|
||||
|
||||
/**
|
||||
* Sets a named property handler on the object template.
|
||||
|
@ -1794,6 +1794,7 @@ static void ObjectTemplateSetNamedPropertyHandler(
|
||||
cons->set_named_property_handler(*obj);
|
||||
}
|
||||
|
||||
// TODO(cbruni) deprecate.
|
||||
void ObjectTemplate::SetNamedPropertyHandler(
|
||||
NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter,
|
||||
NamedPropertyQueryCallback query, NamedPropertyDeleterCallback remover,
|
||||
|
@ -98,10 +98,10 @@ void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
|
||||
SimpleAccessorSetter(Local<String>::Cast(sym->Name()), value, info);
|
||||
}
|
||||
|
||||
void StringInterceptorGetter(
|
||||
Local<String> name,
|
||||
const v8::PropertyCallbackInfo<v8::Value>&
|
||||
info) { // Intercept names that start with 'interceptor_'.
|
||||
void InterceptorGetter(Local<Name> generic_name,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
if (generic_name->IsSymbol()) return;
|
||||
Local<String> name = Local<String>::Cast(generic_name);
|
||||
String::Utf8Value utf8(info.GetIsolate(), name);
|
||||
char* name_str = *utf8;
|
||||
char prefix[] = "interceptor_";
|
||||
@ -117,9 +117,10 @@ void StringInterceptorGetter(
|
||||
.ToLocalChecked());
|
||||
}
|
||||
|
||||
|
||||
void StringInterceptorSetter(Local<String> name, Local<Value> value,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
void InterceptorSetter(Local<Name> generic_name, Local<Value> value,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
if (generic_name->IsSymbol()) return;
|
||||
Local<String> name = Local<String>::Cast(generic_name);
|
||||
// Intercept accesses that set certain integer values, for which the name does
|
||||
// not start with 'accessor_'.
|
||||
String::Utf8Value utf8(info.GetIsolate(), name);
|
||||
@ -140,18 +141,6 @@ void StringInterceptorSetter(Local<String> name, Local<Value> value,
|
||||
}
|
||||
}
|
||||
|
||||
void InterceptorGetter(Local<Name> generic_name,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
if (generic_name->IsSymbol()) return;
|
||||
StringInterceptorGetter(Local<String>::Cast(generic_name), info);
|
||||
}
|
||||
|
||||
void InterceptorSetter(Local<Name> generic_name, Local<Value> value,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
if (generic_name->IsSymbol()) return;
|
||||
StringInterceptorSetter(Local<String>::Cast(generic_name), value, info);
|
||||
}
|
||||
|
||||
void GenericInterceptorGetter(Local<Name> generic_name,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
Local<String> str;
|
||||
@ -198,19 +187,20 @@ void AddAccessor(Local<FunctionTemplate> templ, Local<String> name,
|
||||
templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
|
||||
}
|
||||
|
||||
void AddInterceptor(Local<FunctionTemplate> templ,
|
||||
v8::NamedPropertyGetterCallback getter,
|
||||
v8::NamedPropertySetterCallback setter) {
|
||||
templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
|
||||
}
|
||||
|
||||
|
||||
void AddAccessor(Local<FunctionTemplate> templ, Local<Name> name,
|
||||
v8::AccessorNameGetterCallback getter,
|
||||
v8::AccessorNameSetterCallback setter) {
|
||||
templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
|
||||
}
|
||||
|
||||
void AddStringOnlyInterceptor(Local<FunctionTemplate> templ,
|
||||
v8::GenericNamedPropertyGetterCallback getter,
|
||||
v8::GenericNamedPropertySetterCallback setter) {
|
||||
templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
|
||||
getter, setter, nullptr, nullptr, nullptr, Local<v8::Value>(),
|
||||
v8::PropertyHandlerFlags::kOnlyInterceptStrings));
|
||||
}
|
||||
|
||||
void AddInterceptor(Local<FunctionTemplate> templ,
|
||||
v8::GenericNamedPropertyGetterCallback getter,
|
||||
v8::GenericNamedPropertySetterCallback setter) {
|
||||
@ -1517,7 +1507,7 @@ THREADED_TEST(LegacyInterceptorDoesNotSeeSymbols) {
|
||||
|
||||
child->Inherit(parent);
|
||||
AddAccessor(parent, age, SymbolAccessorGetter, SymbolAccessorSetter);
|
||||
AddInterceptor(child, StringInterceptorGetter, StringInterceptorSetter);
|
||||
AddStringOnlyInterceptor(child, InterceptorGetter, InterceptorSetter);
|
||||
|
||||
env->Global()
|
||||
->Set(env.local(), v8_str("Child"),
|
||||
|
@ -22317,16 +22317,13 @@ THREADED_TEST(InstanceCheckOnInstanceAccessor) {
|
||||
CheckInstanceCheckedAccessors(false);
|
||||
}
|
||||
|
||||
|
||||
static void EmptyInterceptorGetter(
|
||||
Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {}
|
||||
|
||||
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {}
|
||||
|
||||
static void EmptyInterceptorSetter(
|
||||
Local<String> name, Local<Value> value,
|
||||
Local<Name> name, Local<Value> value,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {}
|
||||
|
||||
|
||||
THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
|
||||
v8::internal::FLAG_allow_natives_syntax = true;
|
||||
LocalContext context;
|
||||
@ -22334,8 +22331,8 @@ THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
|
||||
|
||||
Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
|
||||
Local<ObjectTemplate> inst = templ->InstanceTemplate();
|
||||
templ->InstanceTemplate()->SetNamedPropertyHandler(EmptyInterceptorGetter,
|
||||
EmptyInterceptorSetter);
|
||||
templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
|
||||
EmptyInterceptorGetter, EmptyInterceptorSetter));
|
||||
inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter,
|
||||
Local<Value>(), v8::DEFAULT, v8::None,
|
||||
v8::AccessorSignature::New(context->GetIsolate(), templ));
|
||||
|
Loading…
Reference in New Issue
Block a user