Skip to content

API reference / @jsprismarine/script-host / ScriptEngine

ScriptEngine ​

Classes ​

Interfaces ​

DebuggerOptions ​

Defined in: script-host/src/ScriptEngine.ts:120

How ScriptEngine.attachDebugger attaches a debugger.

Properties ​

context? ​

readonly optional context?: number

Defined in: script-host/src/ScriptEngine.ts:126

The context the debugger watches, DEFAULT_CONTEXT when absent. Only its scripts stop and poll; the other contexts' scripts run as if no debugger were attached, even in a file with a breakpoint. A stop's frames still include every context's, each queried in its own.

pollLines? ​

readonly optional pollLines?: number

Defined in: script-host/src/ScriptEngine.ts:132

How many lines a running script runs between DebuggerListener.poll calls, which let a debugger pause a script that never ends. A count of lines, not a time, so a script polls at the same lines every run. No polling when 0.


ScriptEngineOptions ​

Defined in: script-host/src/ScriptEngine.ts:106

How ScriptHostLibrary.createEngine sets up an engine.

Properties ​

bufferSize? ​

readonly optional bufferSize?: number

Defined in: script-host/src/ScriptEngine.ts:112

The transfer buffer's first size in bytes.

loadModule? ​

readonly optional loadModule?: ModuleLoader

Defined in: script-host/src/ScriptEngine.ts:114

Supplies the source of each module a script imports.

memoryLimit? ​

readonly optional memoryLimit?: number

Defined in: script-host/src/ScriptEngine.ts:108

The bytes the engine may allocate; going over stops the script. Unlimited when absent.

resolveModule? ​

readonly optional resolveModule?: ModuleResolver

Defined in: script-host/src/ScriptEngine.ts:116

Names the module each import reaches; defaultModuleName when absent.

stackSize? ​

readonly optional stackSize?: number

Defined in: script-host/src/ScriptEngine.ts:110

The native stack, in bytes, past which a script gets InternalError: stack overflow.


StepBudget ​

Defined in: script-host/src/ScriptEngine.ts:139

How many steps one entry from the host, and one tick, may take. Unlimited when absent.

Properties ​

perCallback? ​

readonly optional perCallback?: number

Defined in: script-host/src/ScriptEngine.ts:140

perTick? ​

readonly optional perTick?: number

Defined in: script-host/src/ScriptEngine.ts:141

Type Aliases ​

EngineStats ​

EngineStats = { -readonly [Key in keyof typeof Stat]: number }

Defined in: script-host/src/ScriptEngine.ts:40

An engine's counters. A step is one call of QuickJS's interrupt handler, which QuickJS makes once every 10,000 of its polls at backward jumps and calls, so the same script takes the same steps on every machine.


HostFunction ​

HostFunction = (...args) => ScriptValue

Defined in: script-host/src/ScriptEngine.ts:52

A function scripts call to reach the host. It runs synchronously and must not return a promise.

Parameters ​

args ​

...ScriptValue[]

Returns ​

ScriptValue


ModuleLoader ​

ModuleLoader = (name, context) => string | ScriptHandle | undefined

Defined in: script-host/src/ScriptEngine.ts:97

Returns a module for its normalized name: its source, or an object whose own enumerable properties become its exports. Undefined when there is none.

Parameters ​

name ​

string

The normalized module name.

context ​

ScriptContextId

The id of the context that imports it.

Returns ​

string | ScriptHandle | undefined


ModuleResolver ​

ModuleResolver = (base, specifier, context) => string

Defined in: script-host/src/ScriptEngine.ts:62

Names the module a specifier reaches from the module that imports it. An engine loads each name once per context, so two specifiers given the same name share one module.

Parameters ​

base ​

string

The name of the importing module.

specifier ​

string

The specifier as the import wrote it.

context ​

ScriptContextId

The id of the context that imports it.

Returns ​

string

The module's name, which the ModuleLoader is then asked for.


ScriptContextId ​

ScriptContextId = number

Defined in: script-host/src/ScriptEngine.ts:100

A context's id in its engine. The context an engine is created with is DEFAULT_CONTEXT.

Variables ​

ABI_VERSION ​

const ABI_VERSION: 4 = 4

Defined in: script-host/src/ScriptEngine.ts:13

The C interface version this binding speaks, JSH_ABI_VERSION in the header.


DEFAULT_BUFFER_SIZE ​

const DEFAULT_BUFFER_SIZE: number

Defined in: script-host/src/ScriptEngine.ts:43

The bytes a new engine's transfer buffer starts with. It grows when a value needs more.


DEFAULT_CONTEXT ​

const DEFAULT_CONTEXT: ScriptContextId = 0

Defined in: script-host/src/ScriptEngine.ts:103

The context an engine is created with.


DEFAULT_POLL_LINES ​

const DEFAULT_POLL_LINES: 10000 = 10_000

Defined in: script-host/src/ScriptEngine.ts:136

The lines between polls when DebuggerOptions.pollLines is absent.


DEFAULT_STACK_SIZE ​

const DEFAULT_STACK_SIZE: number

Defined in: script-host/src/ScriptEngine.ts:49

The native stack a new engine's scripts may use, in bytes. A host callback runs on the same stack, so this leaves room for Node.js's own frames under QuickJS's.


Stat ​

const Stat: object

Defined in: script-host/src/ScriptEngine.ts:22

The jsh_stat counters, by the field of EngineStats each fills.

Type Declaration ​

bytesFromHost ​

readonly bytesFromHost: 5 = 5

bytesToHost ​

readonly bytesToHost: 4 = 4

callbackSteps ​

readonly callbackSteps: 1 = 1

handles ​

readonly handles: 9 = 9

hostCalls ​

readonly hostCalls: 3 = 3

memoryLimitHits ​

readonly memoryLimitHits: 7 = 7

memoryUsed ​

readonly memoryUsed: 8 = 8

stackOverflows ​

readonly stackOverflows: 6 = 6

steps ​

readonly steps: 0 = 0

tickSteps ​

readonly tickSteps: 2 = 2

Functions ​

defaultModuleName() ​

defaultModuleName(base, specifier): string

Defined in: script-host/src/ScriptEngine.ts:71

QuickJS's own module names: a specifier that starts with . is joined to the importing module's folder, its leading ./ and ../ segments resolved, and any other is its own name.

Parameters ​

base ​

string

The name of the importing module.

specifier ​

string

The specifier as the import wrote it.

Returns ​

string

The module's name.