explaingit

bellard/mquickjs

5,812CAudience · developerComplexity · 4/5Setup · hard

TLDR

MicroQuickJS is a tiny JavaScript engine written in C for embedded devices, running on as little as 10KB of RAM with a 100KB ROM footprint, supporting a strict ES5 subset.

Mindmap

mindmap
  root((mquickjs))
    What it does
      Runs JS on embedded devices
      10KB RAM minimum
      Compiles to bytecode
    Tech Stack
      C language
      ARM processors
      ES5 JS subset
    Use Cases
      Microcontroller scripting
      Firmware with JS logic
      Bytecode file execution
    Audience
      Embedded developers
      C programmers
      Firmware engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Run JavaScript scripts on microcontrollers and embedded hardware with very limited memory.

USE CASE 2

Compile JavaScript programs to bytecode files for persistent storage and direct execution on embedded devices.

USE CASE 3

Embed a lightweight scripting engine into a C application running on an ARM processor.

Tech stack

CJavaScriptARM

Getting it running

Difficulty · hard Time to first run · 1h+

Requires a cross-compilation toolchain (e.g. ARM GCC) targeting the specific embedded architecture.

In plain English

MicroQuickJS (also written MQuickJS) is a JavaScript engine written in C for use on embedded systems, devices that have very limited memory. It can run JavaScript programs using as little as 10 kilobytes of RAM, and the whole engine fits in roughly 100 kilobytes of read-only memory when compiled for ARM processors. Its speed is described as comparable to QuickJS, the full-featured sibling engine created by the same author. MQuickJS supports a subset of JavaScript close to the ES5 standard rather than modern JavaScript in its entirety. It runs in what the README calls a stricter mode, where patterns that are common sources of bugs or that consume extra memory are simply not allowed. Arrays cannot have holes, global eval is the only form of eval supported, and value boxing such as new Number(1) is not available. Some ES5 extensions are included, such as typed arrays, the exponentiation operator, and a handful of additional string and math functions. The internal design differs from standard JavaScript engines to reduce memory use. The garbage collector is a tracing, compacting collector, meaning objects can move in memory during a collection pass. The virtual machine does not use the CPU stack, and strings are stored in UTF-8. Because objects can move, the C API requires specific reference-management calls to keep pointers valid across allocations. The standard library is compiled into C data structures that reside in ROM, so loading it at runtime requires almost no RAM. A command-line tool called mqjs provides an interactive read-eval-print loop and can also compile a script to bytecode saved to a file, which the engine can then load and run later without recompiling. This allows programs to be stored in persistent storage on embedded hardware and executed directly from there.

Copy-paste prompts

Prompt 1
How do I embed MQuickJS into a C project to run JavaScript on a microcontroller with only 64KB of RAM?
Prompt 2
Show me how to use the mqjs tool to compile a JavaScript file to bytecode and then load it from flash storage.
Prompt 3
What JavaScript patterns are forbidden in MQuickJS strict mode, and why do they consume extra memory?
Prompt 4
How do I correctly manage C pointers to MQuickJS objects when the compacting garbage collector can move them?
Open on GitHub → Explain another repo

← bellard on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.