This project spans Weeks 4-5 and implements a complete JavaScript runtime from parsing to execution.
Overview
Build a JavaScript engine capable of executing real-world programs. Implement the complete execution pipeline including parsing, bytecode compilation, VM execution, garbage collection, and event loop mechanics.Project requirements
Language features
Closures, prototypes, async/await
Runtime
Complete event loop implementation
Memory
Garbage collection with profiling
Integration
Connect to DOM for interactive apps
Core components
Parsing and AST
Build a JavaScript parser with:
- Lexical analysis and tokenization
- Recursive descent parser
- AST construction and validation
- Scope analysis and symbol resolution
Interpreter implementation
Create a bytecode interpreter featuring:
- Bytecode design and instruction set
- Stack-based VM execution
- Closure implementation with environment chains
- Prototype chain traversal
- Property lookup optimization (inline caches)
Memory management
Implement garbage collection with:
- Mark-and-sweep garbage collection
- Generational collection (young/old generations)
- Incremental and concurrent GC
- WeakMap and WeakSet implementation
- Memory profiling and leak detection
Optional: JIT compilation
For advanced implementation, add just-in-time compilation for hot code paths.
- Inline caching and polymorphic inline caching
- Type feedback and speculative optimization
- Deoptimization and bailout mechanisms
- Register allocation
Language features
Closures
Closures
Implement lexical scoping with environment chains. Closures must capture variables correctly and maintain references across execution contexts.
Prototypes
Prototypes
Implement prototype chain traversal for property lookup. Support constructor functions and prototype-based inheritance.
Async/await
Async/await
Implement async functions and await expressions. Properly handle promise chains and async control flow.
Event loop
Event loop
Correctly schedule microtasks and macrotasks. Implement Promise.then, setTimeout, and other async APIs.
Performance optimization
Hot path optimization
Profile execution and optimize frequently called code paths.
GC tuning
Minimize garbage collection pauses for smooth execution.
Inline caches
Cache property lookups for faster execution.
Memory profiling
Track allocations and identify memory leaks.
DOM integration
Connect your JavaScript engine to a DOM implementation for interactive applications.
- Query and manipulate DOM elements
- Add event listeners
- Modify styles and attributes
- Create and remove nodes dynamically
Deliverables
- Working JavaScript engine executing real programs
- Complete closure and prototype implementations
- Functional async/await with event loop
- Garbage collector with profiling metrics
- DOM bindings for interactive apps
- Performance analysis showing GC pauses and hot path optimization
- Test suite demonstrating language feature compliance
Success criteria
- Execute real-world JavaScript programs correctly
- Pass closure and scope test suites
- Handle async/await and promises properly
- Event loop maintains correct task ordering
- GC pauses remain under acceptable thresholds
- DOM integration enables interactive applications
- Inline caches improve property lookup performance