简体   繁体   English

如何读取“本机代码”JavaScript 函数?

[英]How can I read ‘native code’ JavaScript functions?

Is there any way to see the declaration of JavaScript native code?有什么办法可以看到JavaScript本机代码的声明吗? Whenever I try to look at a native function in Chrome or Firefox, it says " native code ":每当我尝试在 Chrome 或 Firefox 中查看本机函数时,它都会显示“ native code ”:

> String.fromCharCode
function fromCharCode() { [native code] }

What does this mean, and is there any tool which can help me to read actual code?这是什么意思,是否有任何工具可以帮助我阅读实际代码?

The reason Chrome or Firefox says that the code is native is that it really is native - the WebKit and Firefox developers have coded up that functionality in C or C++, not JavaScript. Chrome 或 Firefox 之所以说代码是原生的,是因为它确实是原生的——WebKit 和 Firefox 开发人员已经用 C 或 C++ 编写了该功能,而不是 JavaScript。 However, if you want to see the actual code, you can look at the source repositories for Chromium and Firefox .但是,如果您想查看实际代码,可以查看ChromiumFirefox的源代码库。

Not within the JavaScript environment, but you can view the source for the open-source implementations.不在 JavaScript 环境中,但您可以查看开源实现的源代码。

Google V8: http://code.google.com/p/v8/source/browse谷歌 V8: http : //code.google.com/p/v8/source/browse

Mozilla SpiderMonkey: https://developer.mozilla.org/en/SpiderMonkey Mozilla SpiderMonkey: https : //developer.mozilla.org/en/SpiderMonkey

Firefox now supports the inspection of "[native code]" objects via standard dev tools. Firefox 现在支持通过标准开发工具检查“[native code]”对象。

To see it in action:要查看它的实际效果:

  1. update Firefox (definitely works w/ v68+, may work with older versions as well)更新 Firefox(绝对适用于 v68+,也可以适用于旧版本)
  2. open dev tools打开开发工具
  3. go to the Console转到控制台
  4. type the name of a native object, eg, "Document"输入本机对象的名称,例如“文档”
  5. hit return点击返回
  6. go nuts on all those little dropdown arrows对所有这些小下拉箭头发疯

FireFox - inspect "native code" - Document object FireFox - 检查“本机代码” - 文档对象

Chrome still returns ƒ Document() { [native code] } , unfortunately.不幸的是,Chrome 仍然返回ƒ Document() { [native code] }

Chrome - DON'T inspect "native code" - disappointment Chrome - 不要检查“本机代码” - 失望

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM