Instead of having V8 compile JavaScript on the fly and then execute it, isn't it possible to just compile the JavaScript beforehand and then embed the machine code in the page instead of embedding JavaScript in the page?
In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it.
No, chrome does not support typescript natively - you compile it first to javascript, then you can run it in chrome (and any other browser). That is the main idea behind typescript - and I wouldn't expect browsers to support typescript directly in the near future (if ever).
It all starts with getting JavaScript code from the network. V8 parses the source code and turns it into an Abstract Syntax Tree (AST). Based on that AST, the Ignition interpreter can start to do its thing and produce bytecode. At that point, the engine starts running the code and collecting type feedback.
To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.
There are two main problems with shipping machine code on the web:
To address (1) you'd generally need to cross-compile machine code, which is more difficult and costly than compiling down from a high-level language. To address (2), you'd need to validate the machine code you receive, which is more difficult and costly than compiling a high-level language.
Machine code also tends to be much larger than high-level code, so there is a bandwidth issue as well.
Now, JavaScript may not be a particularly great choice of high-level language. But it is what we are stuck with as the language of the web.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With