Bare Docs
ReferenceBareModules

bare-realm

Realm support for Bare

Documented against v2.0.1
stable

bare-realm — Realm support for Bare. It is a native addon and requires Bare >=1.5.0.

npm i bare-realm

Usage

const Realm = require('bare-realm')

const realm = new Realm()

realm.evaluate('globalThis.foo = 42')
// 42

typeof globalThis.foo
// undefined

API

Realm

evaluate(code: string, options?: EvaluateOptions): any

Evaluate code in the realm's isolated global scope and return its completion value. The realm has its own globalThis, so assignments to globals made by code do not leak into the caller's environment.

Parameters

ParameterTypeDefaultDescription
codestring—The JavaScript source to evaluate.
options?EvaluateOptions—Options. filename is the script name used in stack traces (default '<anonymous>'); offset shifts the reported line numbers (default 0).

Returns any — The completion value of code.

Types

EvaluateOptions

interface EvaluateOptions {
  filename?: string
  offset?: number
}

See also

Last updated on

Was this helpful?

On this page