How can I read ‘native code’ JavaScript functions?

Javascript

Javascript Problem Overview


Is there any way to see the declaration of JavaScript native code? Whenever I try to look at a native function in Chrome or Firefox, it says "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?

Javascript Solutions


Solution 1 - Javascript

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. However, if you want to see the actual code, you can look at the source repositories for Chromium and Firefox.

Solution 2 - Javascript

Not within the JavaScript environment, but you can view the source for the open-source implementations.

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

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

Solution 3 - Javascript

Firefox now supports the inspection of "[native code]" objects via standard dev tools.

To see it in action:

  1. update Firefox (definitely works w/ v68+, may work with older versions as well)
  2. open dev tools
  3. go to the Console
  4. type the name of a native object, e.g., "Document"
  5. hit return
  6. go nuts on all those little dropdown arrows

FireFox - inspect "native code" - Document object

Chrome still returns ƒ Document() { [native code] }, unfortunately.

Chrome - DON'T inspect "native code" - disappointment

Solution 4 - Javascript

Chromium Code Search provides a good way to read javascript native code. This post addresses a litter bit about how to use it. And in this video, you can see an example.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionemphaticsunshineView Question on Stackoverflow
Solution 1 - JavascriptAdam MihalcinView Answer on Stackoverflow
Solution 2 - Javascriptuser1106925View Answer on Stackoverflow
Solution 3 - JavascriptgitbfdView Answer on Stackoverflow
Solution 4 - JavascriptYoel DuranView Answer on Stackoverflow