Interceptors running under "with"

20 views
Skip to first unread message

Danny Dorfman

unread,
Apr 3, 2017, 10:25:25 AM4/3/17
to v8-users
Hello there,

Is there a way for my interceptor to know that it's running under "with", as in this example:

var a = 10;
with (new CONS()) { do_something(a); }

The problem is, that 'a' is intercepted by the new object, and is rendered undefined. I would like it to use the external 'a' instead.

Regards,
Danny

Zac Hansen

unread,
Apr 3, 2017, 3:51:57 PM4/3/17
to v8-users
Are you using the objecttemplate's setnamedpropertyhandler call?  if so, are you implementing all the callbacks to say that your CONS object doesn't have a property a?

Danny Dorfman

unread,
Apr 4, 2017, 2:01:34 AM4/4/17
to v8-users
Yes, I use SetNamedPropertyHandler. However, I'd like to make the following distinction:
If I am not inside "using", the handler for "a" should return v8::Undefined (or some other preset value).
If I am inside "using", the handler should not return anything at all, and let V8 determine the value.
Is that possible?

Zac Hansen

unread,
Apr 4, 2017, 2:05:11 AM4/4/17
to v8-u...@googlegroups.com
I don't know for sure, but if you don't tell the interceptor that a isn't a property on CONS, then it thinks it is and then it finds cons_object.a but then you don't have a value for it, so it returns undefined.   

Have you fully implemented all 5 of the callbacks for setnamedpropertyhandler?  maybe even just put some print statements in them to see which are called when and for what property names.  

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/dJLWr6EF8kc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Danny Dorfman

unread,
Apr 4, 2017, 4:10:10 AM4/4/17
to v8-users
I just implemented all the callbacks, and I see that for "with" there are calls to QueryProperty, which are not present in the no-with scenario.
Maybe I can take it from there. Thanks for the idea!
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

Zac Hansen

unread,
Apr 4, 2017, 4:18:56 AM4/4/17
to v8-u...@googlegroups.com
from the docs:


 Returns a non-empty handle if the interceptor intercepts the request 

so make sure you are returning an empty handle for properties your object shouldn't respond to.

To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages