How bellard/quickjs works
Main Components
• Core Engine: This includes files like qjs.c, quickjs.c, and quickjs-libc.c. They form the central engine responsible for parsing, bytecode generation (handled by qjsc.c), interpretation, and the runtime (including garbage collection, execution, etc.).
• Parser & Compiler: Highlight the modules that handle parsing JavaScript code and compiling it into bytecode (with qjsc.c acting as the compiler front-end).
• Runtime System: This includes components like the interpreter loop, runtime environment, and built-in objects/methods implemented inside the core files.
• Standard Library & Extensions:
– Built-in C library integration (quickjs-libc*).
– Extended functional modules such as the regex engine (libregexp.c/h) and Unicode support (libunicode.c/h).
– Utility routines (e.g., dtoa.c/dtoa.h for number conversions, cutils.c/h).
• Testing and Fuzzing: Represent the separate directories “tests” and “fuzz” as components that are used for validation and ensuring the robustness of the engine.
• Examples: The “examples” folder is meant to showcase how to integrate or use QuickJS (showing both pure JS and hybrid usage with C modules).
• Execution Flow: From the bytecode representation, show a directional flow to the “Interpreter/Runtime” component, which contains the execution loop, garbage collector, and environment management.
• Testing and Quality Assurance: Represent the “tests” and “fuzz” directories as side modules that feed test cases and fuzzing inputs back into the engine components to ensure integrity.
Architectural Patterns and Design Principles
• Modular Design: Emphasize how each distinct responsibility (parsing, execution, library support) has its own set of files and directories.
• Extensibility: Note the separation between the core engine and extensions (e.g., regex, Unicode) to allow replacing or updating these components independently.
• Separation of Concerns: The division between the JS execution engine and the host interfaces (like quickjs-libc) reinforces clear boundaries.
• Testing as a First-Class Citizen: Including robust testing and fuzzing indicates continuous integration which should be part of your overall architecture view.
Relevant Technologies and Libraries
• C as the primary implementation language.
• Use of Makefile for builds indicates that the build and configuration process is central and should be noted.
• The integration of Test262 tests suggests compliance with JavaScript standards.