gpt4 book ai didi

javascript - V8 引擎是否使用 C++ 替换了以前用 JavaScript 编写的部分代码库?

转载 作者:太空狗 更新时间:2023-10-29 20:49:54 31 4
gpt4 key购买 nike

之前看过V8引擎源码。我可以在其中找到 JavaScript 实现的代码,例如Array.js .

最近又想找数组排序的源码,发现去掉了JS部分。我能找到的只有 array-sort.tq,它在 [v8/third_party/v8/builtins] 中。

是不是我找的方法有问题?还是只是去掉了 JS 部分? JavaScript 开发人员很难了解实现的细节。

最佳答案

一些内置函数(例如Array.prototype.sort)现在写在Torque 中而不是 C++ 或 JavaScript。 Torque 是为 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.

(有关 CodeStubAssembler here 的更多信息。)

更多内容在 Torque builtins blog post .

是的,Array.prototype.sort 和许多其他Array 方法现在是用 Torque 编写的,它被编译成高效的汇编代码,供 V8 的 JavaScript 使用解释器 (Ignition) 和 JavaScript 编译器 (TurboFan)。 (是的,V8 两者都有。:-) More here ,但简单地说:V8 将 JavaScript 解析为字节码,然后用 Ignition 对其进行解释。热点 [经常运行的区域] 在需要时通过 TurboFan 编译为 native 代码。)

关于javascript - V8 引擎是否使用 C++ 替换了以前用 JavaScript 编写的部分代码库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57114248/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com