Skip to content

Latest commit

 

History

History
1551 lines (901 loc) · 46.1 KB

File metadata and controls

1551 lines (901 loc) · 46.1 KB

quickjs-emscriptenquickjs-emscripten-coreReadme | Exports


quickjs-emscripten / quickjs-emscripten-core / QuickJSContext

Class: QuickJSContext

QuickJSContext wraps a QuickJS Javascript context (JSContext*) within a runtime. The contexts within the same runtime may exchange objects freely. You can think of separate runtimes like different domains in a browser, and the contexts within a runtime like the different windows open to the same domain. The runtime references the context's runtime.

This class's methods return QuickJSHandle, which wrap C pointers (JSValue*). It's the caller's responsibility to call .dispose() on any handles you create to free memory once you're done with the handle.

Use QuickJSRuntime#newContext or QuickJSWASMModule#newContext to create a new QuickJSContext.

Create QuickJS values inside the interpreter with methods like newNumber, newString, newArray, newObject, newFunction, and newPromise.

Call setProp or defineProp to customize objects. Use those methods with global to expose the values you create to the interior of the interpreter, so they can be used in evalCode.

Use evalCode or callFunction to execute Javascript inside the VM. If you're using asynchronous code inside the QuickJSContext, you may need to also call QuickJSRuntime#executePendingJobs. Executing code inside the runtime returns a result object representing successful execution or an error. You must dispose of any such results to avoid leaking memory inside the VM.

Implement memory and CPU constraints at the runtime level, using runtime. See QuickJSRuntime for more information.

Contents

Extends

Implements

Constructors

new QuickJSContext(args)

new QuickJSContext(args): QuickJSContext

Use QuickJSRuntime#newContext or QuickJSWASMModule#newContext to create a new QuickJSContext.

Parameters

args: Object

args.callbacks: QuickJSModuleCallbacks

args.ctx: Lifetime<JSContextPointer, never, never>

args.ffi: EitherFFI

args.module: EitherModule

args.ownedLifetimes?: Disposable[]

args.rt: Lifetime<JSRuntimePointer, never, never>

args.runtime: QuickJSRuntime

Returns

QuickJSContext

Overrides

quickjs-emscripten-core.UsingDisposable.constructor

Source

packages/quickjs-emscripten-core/src/context.ts:224

Properties

runtime

readonly runtime: QuickJSRuntime

The runtime that created this context.

Source

packages/quickjs-emscripten-core/src/context.ts:186

Accessors

alive

get alive(): boolean

Returns

boolean

true if the object is alive

false after the object has been disposed

Source

packages/quickjs-emscripten-core/src/context.ts:255


false

get false(): QuickJSHandle

false.

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:313


global

get global(): QuickJSHandle

global. A handle to the global object inside the interpreter. You can set properties to create global variables.

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:328


null

get null(): QuickJSHandle

null.

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:287


true

get true(): QuickJSHandle

true.

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:300


undefined

get undefined(): QuickJSHandle

undefined.

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:274

Methods

[dispose]()

[dispose](): void

Just calls the standard .dispose() method of this class.

Returns

void

Implementation of

quickjs-emscripten-core.Disposable.[dispose]

Inherited from

quickjs-emscripten-core.UsingDisposable.[dispose]

Source

packages/quickjs-emscripten-core/src/lifetime.ts:47


callFunction()

callFunction(func, thisVal, args)

callFunction(func, thisVal, args?): QuickJSContextResult<QuickJSHandle>

func.call(thisVal, ...args) or func.apply(thisVal, args). Call a JSValue as a function.

See unwrapResult, which will throw if the function returned an error, or return the result handle directly. If evaluation returned a handle containing a promise, use resolvePromise to convert it to a native promise and runtime.QuickJSRuntime#executePendingJobs to finish evaluating the promise.

Parameters

func: QuickJSHandle

thisVal: QuickJSHandle

args?: QuickJSHandle[]

Returns

QuickJSContextResult<QuickJSHandle>

A result. If the function threw synchronously, result.error be a handle to the exception. Otherwise result.value will be a handle to the value.

Example:

using parseIntHandle = context.getProp(global, "parseInt")
using stringHandle = context.newString("42")
using resultHandle = context.callFunction(parseIntHandle, context.undefined, stringHandle).unwrap()
console.log(context.dump(resultHandle)) // 42
Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.callFunction

Source

packages/quickjs-emscripten-core/src/context.ts:1059

callFunction(func, thisVal, args)

callFunction(func, thisVal, ...args): QuickJSContextResult<QuickJSHandle>

Parameters

func: QuickJSHandle

thisVal: QuickJSHandle

• ...args: QuickJSHandle[]

Returns

QuickJSContextResult<QuickJSHandle>

Implementation of

LowLevelJavascriptVm.callFunction

Source

packages/quickjs-emscripten-core/src/context.ts:1064


callMethod()

callMethod(thisHandle, key, args): QuickJSContextResult<QuickJSHandle>

handle[key](...args)

Call a method on a JSValue. This is a convenience method that calls getProp and callFunction.

Parameters

thisHandle: QuickJSHandle

key: QuickJSPropertyKey

args: QuickJSHandle[]= []

Returns

QuickJSContextResult<QuickJSHandle>

A result. If the function threw synchronously, result.error be a handle to the exception. Otherwise result.value will be a handle to the value.

Source

packages/quickjs-emscripten-core/src/context.ts:1113


decodeBinaryJSON()

decodeBinaryJSON(handle): QuickJSHandle

Outputs Handle of the given QuickJS Object in binary form

// imagine receiving data from another via IPC
socket.on("data", chunk => {
 context.newArrayBuffer(chunk)
   ?.consume(handle => context.decodeBinaryJSON(handle))
   ?.consume(handle => console.log(context.dump(handle)))
})

Parameters

handle: QuickJSHandle

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:1431


defineProp()

defineProp(handle, key, descriptor): void

Object.defineProperty(handle, key, descriptor).

Parameters

handle: QuickJSHandle

key: QuickJSPropertyKey

The property may be specified as a JSValue handle, or as a Javascript string or number (which will be converted automatically to a JSValue).

descriptor: VmPropertyDescriptor<QuickJSHandle>

Returns

void

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.defineProp

Source

packages/quickjs-emscripten-core/src/context.ts:1000


dispose()

dispose(): void

Dispose of this VM's underlying resources.

Returns

void

Implementation of

quickjs-emscripten-core.Disposable.dispose

Overrides

quickjs-emscripten-core.UsingDisposable.dispose

Throws

Calling this method without disposing of all created handles will result in an error.

Source

packages/quickjs-emscripten-core/src/context.ts:265


dump()

dump(handle): any

Dump a JSValue to Javascript in a best-effort fashion. If the value is a promise, dumps the promise's state. Returns handle.toString() if it cannot be serialized to JSON.

Parameters

handle: QuickJSHandle

Returns

any

Source

packages/quickjs-emscripten-core/src/context.ts:1234


encodeBinaryJSON()

encodeBinaryJSON(handle): QuickJSHandle

Outputs QuickJS Objects in binary form

WARNING: QuickJS's binary JSON doesn't have a standard so expect it to change between version

// imagine sending data to another via IPC
let dataLifetime = context.newString("This is an example")
 ?.consume(handle => context.encodeBinaryJSON(handle))
 ?.consume(handle => context.getArrayBuffer(handle))
socket.write(dataLifetime?.value)

Parameters

handle: QuickJSHandle

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:1414


eq()

eq(handle, other): boolean

handle === other - IsStrictlyEqual. See Equality comparisons and sameness.

Parameters

handle: QuickJSHandle

other: QuickJSHandle

Returns

boolean

Source

packages/quickjs-emscripten-core/src/context.ts:811


evalCode()

evalCode(code, filename, options?): QuickJSContextResult<QuickJSHandle>

Like eval(code).

Evaluates code, as though it's in a file named filename, with options options.

  • When options.type is "global", the code is evaluated in the global scope of the QuickJSContext, and the return value is the result of the last expression.
  • When options.type is "module", the code is evaluated is a module scope. It may use import and export if runtime.QuickJSRuntime#setModuleLoader was called. It may use top-level await if supported by the underlying QuickJS library. The return value is the module's exports, or a promise for the module's exports.
  • When options.type is unset, the code is evaluated as a module if it contains an import or export statement, otherwise it is evaluated in the global scope.

When working with async code, you many need to call runtime.QuickJSRuntime#executePendingJobs to execute callbacks pending after synchronous evaluation returns.

See unwrapResult, which will throw if the function returned an error, or return the result handle directly. If evaluation returned a handle containing a promise, use resolvePromise to convert it to a native promise and QuickJSRuntime#executePendingJobs to finish evaluating the promise.

Note: to protect against infinite loops, provide an interrupt handler to QuickJSRuntime#setInterruptHandler. You can use shouldInterruptAfterDeadline to create a time-based deadline.

Parameters

code: string

filename: string= "eval.js"

options?: number | ContextEvalOptions

If no options are passed, a heuristic will be used to detect if code is an ES module.

See EvalFlags for number semantics.

Returns

QuickJSContextResult<QuickJSHandle>

The last statement's value. If the code threw synchronously, result.error will be a handle to the exception. If execution was interrupted, the error will have name InternalError and message interrupted.

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.evalCode

Source

packages/quickjs-emscripten-core/src/context.ts:1156


fail()

protected fail(error): DisposableFail<QuickJSHandle>

Parameters

error: QuickJSHandle

Returns

DisposableFail<QuickJSHandle>

Source

packages/quickjs-emscripten-core/src/context.ts:1440


getArrayBuffer()

getArrayBuffer(handle): Lifetime<Uint8Array, never, never>

Coverts handle to a JavaScript ArrayBuffer

Parameters

handle: QuickJSHandle

Returns

Lifetime<Uint8Array, never, never>

Source

packages/quickjs-emscripten-core/src/context.ts:690


getBigInt()

getBigInt(handle): bigint

Converts handle to a Javascript bigint.

Parameters

handle: QuickJSHandle

Returns

bigint

Source

packages/quickjs-emscripten-core/src/context.ts:681


getIterator()

getIterator(iterableHandle): QuickJSContextResult<QuickJSIterator>

handle[Symbol.iterator](). See [QuickJSIterator]([object Object]). Returns a host iterator that wraps and proxies calls to a guest iterator handle. Each step of the iteration returns a result, either an error or a handle to the next value. Once the iterator is done, the handle is automatically disposed, and the iterator is considered done if the handle is disposed.

for (using entriesHandle of context.getIterator(mapHandle).unwrap()) {
  using keyHandle = context.getProp(entriesHandle, 0)
  using valueHandle = context.getProp(entriesHandle, 1)
  console.log(context.dump(keyHandle), '->', context.dump(valueHandle))
}

Parameters

iterableHandle: QuickJSHandle

Returns

QuickJSContextResult<QuickJSIterator>

Source

packages/quickjs-emscripten-core/src/context.ts:960


getLength()

getLength(handle): undefined | number

handle.length as a host number.

Example use:

const length = context.getLength(arrayHandle) ?? 0
for (let i = 0; i < length; i++) {
  using value = context.getProp(arrayHandle, i)
  console.log(`array[${i}] =`, context.dump(value))
}

Parameters

handle: QuickJSHandle

Returns

undefined | number

a number if the handle has a numeric length property, otherwise undefined.

Source

packages/quickjs-emscripten-core/src/context.ts:870


getNumber()

getNumber(handle): number

Converts handle into a Javascript number.

Parameters

handle: QuickJSHandle

Returns

number

NaN on error, otherwise a number.

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.getNumber

Source

packages/quickjs-emscripten-core/src/context.ts:652


getOwnPropertyNames()

getOwnPropertyNames(handle, options): QuickJSContextResult<DisposableArray<QuickJSHandle>>

Object.getOwnPropertyNames(handle). Similar to the standard semantics, but with extra, non-standard options for:

  • fetching array indexes as numbers (numbers: true)
  • including symbols (symbols: true)
  • only iterating over enumerable properties (onlyEnumerable: true)

The default behavior is to emulate the standard:

context.getOwnPropertyNames(handle, { strings: true, numbersAsStrings: true })

Note when passing an explicit options object, you must set at least one option, and strings are not included unless specified.

Example use:

for (using prop of context.getOwnPropertyNames(objectHandle).unwrap()) {
  using value = context.getProp(handle, prop)
  console.log(context.dump(prop), '->', context.dump(value))
}

Parameters

handle: QuickJSHandle

options: GetOwnPropertyNamesOptions= undefined

Returns

QuickJSContextResult<DisposableArray<QuickJSHandle>>

an an array of handles of the property names. The array itself is disposable for your convenience.

Throws

QuickJSEmptyGetOwnPropertyNames if no options are set.

Source

packages/quickjs-emscripten-core/src/context.ts:907


getPromiseState()

getPromiseState(handle): JSPromiseState

Get the current state of a QuickJS promise, see JSPromiseState for the possible states. This can be used to expect a promise to be fulfilled when combined with unwrapResult:

const promiseHandle = context.evalCode(`Promise.resolve(42)`);
const resultHandle = context.unwrapResult(
 context.getPromiseState(promiseHandle)
);
context.getNumber(resultHandle) === 42; // true
resultHandle.dispose();

Parameters

handle: QuickJSHandle

Returns

JSPromiseState

Source

packages/quickjs-emscripten-core/src/context.ts:715


getProp()

getProp(handle, key): QuickJSHandle

handle[key]. Get a property from a JSValue.

Parameters

handle: QuickJSHandle

key: QuickJSPropertyKey

The property may be specified as a JSValue handle, or as a Javascript string (which will be converted automatically).

Returns

QuickJSHandle

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.getProp

Source

packages/quickjs-emscripten-core/src/context.ts:840


getString()

getString(handle): string

Converts handle to a Javascript string.

Parameters

handle: QuickJSHandle

Returns

string

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.getString

Source

packages/quickjs-emscripten-core/src/context.ts:660


getSymbol()

getSymbol(handle): symbol

Converts handle into a Javascript symbol. If the symbol is in the global registry in the guest, it will be created with Symbol.for on the host.

Parameters

handle: QuickJSHandle

Returns

symbol

Source

packages/quickjs-emscripten-core/src/context.ts:669


getWellKnownSymbol()

getWellKnownSymbol(name): QuickJSHandle

Access a well-known symbol that is a property of the global Symbol object, like Symbol.iterator.

Parameters

name: string

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:388


newArray()

newArray(): QuickJSHandle

[]. Create a new QuickJS array.

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:430


newArrayBuffer()

newArrayBuffer(buffer): QuickJSHandle

Create a new QuickJS ArrayBuffer.

Parameters

buffer: ArrayBufferLike

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:438


newBigInt()

newBigInt(num): QuickJSHandle

Create a QuickJS bigint value.

Parameters

num: bigint

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:396


newError()

newError(error)

newError(error): QuickJSHandle

Parameters

error: Object

error.message: string

error.name: string

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:607

newError(message)

newError(message): QuickJSHandle

Parameters

message: string

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:608

newError(undefined)

newError(): QuickJSHandle

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:609


newFunction()

newFunction(name, fn): QuickJSHandle

Convert a Javascript function into a QuickJS function value. See VmFunctionImplementation for more details.

A VmFunctionImplementation should not free its arguments or its return value. A VmFunctionImplementation should also not retain any references to its return value.

The function argument handles are automatically disposed when the function returns. If you want to retain a handle beyond the end of the function, you can call Lifetime#dup to create a copy of the handle that you own and must dispose manually. For example, you need to use this API and do some extra book keeping to implement setInterval:

// This won't work because `callbackHandle` expires when the function returns,
// so when the interval fires, the callback handle is already disposed.
const WRONG_setIntervalHandle = context.newFunction("setInterval", (callbackHandle, delayHandle) => {
  const delayMs = context.getNumber(delayHandle)
  const intervalId = globalThis.setInterval(() => {
    // ERROR: callbackHandle is already disposed here.
    context.callFunction(callbackHandle)
  }, intervalId)
  return context.newNumber(intervalId)
})

// This works since we dup the callbackHandle.
// We just need to make sure we clean it up manually when the interval is cleared --
// so we need to keep track of those interval IDs, and make sure we clean all
// of them up when we dispose the owning context.

const setIntervalHandle = context.newFunction("setInterval", (callbackHandle, delayHandle) => {
  // Ensure the guest can't overload us by scheduling too many intervals.
  if (QuickJSInterval.INTERVALS.size > 100) {
    throw new Error(`Too many intervals scheduled already`)
  }

  const delayMs = context.getNumber(delayHandle)
  const longLivedCallbackHandle = callbackHandle.dup()
  const intervalId = globalThis.setInterval(() => {
    context.callFunction(longLivedCallbackHandle)
  }, intervalId)
  const disposable = new QuickJSInterval(longLivedCallbackHandle, context, intervalId)
  QuickJSInterval.INTERVALS.set(intervalId, disposable)
  return context.newNumber(intervalId)
})

const clearIntervalHandle = context.newFunction("clearInterval", (intervalIdHandle) => {
  const intervalId = context.getNumber(intervalIdHandle)
  const disposable = QuickJSInterval.INTERVALS.get(intervalId)
  disposable?.dispose()
})

class QuickJSInterval extends UsingDisposable {
  static INTERVALS = new Map<number, QuickJSInterval>()

  static disposeContext(context: QuickJSContext) {
    for (const interval of QuickJSInterval.INTERVALS.values()) {
      if (interval.context === context) {
        interval.dispose()
      }
    }
  }

  constructor(
    public fnHandle: QuickJSHandle,
    public context: QuickJSContext,
    public intervalId: number,
  ) {
    super()
  }

  dispose() {
    globalThis.clearInterval(this.intervalId)
    this.fnHandle.dispose()
    QuickJSInterval.INTERVALS.delete(this.fnHandle.value)
  }

  get alive() {
    return this.fnHandle.alive
  }
}

To implement an async function, create a promise with newPromise, then return the deferred promise handle from deferred.handle from your function implementation:

const deferred = vm.newPromise()
someNativeAsyncFunction().then(deferred.resolve)
return deferred.handle

Parameters

name: string

fn: VmFunctionImplementation<QuickJSHandle>

Returns

QuickJSHandle

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.newFunction

Source

packages/quickjs-emscripten-core/src/context.ts:601


newNumber()

newNumber(num): QuickJSHandle

Converts a Javascript number into a QuickJS value.

Parameters

num: number

Returns

QuickJSHandle

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.newNumber

Source

packages/quickjs-emscripten-core/src/context.ts:347


newObject()

newObject(prototype?): QuickJSHandle

{}. Create a new QuickJS object.

Parameters

prototype?: QuickJSHandle

Like Object.create.

Returns

QuickJSHandle

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.newObject

Source

packages/quickjs-emscripten-core/src/context.ts:416


newPromise()

newPromise(undefined)

newPromise(): QuickJSDeferredPromise

Create a new QuickJSDeferredPromise. Use deferred.resolve(handle) and deferred.reject(handle) to fulfill the promise handle available at deferred.handle. Note that you are responsible for calling deferred.dispose() to free the underlying resources; see the documentation on QuickJSDeferredPromise for details.

Returns

QuickJSDeferredPromise

Source

packages/quickjs-emscripten-core/src/context.ts:451

newPromise(promise)

newPromise(promise): QuickJSDeferredPromise

Create a new QuickJSDeferredPromise that resolves when the given native Promise<QuickJSHandle> resolves. Rejections will be coerced to a QuickJS error.

You can still resolve/reject the created promise "early" using its methods.

Parameters

promise: Promise<QuickJSHandle>

Returns

QuickJSDeferredPromise

Source

packages/quickjs-emscripten-core/src/context.ts:459

newPromise(newPromiseFn)

newPromise(newPromiseFn): QuickJSDeferredPromise

Construct a new native Promise<QuickJSHandle> , and then convert it into a QuickJSDeferredPromise.

You can still resolve/reject the created promise "early" using its methods.

Parameters

newPromiseFn: PromiseExecutor<QuickJSHandle, Error | QuickJSHandle>

Returns

QuickJSDeferredPromise

Source

packages/quickjs-emscripten-core/src/context.ts:466


newString()

newString(str): QuickJSHandle

Create a QuickJS string value.

Parameters

str: string

Returns

QuickJSHandle

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.newString

Source

packages/quickjs-emscripten-core/src/context.ts:354


newSymbolFor()

newSymbolFor(key): QuickJSHandle

Get a symbol from the global registry for the given key. All symbols created with the same key will be the same value.

Parameters

key: string | symbol

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:377


newUniqueSymbol()

newUniqueSymbol(description): QuickJSHandle

Create a QuickJS symbol value. No two symbols created with this function will be the same value.

Parameters

description: string | symbol

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/context.ts:365


resolvePromise()

resolvePromise(promiseLikeHandle): Promise<QuickJSContextResult<QuickJSHandle>>

Promise.resolve(value). Convert a handle containing a Promise-like value inside the VM into an actual promise on the host.

Parameters

promiseLikeHandle: QuickJSHandle

A handle to a Promise-like value with a .then(onSuccess, onError) method.

Returns

Promise<QuickJSContextResult<QuickJSHandle>>

Remarks

You may need to call runtime.QuickJSRuntime#executePendingJobs to ensure that the promise is resolved.

Source

packages/quickjs-emscripten-core/src/context.ts:754


sameValue()

sameValue(handle, other): boolean

Object.is(a, b) See Equality comparisons and sameness.

Parameters

handle: QuickJSHandle

other: QuickJSHandle

Returns

boolean

Source

packages/quickjs-emscripten-core/src/context.ts:819


sameValueZero()

sameValueZero(handle, other): boolean

SameValueZero comparison. See Equality comparisons and sameness.

Parameters

handle: QuickJSHandle

other: QuickJSHandle

Returns

boolean

Source

packages/quickjs-emscripten-core/src/context.ts:827


setProp()

setProp(handle, key, value): void

handle[key] = value. Set a property on a JSValue.

Parameters

handle: QuickJSHandle

key: QuickJSPropertyKey

The property may be specified as a JSValue handle, or as a Javascript string or number (which will be converted automatically to a JSValue).

value: QuickJSHandle

Returns

void

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.setProp

Remarks

Note that the QuickJS authors recommend using defineProp to define new properties.

Source

packages/quickjs-emscripten-core/src/context.ts:985


success()

protected success<S>(value): DisposableSuccess<S>

Type parameters

S

Parameters

value: S

Returns

DisposableSuccess<S>

Source

packages/quickjs-emscripten-core/src/context.ts:1436


throw()

throw(error): JSValuePointer

Throw an error in the VM, interrupted whatever current execution is in progress when execution resumes.

Parameters

error: Error | QuickJSHandle

Returns

JSValuePointer

Source

packages/quickjs-emscripten-core/src/context.ts:1193


typeof()

typeof(handle): string

typeof operator. Not standards compliant.

Parameters

handle: QuickJSHandle

Returns

string

Implementation of

quickjs-emscripten-core.LowLevelJavascriptVm.typeof

Remarks

Does not support BigInt values correctly.

Source

packages/quickjs-emscripten-core/src/context.ts:643


unwrapResult()

unwrapResult<T>(result): T

Unwrap a SuccessOrFail result such as a VmCallResult or a ExecutePendingJobsResult, where the fail branch contains a handle to a QuickJS error value. If the result is a success, returns the value. If the result is an error, converts the error to a native object and throws the error.

Type parameters

T

Parameters

result: SuccessOrFail<T, QuickJSHandle>

Returns

T

Source

packages/quickjs-emscripten-core/src/context.ts:1277


Generated using typedoc-plugin-markdown and TypeDoc