(V8 developer here.) V8's API does not provide access to functions' bytecode. That's intentional, because bytecode is an internal implementation detail. For inspecting bytecode, the --print-bytecode
flag is the way to go.
If you insist on mucking with internal details, then of course you can circumvent the public API and poke at V8's internals. From a v8::internal::JSFunction
you can get to the v8::internal::SharedFunctionInfo
, check whether it HasBytecodeArray()
, and if so, call GetBytecodeArray()
on it. Disassembling bytecode never has side effects, and never executes the bytecode. It's entirely possible that a function doesn't have bytecode at a given moment in time -- bytecode is created lazily when it's needed, and thrown away if it hasn't been used in a while. If you dig far enough, you can interfere with those mechanisms too, but...:
Needless to say, accessing internal details is totally unsupported, not recommended, and even if you get it to work in Node version x.y, it may break in x.(y+1), because that's what "internal details" means.