2

While using v8 JavaScript engine I do this:

script->Run();

but I want to do something like that:

while (!script->Finished()) {
   script->NextOperation();
   printf("current line: %i\n", script->line);
}

I ask this because I want to understand v8 better. I know it is JIT-compiled, it has debugger interface listening on some port. I failed to find answer to my question by examining headers, leave alone minimalist documentation provided by google.

1 Answer 1

1

What exactly is the question you failed to find an answer to?

What is script->NextOperation() supposed to do?

V8 itself is not JIT-compiled; it JIT-compiles the JavaScript code it executes. How is tracing the JS script line by line related to understanding V8 better?

Two existing approaches come to mind:

  • if you want to trace JavaScript execution, V8 has a built-in --trace flag, which will print a line to stdout whenever a function is entered or exited.
  • if you want to trace the C++ side to see what V8 does under the hood, use your favorite C++ debugger. (Note that this is going to be a very time-consuming approach, as V8 is huge and does lots of things. It might be helpful to be a bit more focused in your investigation, e.g. "how does the parser work" or "what does the garbage collector do". There are also various design docs and blog posts floating around that might be a quicker way to understand many concepts than digging through source or tracing execution.)
Sign up to request clarification or add additional context in comments.

2 Comments

I was thinking how to write JavaScript debugger in C++, I wanted to do step-over, etc.
Well, a full debugger needs much more than just tracing ;-) V8 has all you need, see: github.com/v8/v8/wiki/Debugging-over-the-V8-Inspector-API (that's the same interface as Chrome's DevTools debugger uses, so it's very powerful).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.