Where can I find javascript native functions source code? [duplicate] - javascript

This question already has an answer here:
How can I see the source of built-in JavaScript functions? [closed]
(1 answer)
Closed 6 years ago.
where can I find the source code of native js functions, for example I want to look at eval() function

Both Chrome and Firefox are open source and you can look at the implementation of any part of the javascript engine in the source code for those products. Other browsers have their own implementation (like IE) that is not available to the public to look at.
The Chrome v8 javascript engine code is here: https://github.com/v8/v8
The Firefox SpiderMonkey engine code is here:
https://searchfox.org/mozilla-central/source/js/src
Warning, if you aren't already familiar with those products and their tools, it may take while to get familiar enough to find what you're looking for.
These links may change over time, but can easily be found with Google searches if they move.

Javascript is a script language that is implemented within a Browser's code-base. This means that there may be different implementations of the script language, with different levels of quality, and possibly different intepretations of what is required. Hence the head-against-wall frustrations of many a web-developer when dealing with different web-browsers.
It is possible for you to examine a browser's implementation of Javascript if the browser is an Open Source version, eg: Chrome, Firefox, as given in other answers listed.

In the JavaScript engine's source code.

Related

Where is low level code of Javascript standard built-in objects?

I'm looking for the way to get low level code of javascript built-in function.
For example, there is an polyfill(I want like this form and I call this low level code in my way) in mdn site of 'Array.prototype.indexOf()'
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
And I get to understand that it is kinda low level code of built-in method.
Here is my question, where can I see the code to look inside of method of 'String.prototype.toLowerCase()'?
It'll depend on your javascript implementation.
For V8, here is the guts of toLowerCase (and toUpperCase)
Low level functions (such as these) are generally written in whatever language the javascript engine is written in - that's why they're so fast. So don't go in expecting something that's easy to read for the average javascript-only developer :)
The answer you are looking for probably doesn't exist but I'll do my best do help you out.
The low level function are dependent on which Engine you are using.
A few examples are:
V8 — open source, developed by Google, written in C++
Rhino — managed by the Mozilla Foundation, open source, developed entirely in Java
SpiderMonkey — the first JavaScript engine, which back in the days powered Netscape Navigator, and today powers Firefox
JavaScriptCore — open source, marketed as Nitro and developed by Apple for Safari
I assume you are looking for the function to understand what they are doing. If this is the case and you don't understand the languages that the engines are written it might be an idea to look at the polyfill implementation of those functions. Those are written in javascript and might help you understand them if that's what you are looking for.
Good luck! :)
JavaScript is defined by a standard, with many major implementations.
The definition for that method and others can be found in the TC39 website. It is only defined algorithmically, not in actual code.
That being said, for the open-source implementations, you can actually look at the source code for those implementations, though they will probably be in some other language, such as C++.
The major current open-source implementations of JavaScript are Google's V8, Apple's WebKit and Mozilla's SpiderMonkey.

Is it possible to read the code for JavaScript Global / Built-in Objects' Methods (i.e., array.filter, .sort)? [duplicate]

This question already has answers here:
How can I read ‘native code’ JavaScript functions?
(3 answers)
Closed 6 years ago.
I'm learning JavaScript and am interested in reading the code that makes array.filter, array.sort, and the like work.
I'm not sure what the correct terminology for these methods are, but assumed Global / Built-in after reading this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects.
Is it possible to read the code that makes them work?
There are two levels to the answer to this question. The first level is the specification, for example for array.prototype.filter, it is defined in ECMAScript 5.1 here.
Each JavaScript engine then writes their own implementations of these. Depending on which engine you're interested in, you will be able to see the actual code implementation. For example, V8 (in Chrome) is open source.
Short answer: No.
Long answer: It depends.
Of course these methods are written somewhere; but not usually in JavaScript. They're built into the interpretor, so they're generally written in C/C++, or some other low-level language, depending on which JavaScript engine you're using.
The Spidermonkey, used in FireFox, source is available here, or the V8 sources, used in Node.js and Chrome, here. The source for Microsoft's Chakra engine, used in Edge, is available here. There are many other JavaScript engine implementations, though, some open source, others not.

Google Apps Script Javascript Standard Support [duplicate]

This question already has answers here:
Which Edition of ECMA-262 Does Google Apps Script Support?
(2 answers)
Closed 2 years ago.
Simple question: Can anyone point to a resource or knows anything about which standard of Javascript is supported in Google Apps Script?
I assume naturally that ES5 is fully supported, but what about ES6 (and even 7)?
Note: I mean the built-in code editor, which will appear if you open a Spreadsheet (for example), and click Tools > Script editor...
According to the docs Apps Script is based on JavaScript 1.6.
This table explains the correlation to the ES standards.
From https://developers.google.com/apps-script/guides/services/#basic_javascript_features (January 27, 2019)
Basic JavaScript features
Apps Script is based on
JavaScript 1.6,
plus a few features from
1.7 and
1.8.
Many basic JavaScript features are thus available in addition to the built-in
and advanced Google services: you can
use common objects like
Array,
Date,
RegExp,
and so forth,
as well as the
Math and
Object
global objects. However, because Apps Script code runs on Google's servers (not
client-side, except for HTML-service pages),
browser-based features like DOM manipulation or the
Window API are not
available.
In the native editor it appears you are limited to an earlier version of JS (~ES5).
There is an official tool called "Clasp" though, which lets you write typescript (.ts) files with ES6+ syntax and then compile & upload your files to Drive with clasp push --watch.
Alternatively, you can use Webpack in your local setup as detailed in this answer.
My guess is AngluarJS is since it was made by a google developer.

Hiding javascript files from public [duplicate]

This question already has answers here:
How do I hide javascript code in a webpage?
(12 answers)
Closed 8 years ago.
I have a site whereby I can currently use firebug to look at all the angularjs files.
Is there anyway I can hide these so people cannot use tools to view them?
No you can't, the browsers need to see the code to execute it.
No. JavaScript files will always be accessible from client tools like IE dev tools or Chrome or just about any other browser's dev tools. You can take steps to make the js harder to read, but it will still be accissible
Yes, but the way is to stop people from accessing your site, which is probably worse. The way JavaScript works on most sites ( other than ones built on Node ) is that it is run in the browser and to do that it must be sent to the browser.
The reason it doesn't matter is that nobody wants to steal your code.
You need to remember that nothing you want to be kept secret should be in that JavaScript- run that on the server and pass the results out to front end - and for production you should probably be minimising your code anyway which provides a lot of obfuscation, but in general it is not worth worrying about.
You cant. But you can minify them using for example Google's closure compiler or Microsoft Ajax Minifier. Minifying not only makes your javascript less in size, but also gives an obfuscation to your code, so it is much more harder to understand

Live javascript debugging by recording function calls and parameters [duplicate]

This question already has answers here:
Can I override the Javascript Function object to log all function calls?
(6 answers)
Closed 5 years ago.
Is there a debugging system that allows me to record javascript function calls and their parameters as they occur? this would allow me to trace and debug applications in live/client situations without the performance hit due to manual logging.
Edit: I'm not talking about manually calling functions using a 'console' window and viewing the results, or manually adding 'trace' or 'log' commands into my javascript. I need it to work with any running javascript.
Can you override Function.prototype.call and retrieve arguments and arguments.callee?
This would have the effect of reporting on ALL functions and therefore being super verbose, but maybe you'd want to filter.
Then you have the question of how you want to report, perhaps with if (console) console.log
you could take a look at http://ajax.dynatrace.com/ajax/en/ - its IE only but pretty darn good, see this article by j. Resig : http://ejohn.org/blog/deep-tracing-of-internet-explorer/ > "..dynaTrace provides some information that I’ve never seen before – in any tool on any browser."
#Jenko if what you're looking for something similar to an IDE debugger, in that case Internet Explorer 8 and 9 have a built-in Developer Tools (press F12) and Chrome has Developer Tools as well. Both IE and Chrome allow you to set breakpoints in your code and step through it while it's running. Firefox has Firebug, which others have mentioned, and it too allows to set breakpoints and examine the execution of your code. Opera has Dragonfly (built-in) and has the same features as the other browsers.
As I was reading the answers and laughing at the duplicate answers of "You can use Firebug!" I realized.... you can use Firebug.
Seriously, it has a "profile" command that does exactly what you are asking for. Safari and Chrome have this feature so you can check in there as well. IE8/9 has a "profiler" tool which is similar (but I don't know if it can be called from JavaScript with console.profile())
This will give you accurate times since any code and logging you add would also afect the actual performance. And because this feature is in the top browsers, you get a reasonable amount of data.
I've found fireflow: https://addons.mozilla.org/en-us/firefox/addon/fireflow/
incredible helpful.
If you're talking about browser-side javascript dedub you can use Firebug, which is an excellent tool.
http://getfirebug.com/
Here you can find a step-by-step tutorial:
http://www.digitalmediaminute.com/screencast/firebug-js/
Yes. all major browsers have a debugger built-in (IE, Chrome, Safari), or available as a add-on (Firebug for Firefox).
Firebug is good for this. Or you can use Google Chrome's built-in debugger as well.
for Firefox Firebug
for IE deeloper tool
for chrome built-in debugger is nice to use
Arguably the best online Javascript Code Quality Controll is JSLint. It not only checks code for errors, it improves the coding style of programmes entirely<< this is the reason the author has made it in the first place. My 0,02 $
http://www.jslint.com/

Categories