r/learnjavascript • u/Upstairs-Concert5800 • 5d 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!
2
u/androbat 4d ago edited 4d ago
Will proxies around them do what you want?
1
u/GiggleSamurai 4d ago
For Web APIs like
navigator.bluetoothyou don't need V8 internals: they're accessor properties generated from Blink's IDL bindings, so hook the generated getters there (Chromium already does this for its use counters with the[Measure]/[MeasureAs]IDL attributes). For arbitrary JS properties there's no single spot, because inline caches and optimized code read fields straight from the object without calling into the runtime.1
u/Greedy_Ad_7658 3d ago
Adding to the "no single spot" answer with where the closest thing to a central spot actually is: the Ignition interpreter. Every unoptimized named property read compiles to a LdaNamedProperty bytecode (or the NoFeedback variant), and those have single handlers in the interpreter, generated from interpreter-generator.tq. People doing dynamic analysis on V8 usually hook there, or start cheaper by running with --trace-ic to watch the IC feedback evolve per access site.
The catch is what happens next. Once the ICs warm up and TurboFan optimizes the function, a monomorphic property load gets lowered to a map check plus a plain memory read at a fixed offset. The "property access" stops existing as an operation, so any central hook silently sees less and less as code tiers up. For a thesis that is actually a nice result to demonstrate rather than a failure: run the same workload with --no-opt versus default and show how much of the access stream disappears from your hook as optimization kicks in.
Practical tip: build d8 and experiment there instead of full Chrome. You get the useful flags (--trace-ic, --print-bytecode, --allow-natives-syntax with %DebugPrint to inspect maps and hidden classes) without building Blink. Blink only matters for the navigator.* side, and there the IDL/[Measure] route from the other answer is the right one.