Reputation: 207
I read article about how JavaScript Engine works, but there is thing that confusing me, it says the following:
Is last step true? Does above how JavaScript Engines work like "V8"?
Upvotes: 0
Views: 2166
Reputation: 40501
(V8 developer here.)
Yes, the JavaScript engines used in "modern" (since 2008) browsers have just-in-time compilers that compile JavaScript to machine code. That's probably what that article meant to say. If you want to distinguish the terms "assembly language" and "machine code", then the former would be the human-readable form (such as mov eax, ebx
, written by humans and produced by disassemblers) and the latter would be the binary-encoded form that the CPU understands (such as 0x89 0xD8
, produced by compilers/assemblers). I'd say that the term "assembly code" is sufficiently ambiguous that it could refer to either, or could imply that you don't want to distinguish.
I find the third step in your description more misleading: byte code is typically not optimized. The bytecode interpreter, if it exists, is usually the engine's first execution tier, and its purpose is to start execution as soon as possible, without first spending any time on optimizations. If a function runs hot enough, the engine will eventually decide to spend the time to optimize it to machine code (depending on the engine, possibly in a succession of several increasingly powerful but costly compilers). These later, optimizing tiers may or may not take the bytecode as input; alternatively they can parse the source again to build an AST (taking V8 as a specific example, it used to do the latter and is currently doing the former).
Side note: that article is pretty silly indeed. Example:
techniques like inlining (removing white space)
That's so wrong that it's outright funny :-D
Upvotes: 4