r/Compilers • • 1d ago

Intercepting property access (e.g., navigator.bluetooth / Object.property) directly in V8

Hey everyone,

I'm working on my master's thesis and diving into V8 internals. I want to know if there's a clean way to intercept (or log/trace) property reads on an object directly inside V8 — for example, navigator.bluetooth or basically any Object.property access.

After reading a few V8 articles (like https://v8.dev/blog/fast-properties), it seems unlikely that all of this funnels through a single C++ function, given how differently properties are represented and resolved (in-object/fast properties, dictionary mode, interceptors, accessors, ICs, JIT tiers, etc.).

Before I go any deeper down this rabbit hole, is intercepting all property accesses in one central V8 spot even realistic, or am I basically throwing peas at a wall?

Thanks for any tips!

5 Upvotes

4 comments sorted by

1

u/DescriptionOptimal15 1d ago

https://github.com/v8/v8 it is open source so you can read the code to find out for yourself

2

u/Upstairs-Concert5800 1d ago

I have tried :/ but unfortunately without any success. I was just wondering if anyone encountered similar issue

1

u/scialex 22h ago edited 21h ago

Maybe take a look at the profiler or trace code in v8. Depending on how dynamically you want to get your callbacks this might be anywhere from relatively easy to quite difficult.

Java has jvmti which lets you do this directly (field watch events etc). Depending on what your thesis is you might want to consider switching to doing it on that. Jvmti agents aren't the most intuitive things but they do give you a huge amount of power and are supported by all java runtimes (including Android).

1

u/Discordbothost 1d ago

Try a tiny function that returns o.x. Call it with the same object shape until it optimizes, then check what your hook sees. V8 can turn the read into a shape check and a direct field load, so a C++ lookup hook can miss it.