- "quickjs:engine" (namespace)
- "quickjs:engine".isMainModule (exported function)
- "quickjs:engine".setMainModule (exported function)
- "quickjs:engine".evalScript (exported function)
- "quickjs:engine".runScript (exported function)
- "quickjs:engine".importModule (exported function)
- "quickjs:engine".resolveModule (exported function)
- "quickjs:engine".getFileNameFromStack (exported function)
- "quickjs:engine".isModuleNamespace (exported function)
- "quickjs:engine".defineBuiltinModule (exported function)
- "quickjs:engine".ModuleDelegate (exported ModuleDelegate)
- "quickjs:engine".gc (exported function)
declare module "quickjs:engine" {
export function isMainModule(resolvedFilepath: string): boolean;
export function setMainModule(resolvedFilepath: string): void;
export function evalScript(
code: string,
options?: {
backtraceBarrier?: boolean;
filename?: string;
async?: boolean;
},
): any;
export function runScript(filename: string): any;
export function importModule(
filename: string,
basename?: string,
): {
[key: string]: any;
};
export function resolveModule(filename: string, basename?: string): string;
export function getFileNameFromStack(stackLevels?: number): string;
export function isModuleNamespace(target: any): boolean;
export function defineBuiltinModule(
name: string,
obj: {
[key: string]: any;
},
): void;
export const ModuleDelegate: ModuleDelegate;
export function gc(): void;
}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.
export function isMainModule(resolvedFilepath: string): boolean;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.
export function setMainModule(resolvedFilepath: string): void;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.
export function evalScript(
code: string,
options?: {
backtraceBarrier?: boolean;
filename?: string;
async?: boolean;
},
): any;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.
export function runScript(filename: string): any;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.@returnsThe result of the evaluation (module namespace object).
export function importModule(
filename: string,
basename?: string,
): {
[key: string]: any;
};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.@returnsThe resolved module path.
export function resolveModule(filename: string, basename?: string): string;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.
export function getFileNameFromStack(stackLevels?: number): string;Returns true if target is a module namespace object.
export function isModuleNamespace(target: any): boolean;Create a virtual built-in module whose exports consist of the own
enumerable properties of obj.
export function defineBuiltinModule(
name: string,
obj: {
[key: string]: any;
},
): void;An object which lets you configure the module loader (import/export/require). You can change these properties to add support for importing new filetypes.
const ModuleDelegate: ModuleDelegate;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.
export function gc(): void;