Interceptor gets called only once on an instance

30 views
Skip to first unread message

Alexandre Parenteau

unread,
Sep 22, 2017, 7:41:59 AM9/22/17
to v8-users
Hi,

Using V8 5.1.

I have this function template class "Group":

templ->SetClassName(v8::String::NewFromUtf8(isolateP, "Group"));

  v8::Handle<v8::ObjectTemplate> inst = templ->InstanceTemplate();
inst->SetInternalFieldCount(1);

I set an accessor "foo", and this one gets always called when doing "group.foo":

inst->SetAccessor(v8::String::NewFromUtf8(isolateP, "foo"), getProperty, 0, v8::Int32::New(42));

The interceptor intercepts "bar". GroupNamedQueryInterceptor returns "v8::PropertyAttribute::None" for "bar"

inst->SetHandler(v8::NamedPropertyHandlerConfiguration(
GroupNamedPropertyGetter, NULL, GroupNamedQueryInterceptor, NULL, NULL,
v8::Local<v8::Value>(),
v8::PropertyHandlerFlags(0)));

The initial instance is created with:

v8::Handle<v8::Object> instance = ...>GetFunction()->NewInstance();

And added to the global scope as "group" of class "Group"

When executing "group.bar", I get in the interceptor GroupNamedQueryInterceptor. The getter GroupNamedPropertyGetter creates a new instance of same class "Group", and returns it.

So now "bar" is an instance of "Group" as well.

So I would expect "group.bar.bar" to come back in the interceptor a second time, but it does not!

However "group.bar.foo" accesses the second instance accessor just fine.

It feels really strange. I was hoping someone could unstuck me.

Thanks in advance!
alex

Zac Hansen

unread,
Sep 24, 2017, 11:06:55 PM9/24/17
to v8-users
I'd suggest implementing the other parts of the interceptor and see if they're getting called.. and if so, make sure to implement them properly for your object.

This is just the approach I would take without really understanding why you're seeing this behavior..

Alexandre Parenteau

unread,
Sep 25, 2017, 2:11:25 PM9/25/17
to v8-users
Thanks Zac for the suggestion!

I will try to expand the interceptors tomorrow.

I found one promising example in Chrome (below), and I'm hoping to find the fastest possible way, one that avoids lookup (it's using kNonMasking, but I'm guessing kOnlyInterceptStrings would help too).

chrome\src\third_party\pdfium\fxjs\cfxjse_class.cpp

I was intrigued by this line in the file above:

void NamedPropertyQueryCallback()
{
...
  const int32_t iV8Absent = 64;
  info.GetReturnValue().Set(iV8Absent);
}

Someone knows what is iV8Absent !? It's not listed in the API afaik

Cheers,
alex
Reply all
Reply to author
Forward
0 new messages