gngrOrg / gngr

a cross-platform browser focussed on privacy.
https://gngr.info
285 stars 61 forks source link

Beautify JS when -debug is passed #63

Open hrj opened 9 years ago

hrj commented 9 years ago

It is easier to debug the browser when the JS is beautified. Stack traces are easier to analyse.

We can integrate a beautifier into the browser and perform the beautification automatically.

This beautifier works fine. It is written in Javascript, and I was able to run it with Nashorn easily with this script:

load('beautify.js');
var src = readFully($ARG[0]);
print(js_beautify(src));

Slight modification to beautify.js is required: the scope wrapping the code had to be commented out.

invoked using:

jjs -scripting beautify_test.js -- filename

The next steps would be:

hrj commented 9 years ago

I was able to invoke the script from the browser (with both Nashorn and Rhino). I even optimised it by compiling the JS to bytecode (though it still requires Rhino engine to execute).

However, it is a little slow (couple of seconds for large files such as jquery). A pure Java version would be very desireable.