Search code examples
node.jsv8

In nodejs, how was javascript with c++ code references compiled and executed by the V8 engine?


I know that internalBindings is used in nodejs to help javascript code introduce the c++ module, but in the end v8 will compile javascript into ast. At this time, ast contains both the content of the javascript language and the content referenced by c++.

When executing ast, I wonder if it is parsed When reaching the content referenced by c++, first run the c++ code and then return the result, so that JavaScript can be fully integrated into the c++ code. Is this how v8 runs js code?


Solution

  • Like Bergi mentioned the nature of native biding is different and it happens at binary "level" in what we call an ABI (Application Binary Interface). Basically it is the runtime that knows how to deal with objects written in both languages because they respect the same binary structure and interface.

    NodeJS allows you to write C++ addons but it typically provides a Node-API interface in C which can be used with a C++ wrapper that provides a C++ object model and exception handling semantics with low overhead.