Skip to content

Latest commit

 

History

History
91 lines (53 loc) · 2.72 KB

quickjs.md

File metadata and controls

91 lines (53 loc) · 2.72 KB

quickjs-emscriptenGlobalsQuickJS

Class: QuickJS

QuickJS presents a Javascript interface to QuickJS, a Javascript interpreter that supports ES2019.

QuickJS is a singleton. Use the getQuickJS function to instantiate or retrieve an instance.

Use the QuickJS.createVm method to create a QuickJSVm.

Use the QuickJS.evalCode method as a shortcut evaluate Javascript safely and return the result as a native Javascript value.

Hierarchy

  • QuickJS

Index

Constructors

Methods

Constructors

constructor

+ new QuickJS(): QuickJS

Defined in quickjs.ts:992

Returns: QuickJS

Methods

createVm

createVm(): QuickJSVm

Defined in quickjs.ts:1039

Create a QuickJS VM.

Each VM is completely independent - you cannot share handles between VMs.

Returns: QuickJSVm


evalCode

evalCode(code: string, options: QuickJSEvalOptions): unknown

Defined in quickjs.ts:1080

One-off evaluate code without needing to create a VM.

To protect against infinite loops, use the shouldInterrupt option. The shouldInterruptAfterDeadline function will create a time-based deadline.

If you need more control over how the code executes, create a QuickJSVm instance and use its QuickJSVm.evalCode method.

Asynchronous callbacks may not run during the first call to evalCode. If you need to work with async code inside QuickJS, you should create a VM and use QuickJSVm.executePendingJobs.

throws If code throws during evaluation, the exception will be converted into a native Javascript value and thrown.

throws if options.shouldInterrupt interrupted execution, will throw a Error with name "InternalError" and message "interrupted".

Parameters:

Name Type Default
code string -
options QuickJSEvalOptions {}

Returns: unknown

The result is coerced to a native Javascript value using JSON serialization, so properties and values unsupported by JSON will be dropped.