AccessInfo vs AccessorPair?

58 views
Skip to first unread message

Jann Godspeed

unread,
Jul 20, 2020, 7:03:18 AM7/20/20
to v8-dev
I'm having trouble understanding how AccessInfo works. Can they only be defined on special objects?


To define an AccessorPair on an object I would do something like

let o = {}
o
.__defineGetter__("test", function() { });

let o = {};
???

Jakob Kummerow

unread,
Jul 20, 2020, 8:50:23 AM7/20/20
to v8-...@googlegroups.com
AFAIK AccessorInfo can only be defined via the C++ API, i.e. by the embedder (or by V8 itself). AccessorPair is what you get when you define accessors via JavaScript.


--
--
v8-dev mailing list
v8-...@googlegroups.com
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 v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/ec43f635-e18f-481d-95df-52b6180a84edo%40googlegroups.com.

Jann G

unread,
Jul 20, 2020, 10:39:41 AM7/20/20
to v8-dev
Can an AccessorInfo be defined on normal objects or only custom receivers? There's been some confusion in bug reports like:
https://bugs.chromium.org/p/chromium/issues/detail?id=1082355 which reaches PropertyCallbackArguments::CallAccessorGetter.


On Monday, July 20, 2020 at 1:50:23 PM UTC+1, Jakob Kummerow wrote:
AFAIK AccessorInfo can only be defined via the C++ API, i.e. by the embedder (or by V8 itself). AccessorPair is what you get when you define accessors via JavaScript.


On Mon, Jul 20, 2020 at 1:03 PM Jann Godspeed <janngo...@gmail.com> wrote:
I'm having trouble understanding how AccessInfo works. Can they only be defined on special objects?


To define an AccessorPair on an object I would do something like

let o = {}
o
.__defineGetter__("test", function() { });

let o = {};
???

--
--
v8-dev mailing list
v8-...@googlegroups.com
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 v8-...@googlegroups.com.

Jakob Kummerow

unread,
Jul 20, 2020, 1:10:55 PM7/20/20
to v8-...@googlegroups.com
They can be defined on normal objects. The canonical example is Array.prototype.length being implemented as an AccessorInfo.

Toon Verwaest

unread,
Jul 31, 2020, 5:49:06 AM7/31/20
to v8-...@googlegroups.com
AccessorInfo is a "native data property". It behaves like an accessor from the embedder point-of-view, but looks like a data property from javascript (getOwnPropertyDescriptor will return value: ... rather than get(), set(v)).

Even though regular objects can have them too in V8, the embedder can only attach them to custom receivers. If you see something else, this might be because you're looking at This() rather than Holder() when loading a property through the prototype chain. This() will be the object on which the lookup was started, while Holder() is the custom receiver object on which the accessor is installed.

hth

--
--
v8-dev mailing list
v8-...@googlegroups.com
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 v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAKSzg3RxoJDrz2DB4Lt1ww0me6T-3xi2xQfGD9nBabR4q%2BKLbw%40mail.gmail.com.

Jann G

unread,
Aug 20, 2020, 12:18:42 PM8/20/20
to v8-dev
Thanks for the replies! This all makes sense. Where do interceptors come into the picture? Can you only add interceptors to JS_SPECIAL_API_OBJECT_TYPE ? 

Jakob Kummerow

unread,
Aug 20, 2020, 12:50:48 PM8/20/20
to v8-dev
On Thu, Aug 20, 2020 at 6:18 PM Jann G <janngo...@gmail.com> wrote:
Thanks for the replies! This all makes sense. Where do interceptors come into the picture?

Interceptors can only be set via the API, and are "catch-all accessors", a bit like a JS Proxy's traps.
 
Can you only add interceptors to JS_SPECIAL_API_OBJECT_TYPE ? 

Yes, JS_SPECIAL_API_OBJECT_TYPE has been introduced to let V8 quickly determine "do I need to check for interceptors (and a few other special cases) on this object, or not?". So the implication is kind of the other way round: if you configure interceptors, the object will have ...SPECIAL... type.
Reply all
Reply to author
Forward
0 new messages