Recently, I saw several related questions in Zhihu:

  • How do I read ChakraCore’s code?

  • How should a novice read the Google V8 engine source code?

  • What kind of JavaScript engine is Kinoma XS6?


These questions are all about trying to learn the JavaScript engine implementation from reading the source code. For novices, however, starting directly from the source code of a complex implementation is inevitably a waste of time.

To learn JavaScript engine implementation, as with anything else, it’s best to do it step by step, laying the foundation first and then combining it with the mainstream implementation.

My recommended learning route is:

  • Copy: first find a relatively simple language of the simple interpreter implementation, it as a model, their own copy of an interpreter. In this process, you can learn the basic structure of the interpreter of the programming language, especially the division of its components and where each component fits in the workflow. After the whole process is strung together, the idea will be much clearer, and the next learning can be targeted.
  • Copying must be a specific, simple implementation of each part of an interpreter. However, what is the principle behind it, and whether there are other more advanced (or different alternatives) for the same component, needs to be further studied. At this point, you can read different books for each section, such as compilation principles, GC, object model, etc. Study principle, consolidate foundation, expand vision.
  • Specification: At this point you have enough foundation to start learning/implementing a real JavaScript engine. But before getting started, you should read up on the ECMAScript specification to understand exactly what the semantics of the JavaScript language are and solve the “what” question. If you find the new ECMAScript 2015 too complex, ECMAScript 5.1 is a good place to start. There’s an Annotated ECMAScript 5.1 specification that’s especially good to learn: Annotated ECMAScript 5.1. In addition, students who prefer to read Chinese documents can see the ES5-HTML5 Chinese Interest Group Wiki recommended by @Lu Kanghao in the comments section. That is his complaint.
  • Integration: combine the previous knowledge, in accordance with the specification of their own simple JavaScript engine; Or, at this point, you can read the implementation of a relatively simple JavaScript engine, but write it yourself once to get a better understanding.
  • Step up: At this stage, read the source code of the mainstream, high-performance JavaScript engine in the real world, and you can achieve the target. A quick read of the official documentation and a look at the code organization should give you a sense of the architecture of an implementation. Then take a look at the potentially important design points of the JavaScript engine implementation to see which implementations the implementation chooses for each section. In fact, like building blocks, you know exactly what options are available for each part, so you can read the code in detail and extract the information you want to know with less effort. Most of the time, the directory structure and source file name can roughly guess the information needed in which file, go in to confirm it.


I recommend this learning route, because I have gone through all the above stages, and it works. There are a lot of domestic counterparts engaged in JavaScript engine research and development, do not know what is your learning route?

In the Kinoma XS6 discussion, for example, it took me only a few minutes to see the question, start reading the source code, and write a complete answer. This answer contains the first design points THAT I look at when reading a JavaScript engine implementation. By grasping these points and reading the source code, I can quickly understand the overall picture of the implementation, its general design ideas and trade-off directions. In other words, I don’t need to learn a lot of new things from the details in order to get an overview of it, but I just need to verify what the implementation chooses among the possible implementations in the existing knowledge.

I also want to mention Constellation’s large LV5 JavaScript engine (Constellation/ IV · GitHub). Its evolution has seen Constellation grow, and it follows the “regulation-integration-progression” process described above – lv5 was initially implemented in a straightforward way while reading the ES5 specification. As the process worked its way through, he began learning advanced practices from mainstream open source JavaScript engines and gradually implemented them into LV5, gradually evolving it into a fairly solid, modern implementation.

I have also mentioned LV5 here: How to determine the direction of work for computer majors in junior college? – Answer by RednaxelaFX





In fact, I have been accumulating some words intermittently since 2012, hoping to write a book under a systematic knowledge system, so as to better spread these relevant knowledge to everyone. However, this project is still in the early stage, and no reminders will be accepted for the time being. Thank you…

While the book is still a long way off, I have tried to put together a few pieces of what I have accumulated: [link posts] an introduction to various JavaScript engines, and related material/blog collection posts for your reference and suggestions. This series of posts has not been updated for a long time…


In other words, all things are difficult before they are easy. According to the above route, it is necessary to find an original copy object to learn.

There are many things to choose from, but I would like to recommend the verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Verbal Oral I’ve posted an introductory post here: “Homemade Programming Languages” focuses on discussion posts

The Crowbar language, with its interpreter implementation, is what I would recommend as a starting copy.

To learn how it is designed and implemented, see next chapter