Tuesday, January 29, 2019

How to Look Under the Hood at Javascript Code

I'm finally taking the long overdue step of learning Javascript. Part of the process of learning language is to figure out what it is doing at a far lower level then the luxurious heights at which we get to program. Plus it's just damn interesting.

In the Node (using v10.14.2) usage description there is an option --v8-options. Run Node with this to see a long list of options to give directly to V8, the Javascript engine running under the hood of Node.

There are a few options in here that will get us a look at the inner workings of the Javascript code we write.
--print-code
--print-bytecode
--print-code prints the code out in x64 assembly, I think.

--print-bytecode prints the intermediate bytecode.

For even a simple program like hello world there are a few pages of bootstrapping code that also gets printed out. Your functions are put under a label that looks like this: 
[generated bytecode for function: myadd]

Use that to your advantage to find your code.

Good Luck!

-Victor F.


No comments:

Post a Comment