问题
I'm learning about the V8 run time and I'm wondering if array methods for example, such as array.map
, are written in C++ inside V8? I see here some Torque files that confuse me so I am wondering if maybe they are written in Torque instead of C++?
https://github.com/v8/v8/blob/master/src/builtins/array-map.tq
My understanding is that V8 converts the JavaScript code to machine code using a Just in Time (JIT) concept.
So I guess I'm wondering if there are C++ or Torque equivalents of array.map
, or are the C++ or Torque modules only meant to convert the JS version of array.map
to machine code?
Thanks!
回答1:
V8 developer here. We have several different implementation techniques for "builtins": some are written in C++, some in Torque, some in what we call CodeStubAssembler, and a few directly in assembly. In earlier versions of V8, some were implemented in JavaScript. Each of these strategies has its own strengths (trading off code complexity, debuggability, performance in various situations, binary size, and memory consumption); plus there is always the historical reason that code has evolved over time.
来源:https://stackoverflow.com/questions/56585898/are-array-methods-in-v8-written-in-c-torque-or-is-the-js-converted-to-machine