v8

what functions will be called in v8 source code when run JavaScript code?


what functions will be called in v8 source code when run the following JavaScript code:

var x = new Number(1);

In which files are these functions?

I want to trace or debug the V8 engine source code. When execute or interpret JavaScript code, what functions in these source code will be called.


Solution

  • In short: "yes" :-)

    By which I mean: all of V8 exists in order to execute JavaScript (and WebAssembly). So when you execute JS, functions in V8 will get called -- more or less all of them, sooner or later.

    Describing with function-level detail how all of V8 works (interpreter, various compilers, builtins, ...) is waaaay too much for one SO answer; in fact it is more than any one human knows. Just read or trace/step the parts of the source that are of interest to you right now.

    One way to get started: Add %SystemBreak(); to your JS snippet, run d8 with --allow-natives-syntax in a debugger like GDB, wait for the breakpoint to get hit, and start stepping from there.

    Or, if you already have a rough idea what you're looking for, set a breakpoint via your debugger. For example, if you want to know how exactly source code is consumed, find the place in d8.cc where the input file is read, and see where it flows from there.