Skip to main content
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

1

Parsing and AST

Build a JavaScript parser with:
  • Lexical analysis and tokenization
  • Recursive descent parser
  • AST construction and validation
  • Scope analysis and symbol resolution
The parser must handle modern JavaScript syntax and produce a valid AST.
2

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)
The VM must execute JavaScript semantics correctly with acceptable performance.
3

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
Profile GC pauses and optimize for minimal interruption.
4

Event loop mechanics

Build the event loop system:
  • Microtask queue (Promise.then)
  • Macrotask queue (setTimeout, I/O)
  • Animation frame callbacks
  • Idle callbacks and scheduling
  • Task prioritization
The event loop must correctly handle async operations and maintain task ordering.

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

Implement lexical scoping with environment chains. Closures must capture variables correctly and maintain references across execution contexts.
Implement prototype chain traversal for property lookup. Support constructor functions and prototype-based inheritance.
Implement async functions and await expressions. Properly handle promise chains and async control flow.
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.
Implement bindings that allow JavaScript code to:
  • 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

Build docs developers (and LLMs) love