93

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?

2

3 Answers 3

106

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I agree but I thought maybe some extension is there which does that for me. I can look into documentation but I was looking for a shortcut.
Is there a way to look into native webkit code for Safari? I'm debugging an issue with webkitAudioContext (HTML5 WebAudio API). Dealing with ScriptProcessorNode, works fine in Chrome & Firefox and behaves weirdly in Safari. Since Safari code isn't open, is there a way to debug using something like ptrace?
how can search what i want in this doc?!
34

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

1 Comment

That's very useful but I was looking within a console or something. A shortcut. Going to documentation and search for it was annoying. Anyways thank you for replying.
-1

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

2 Comments

This doesn't show the source code of the function, it just shows the object properties of the function object like console.dir(Document) does.
I agree with Bergi. I used FF 80, ran Number.prototype.constructor.toString() and got "function Number() { [native code] }" as output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.