Some builtins (such as Array.prototype.sort
) are now written in Torque rather than C++ or JavaScript. Torque is a language built for V8:
The language was designed to be simple enough to make it easy to directly translate the ECMAScript specification into an implementation in V8, but powerful enough to express the low-level V8 optimization tricks in a robust way, like creating fast-paths based on tests for specific object-shapes.
...
Torque provides language constructs to represent high-level, semantically-rich tidbits of V8 implementation, and the Torque compiler converts these morsels into efficient assembly code using the CodeStubAssembler
.
(More about CodeStubAssembler
here.)
More in the Torque builtins blog post.
So yes, Array.prototype.sort
and many other Array
methods are written in Torque now, which is compiled to efficient assembly code, which is used by V8's JavaScript interpreter (Ignition) and JavaScript compiler (TurboFan). (Yes, V8 has both. :-) More here, but briefly: V8 parses JavaScript to bytecode, then interprets it with Ignition. Hotspots [areas that are run a lot] get compiled to native code via TurboFan as and when needed.)