Hasty Briefsbeta

Bilingual

Micro QuickJS: a JavaScript engine for microcontroller

4 months ago
  • #JavaScript
  • #Memory Optimization
  • #Embedded Systems
  • MicroQuickJS (MQuickJS) is a JavaScript engine for embedded systems, requiring as low as 10 kB of RAM and about 100 kB of ROM.
  • It supports a subset of JavaScript close to ES5, with a stricter mode that disables error-prone or inefficient constructs.
  • MQuickJS uses a tracing garbage collector, stores strings in UTF-8, and avoids using the CPU stack for the VM.
  • The REPL is called 'mqjs' and supports various options including memory limits, interactive mode, and bytecode output.
  • Bytecode can be saved and run later, with format depending on CPU endianness and word length (32 or 64 bit).
  • MQuickJS enforces strict mode, disallowing constructs like 'with', global variables without 'var', and array holes.
  • Only global 'eval' is supported, and value boxing (e.g., 'new Number(1)') is not allowed.
  • Arrays in MQuickJS cannot have holes, and out-of-bound sets are errors unless at the end of the array.
  • The engine has minimal dependencies on the C library, using a provided memory buffer for allocations instead of 'malloc' or 'free'.
  • The C API is similar to QuickJS but requires handling of moving objects due to the compacting garbage collector.
  • MQuickJS includes its own tiny mathematical library and floating-point emulator for CPUs without FP support.
  • Strings are stored in UTF-8, maintaining compatibility with JavaScript while optimizing for memory usage.
  • The standard library resides in ROM, enabling fast instantiation with minimal RAM usage.
  • MQuickJS is released under the MIT license, with sources primarily copyright Fabrice Bellard and Charlie Gordon.