RunJS is a small JavaScript engine written in JavaScript, no external dependency.
It includes a set of classic JavaScript features in reference to the ECMA-262 Language Specification.
main.js
provides a run
function that accepts JavaScript source code as an argument.
You can import run
anywhere and execute it.
- Primitive data types and object
- Arithmetic and logical operations
- Conditional and iteration statements
- Function and scope
// Similar to console.log()
log(...args);
Implemented lexical analysis using regular expressions.
Implemented syntax analysis from scratch according to LL algorithm, and construct AST.
Implemented a set of runtime infrastructure:
- LanguageTypes
- NumberType (represented as Float64Array)
- StringType (represented as Uint16Array)
- BooleanType
- ObjectType
- UndefinedType
- NullType
- Realm
- The
log
function is registered here
- The
- SpecificationTypes
- CompletionRecord
- LexicalEnvironment
- Reference
- ExecutionContext
When a new instance of the JavaScript engine is created, Realm will be created, ExecutionContextStack will be initialized, AST will be traversed and interpreted.