qjs - QuickJS Interpreter
Theqjs executable is the QuickJS JavaScript interpreter. It includes a simple standard library and an interactive REPL (Read-Eval-Print Loop).
Basic Usage
Running JavaScript Files
Interactive REPL
Evaluate Expressions
Command-Line Options
General Options
Display help information and list all available options
Evaluate the given expression and exit
Enter interactive REPL mode after running scripts or expressions
Instantiate the interpreter and quit immediately (useful for testing)
Module Loading
Load the file as an ES6 module (default=autodetect)
Load the file as a classic JavaScript script (default=autodetect)
By default,
qjs automatically detects whether to load a file as a module or script based on:- File extension (
.mjsfiles are modules) - Content analysis (presence of
import/exportstatements)
Include an additional file before running the main script
Make the This makes the modules accessible without imports:
std, os, and bjson modules available globally to the scriptMemory and Performance
Limit memory usage to N kilobytes (supports b, k, m, g suffixes)
Limit stack size to N kilobytes (supports b, k, m, g suffixes)
Debugging and Diagnostics
Enable memory allocation tracing for debugging memory issues
Dump memory usage statistics when the runtime exits
Set debug dump flags (hexadecimal value). See Dump Flags below.
Compilation Options
Compile the JavaScript file into a standalone executableMust be used with
-o to specify the output file.Specify the output filename for standalone executables
Select the executable to use as the base for standalone builds (defaults to current qjs)
Dump Flags
The--dump-flags option accepts a hexadecimal value combining these flags:
| Flag | Value | Description |
|---|---|---|
DUMP_BYTECODE_FINAL | 0x00001 | Dump pass 3 final bytecode |
DUMP_BYTECODE_PASS2 | 0x00002 | Dump pass 2 code |
DUMP_BYTECODE_PASS1 | 0x00004 | Dump pass 1 code |
DUMP_BYTECODE_HEX | 0x00010 | Dump bytecode in hexadecimal |
DUMP_BYTECODE_PC2LINE | 0x00020 | Dump line number table |
DUMP_BYTECODE_STACK | 0x00040 | Dump compute_stack_size |
DUMP_BYTECODE_STEP | 0x00080 | Dump executed bytecode |
DUMP_READ_OBJECT | 0x00100 | Dump marshalled objects at load time |
DUMP_FREE | 0x00200 | Dump every object free |
DUMP_GC | 0x00400 | Dump automatic GC occurrences |
DUMP_GC_FREE | 0x00800 | Dump objects freed by GC |
DUMP_MODULE_RESOLVE | 0x01000 | Dump module resolution steps |
DUMP_PROMISE | 0x02000 | Dump promise steps |
DUMP_LEAKS | 0x04000 | Dump leaked objects and strings in JS_FreeRuntime |
DUMP_ATOM_LEAKS | 0x08000 | Dump leaked atoms in JS_FreeRuntime |
DUMP_MEM | 0x10000 | Dump memory usage in JS_FreeRuntime |
DUMP_OBJECTS | 0x20000 | Dump objects in JS_FreeRuntime |
DUMP_ATOMS | 0x40000 | Dump atoms in JS_FreeRuntime |
DUMP_SHAPES | 0x80000 | Dump shapes in JS_FreeRuntime |
Example: Debugging Memory Leaks
Environment Variables
Set default dump flags via environment variable
Global Objects
Theqjs interpreter adds several global objects to the JavaScript environment:
execArgv
Array containing all command-line arguments:
argv0
The first command-line argument (typically the script name):
navigator.userAgent
Contains the QuickJS-ng version string:
gc()
Manually trigger garbage collection:
Examples
Run a Simple Script
Run with Standard Library
Debug Memory Usage
Interactive REPL with Preloaded Code
Compile to Standalone Executable
Exit Codes
0- Success1- Script execution error or compilation failure2- Runtime/context allocation failure
See Also
- qjsc - QuickJS compiler for generating C code
- Creating Standalone Executables - Guide to creating standalone binaries