I have a following JavaScript code:
class Contract {
// constructor
constructor() {
// dynamic data
this.str = '';
this.count = 0;
}
// update function
update(_value){
this.str = _value;
this.count++;
}
}
How can I get bytecode and state of virtual machine using V8 engine?
asked Apr 27, 2018 at 20:25
Lilit Zakaryan
891 silver badge6 bronze badges
1 Answer 1
Bytecode is not exposed on V8's C++ API.
For human inspection, you can dump it to stdout by using the --print-bytecode flag.
If you're willing to modify V8 for your purposes, you can e.g. look for occurrences of FLAG_print_bytecode in the source to see how the bytecode can be accessed.
answered Apr 27, 2018 at 20:35
jmrk
42.1k7 gold badges74 silver badges93 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
Lilit Zakaryan
Thank you. I can parse javascript with V8's C++ to C++ object and get access to properties. So there should be a way for accessing property bytcode
jmrk
Internally, there's
SharedFunctionInfo::HasBytecodeArray() and SharedFunctionInfo::GetBytecodeArray(), but as I said, these are not exposed on the embedder API. What do you need the bytecode for?Lilit Zakaryan
Sorry as I understand this APIs is not public ?
Lilit Zakaryan
I just need to get the byte code and the state of the virtual machine after each call. I mean to have some C++ object which contains byte code. Not just printing
jmrk
Correct, there's no way to access bytecode via the public API. It's an internal implementation detail. Sorry.
default