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?
readonlyoptionalcontext?: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?
readonlyoptionalpollLines?: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?
readonlyoptionalbufferSize?:number
Defined in: script-host/src/ScriptEngine.ts:112
The transfer buffer's first size in bytes.
loadModule?
readonlyoptionalloadModule?:ModuleLoader
Defined in: script-host/src/ScriptEngine.ts:114
Supplies the source of each module a script imports.
memoryLimit?
readonlyoptionalmemoryLimit?:number
Defined in: script-host/src/ScriptEngine.ts:108
The bytes the engine may allocate; going over stops the script. Unlimited when absent.
resolveModule?
readonlyoptionalresolveModule?:ModuleResolver
Defined in: script-host/src/ScriptEngine.ts:116
Names the module each import reaches; defaultModuleName when absent.
stackSize?
readonlyoptionalstackSize?: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?
readonlyoptionalperCallback?:number
Defined in: script-host/src/ScriptEngine.ts:140
perTick?
readonlyoptionalperTick?: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
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
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
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
constABI_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
constDEFAULT_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
constDEFAULT_CONTEXT:ScriptContextId=0
Defined in: script-host/src/ScriptEngine.ts:103
The context an engine is created with.
DEFAULT_POLL_LINES
constDEFAULT_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
constDEFAULT_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
constStat:object
Defined in: script-host/src/ScriptEngine.ts:22
The jsh_stat counters, by the field of EngineStats each fills.
Type Declaration
bytesFromHost
readonlybytesFromHost:5=5
bytesToHost
readonlybytesToHost:4=4
callbackSteps
readonlycallbackSteps:1=1
handles
readonlyhandles:9=9
hostCalls
readonlyhostCalls:3=3
memoryLimitHits
readonlymemoryLimitHits:7=7
memoryUsed
readonlymemoryUsed:8=8
stackOverflows
readonlystackOverflows:6=6
steps
readonlysteps:0=0
tickSteps
readonlytickSteps: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.