"quickjs:engine" (namespace)
code: string,
options?: {
backtraceBarrier?: boolean;
filename?: string;
async?: boolean;
},
): any;
filename: string,
options?: {
with?: Record<string, string>;
},
): {
[key: string]: any;
};
filename: string,
options?: {
with?: Record<string, string>;
},
): string;
name: string,
obj: {
[key: string]: any;
},
): void;
filename: string,
line: number,
column: number,
) =>
| {
filename: string;
line: number;
column: number;
}
| null
| undefined;
): void;
value: any,
options?: {
showHidden?: boolean;
showClosure?: boolean;
rawDump?: boolean;
maxDepth?: number;
maxStringLength?: number;
maxItemCount?: number;
},
): string;
}
"quickjs:engine".isMainModule (exported function)
Return whether the provided resolved module path is set as the main module.
In other words, return what the value of import.meta.main would be within
the module.
The main module can be set via setMainModule.
"quickjs:engine".setMainModule (exported function)
Set the main module to the module with the provided resolved path.
This will affect the value of import.meta.main for modules loaded in the
future, but it will NOT retroactively change the value of
import.meta.main in existing already-loaded modules.
"quickjs:engine".evalScript (exported function)
Evaluate the string code as a script (global eval).
@paramcode — The code to evaluate.@paramoptions — An optional object containing the following optional properties:@propertybacktraceBarrier — Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.@propertyfilename — String (default = ""). The filename to associate with the code being executed. @propertyasync — Boolean (default = false). If true,awaitis accepted at the top level ofcodeand a Promise is returned.@returnsThe result of the evaluation. Ifasyncis true, a Promise.
code: string,
options?: {
backtraceBarrier?: boolean;
filename?: string;
async?: boolean;
},
): any;
"quickjs:engine".runScript (exported function)
Evaluate the file filename as a script (global eval).
@paramfilename — The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.@returnsThe result of the evaluation.
"quickjs:engine".importModule (exported function)
Evaluate the file filename as a module. Effectively a synchronous dynamic import().
@paramfilename — The relative or absolute path to the file to import. Relative paths are resolved relative to the file callingimportModule, orbasenameif present.@parambasename — If present andfilenameis a relative path,filenamewill be resolved relative to this basename.@paramoptions — Mirrors the second argument of dynamicimport(). Itswithproperty carries import attributes, eg{ with: { type: "json" } }.@returnsThe result of the evaluation (module namespace object).
filename: string,
options?: {
with?: Record<string, string>;
},
): {
[key: string]: any;
};
"quickjs:engine".resolveModule (exported function)
Return the resolved path to a module.
@paramfilename — The relative or absolute path to the file to import. Relative paths are resolved relative to the file callingimportModule, orbasenameif present.@parambasename — If present andfilenameis a relative path,filenamewill be resolved relative to this basename.@paramoptions — Mirrors the second argument of dynamicimport(). Itswithproperty carries import attributes, eg{ with: { type: "json" } }.@returnsThe resolved module path.
filename: string,
options?: {
with?: Record<string, string>;
},
): string;
"quickjs:engine".getFileNameFromStack (exported function)
Read the script of module filename from an active stack frame, then return it as a string.
If there isn't a valid filename for the specified stack frame, an error will be thrown.
@paramstackLevels — How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
"quickjs:engine".isModuleNamespace (exported function)
Returns true if target is a module namespace object.
"quickjs:engine".defineBuiltinModule (exported function)
Create a virtual built-in module whose exports consist of the own
enumerable properties of obj.
name: string,
obj: {
[key: string]: any;
},
): void;
"quickjs:engine".ModuleDelegate (exported ModuleDelegate)
An object which lets you configure the module loader (import/export/require). You can change these properties to add support for importing new filetypes.
"quickjs:engine".gc (exported function)
Manually invoke the cycle removal algorithm (garbage collector).
The cycle removal algorithm is automatically started when needed, so this function is useful in case of specific memory constraints or for testing.
"quickjs:engine".StackFrameMapper (exported type)
A callback that translates the location of a stack frame as an error's backtrace is built. See setStackFrameMapper for details.
line and column are 1-based, both for the values passed in and for the
values returned. To change the frame's location, return an object
containing all three of filename, line, and column. Return null or
undefined (or an object missing any field) to leave the location
unchanged.
filename: string,
line: number,
column: number,
) =>
| {
filename: string;
line: number;
column: number;
}
| null
| undefined;
"quickjs:engine".setStackFrameMapper (exported function)
Register a callback that translates the location of each stack frame as an
error's backtrace is built. This is the hook to use for source-map support:
the engine itself knows nothing about source maps, so the callback is where
you map a compiled (filename, line, column) back to its original source
location.
The callback is invoked once per frame while the backtrace string is being
assembled. The location it returns is used both in the human-readable
error.stack string AND in the fileName / lineNumber / columnNumber
own properties set on the error object, so they stay consistent.
line and column are 1-based, both for the values passed to the callback
and for the values it returns.
To take effect, the callback must return an object containing all three of
filename, line, and column. If it instead returns null or
undefined, returns an object missing any of those fields, returns a
non-object, or throws, the frame's original location is kept unchanged (a
thrown error is swallowed rather than propagated into backtrace
construction).
Only one mapper can be registered at a time; registering a new one replaces
the previous one. Pass null or undefined to unregister, restoring the
default behavior of reporting compiled locations.
While the mapper is running, it is temporarily disabled for any error thrown from within it, so an error thrown inside the mapper will not recurse infinitely; that nested error's backtrace simply reports its original (unmapped) locations.
@parammapper — The translation callback, ornull/undefinedto unregister.
): void;
"quickjs:engine".getStackFrameMapper (exported function)
Return the stack frame mapper currently registered via
setStackFrameMapper, or null if none is registered.
This is useful for composing mappers: read the existing one, then register a new mapper that adds your own behavior and delegates to the previous one.
const mapped = previous ? previous(filename, line, column) : null;
const location = mapped ?? { filename, line, column };
// ...apply your own additional adjustments to `location`...
return location;
});
"quickjs:engine".formatValue (exported function)
Format a value for debugging using QuickJS's built-in C-level printer.
This is a parallel formatter to inspect — it uses the engine's
internal pretty-printer (the same one used by JS_PrintValue in the C
API). It can show things JS cannot, like the closure variables of a
function (with showClosure: true), and runs without invoking any
user-defined toString / [Symbol.toPrimitive] / Proxy traps in
rawDump mode.
For typical script-level value formatting, inspect() is usually a
better choice — it is more configurable, handles cycles via path
strings, and supports custom formatters via inspect.custom. Reach for
formatValue when you need C-level introspection (closure access) or
a side-effect-free dump (rawDump).
@paramvalue — The value to format.@paramoptions — Optional formatting options.@propertyshowHidden — Boolean (default = false). Include non-enumerable properties.@propertyshowClosure — Boolean (default = false). For functions, include closure variables and home object.@propertyrawDump — Boolean (default = false). Skip toString/toPrimitive/Proxy traps; print raw structural info.@propertymaxDepth — Number (default = 2, hard cap = 8). Recursion limit. Set to 0 for the hard cap.@propertymaxStringLength — Number (default = 1000). Truncate strings longer than this. Set to 0 for unlimited.@propertymaxItemCount — Number (default = 100). Truncate arrays/objects with more entries than this. Set to 0 for unlimited.@returnsThe formatted string.
value: any,
options?: {
showHidden?: boolean;
showClosure?: boolean;
rawDump?: boolean;
maxDepth?: number;
maxStringLength?: number;
maxItemCount?: number;
},
): string;
"quickjs:engine".__printObject (exported function)
Format a value using QuickJS's built-in C-level printer and write the result directly to stdout (no trailing newline).
Equivalent in spirit to process.stdout.write(formatValue(value)),
but writes directly via the C API without building a JS string in
between. Provided for API parity with the underlying JS_PrintValue
C API.
The __ prefix marks this as a direct mirror of upstream QuickJS's
std.__printObject API (relocated to quickjs:engine in this fork
because the fork has been moving std helpers to engine).
@paramvalue — The value to print.