In Cloudflare Workers we just updated to v8 12.6 and spotted a new pending
deprecation notice saying to move from using SetAccessor to
SetNativeDataProperty. Unfortunately, there appears to possibly to be an
issue with that when using a `v8::FunctionTemplate` and setting the
accessor property on the `PrototypeTemplate()`
Take for example the following snippet (there are a few utility methods in
here from the workerd codebase like check() and `js.str(...)` etc that are
just helpers...
auto tmpl = v8::FunctionTemplate::New(js.v8Isolate, nullptr);
v8::Local<v8::String> foo = js.str("foo"_kj);
tmpl->PrototypeTemplate()->SetNativeDataProperty(foo,
[](v8::Local<v8::Name> name, const
v8::PropertyCallbackInfo<v8::Value>& info) {
auto& js = Lock::from(info.GetIsolate());
info.GetReturnValue().Set(v8::Local<v8::Value>(js.str("foo"_kj)));
},
[](v8::Local<v8::Name> name, v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
KJ_DBG("Setter is called!");
info.GetReturnValue().Set(value);
}, v8::Local<v8::Value>(), v8::PropertyAttribute::None);
v8::Local<v8::Object> obj =
check(tmpl->InstanceTemplate()->NewInstance(js.v8Context()));
// The setter is not called in this case!
check(obj->Set(js.v8Context(), foo, js.num(1)));
// The setter IS called in this one
check(obj->GetPrototype().As<v8::Object>()->Set(js.v8Context(), foo,
js.num(2)));
In this case, the Setter configured on the obj prototype is not called when
set via `obj->Set(...)`.
The question is: with the intended move to `SetNativeDataProperty()` as
communicated via the pending deprecation notice, is this a bug or is the
behavior here intentional? Should setters provided
`PrototypeInstance()->SetNativeDataProperty(...)` Just Work? Or am I just
doing something wrong here?
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/v8-dev/da4aa5ef-d4ae-4b35-ae5c-4946cf8f4d49n%40googlegroups.com.