Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to see JavaScript default methods source-code?

Is there any way to see JavaScript default methods source-code? For example .sort() or .reverse(). I think is C code but where can I read it?

like image 572
user2105306 Avatar asked Oct 25 '25 04:10

user2105306


1 Answers

In the code for SpiderMonkey's JavaScript Array implementation (used in Firefox), you'll want to start by looking at the array_sort and array_reverse functions. More generally, look for the array_methods constant; it has indices to the relevant functions.

In the code for V8's JavaScript Array implementation (used in Chrome and Opera), you want to look for ArraySort and ArrayReverse functions respectively. Look for GlobalArray.prototype to find an index to the other functions.

JavaScript Core's JavaScript Array implementation (used in Safari) is a bit unusual, in that Array.prototype.sort and its ilk are actually implemented in JavaScript. The sort function you want is simply named sort in this file. However, not all of the Array.prototype family of functions are found in that file; for example, I'm not sure where reverse is.

The source code for Chakra's implementation (used in IE) is not available, and I suspect that they probably never will be. The same goes for the source code for Presto's implementation (formerly used in Opera, before they switched to Blink/V8).

like image 101
The Spooniest Avatar answered Oct 26 '25 19:10

The Spooniest