How to get native javascript functions source code?

What is V8?

  • V8 is Google's open source JavaScript engine.
  • V8 implements ECMAScript as specified in ECMA-262.
  • V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
  • V8 can run standalone, or can be embedded into any C++ application.
  • V8 project page: https://github.com/v8/v8/wiki
  • V8 source code: https://github.com/v8/v8

The contract for exactly how the Javascript built-ins should behave is outlined in the ECMAScript specification (see example for Array.every()).

There are a number of different Javascript engines, each with their own specific implementation of ECMAScript. The most common Javascript engines are (links point to code for Array.every()):

  • V8 (Chrome, Node, Edge, Android, Opera, other Chromium-based browsers)
  • SpiderMonkey (Firefox)
  • JavaScriptCore (Safari)

  1. Pick a browser
  2. Make sure it is an open source one
  3. Dig through its source code

Some repositories include:

  • Firefox
  • Webkit
  • Chromium

Note that JavaScript native functions are generally not written in JavaScript (expect C or C++ most of the time). They are just exposed to JS through an API.

Also note that the code that scrolls a page when the spacebar is pressed isn't even a function that is exposed to JS.


While this will not show you actual source code, if you're interested in how many of the native JavaScript functions are implemented, you can peruse the specification upon which they are based:

Standard ECMA-262

Tags:

Javascript