A toy browser and JavaScript engine implementation for learning how web browsers work.
golemjs/
├── internal/
│ ├── ast/ # Abstract Syntax Tree implementation
│ ├── lexer/ # JavaScript tokenizer
│ ├── parser/ # JavaScript parser
│ └── interpreter/ # JavaScript interpreter
└── tests/ # Test files
toybrowser/
├── internal/
│ ├── html/ # HTML parser and DOM implementation
│ ├── css/ # CSS parser and styling
│ ├── layout/ # Layout engine
│ └── render/ # Rendering engine
└── examples/ # Example applications
We've implemented a JavaScript engine that can:
- Parse JavaScript code into an AST
- Evaluate basic JavaScript expressions
- Handle variables and scope
- Support functions and function calls
- Process basic data types (numbers, strings, booleans)
- Handle control flow (if/else, while loops)
Key components:
- Lexer: Breaks JavaScript code into tokens
- Parser: Builds an Abstract Syntax Tree (AST)
- Interpreter: Evaluates the AST and produces results
- Environment: Manages variable scope and closures
We've implemented a basic HTML parser that:
- Parses HTML into a DOM tree
- Handles different node types (elements, text, comments)
- Supports attributes and nested elements
- Maintains parent-child relationships
The DOM implementation includes:
- Node Types: Element, Text, Comment, Doctype
- Node Properties: Tag name, attributes, children
- Tree Structure: Parent-child relationships
- Document Object: Root of the DOM tree
The project demonstrates how:
- JavaScript can interact with the DOM
- HTML is parsed into a tree structure
- JavaScript code is executed in the context of a web page
- The browser's rendering pipeline works
This project is designed to help understand:
- How JavaScript works at a fundamental level
- How the DOM represents web pages
- How JavaScript and the DOM interact
- How web browsers process and display content
- Implement CSS parsing and styling
- Add layout engine for positioning elements
- Implement rendering engine
- Add more JavaScript features (objects, arrays, etc.)
- Implement event handling
- Add network capabilities for loading resources
- Build the JavaScript engine:
cd golemjs
go test ./...- Build the toy browser:
cd toybrowser
go run examples/simple/main.goThis is a learning project. Feel free to:
- Fork the repository
- Add new features
- Fix bugs
- Improve documentation
- Share what you've learned
MIT License - feel free to use this code for learning and experimentation.