bare-realm
Realm support for Bare
v2.1.1bare-realm — Realm support for Bare. It is a native addon and requires Bare >=1.37.0. Before v2.1.0, it required Bare >=1.5.0.
npm i bare-realmUsage
const Realm = require('bare-realm')
const realm = new Realm()
realm.evaluate('globalThis.foo = 42')
// 42
typeof globalThis.foo
// undefinedAPI
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
| Parameter | Type | Default | Description |
|---|---|---|---|
code | string | — | 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). Fixed in v2.1.1: the script name in stack traces ended in a NUL character, as in x.js\u0000:1:7. |
Returns any — The completion value of code.
Realm.globalOf(value: unknown): object | null
Get the global object of the realm that created value. Added in v2.1.0.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | unknown | — | The value to look up. |
Returns object | null — The globalThis of the realm that created value, or null if value is not an object or the engine cannot tell which realm created it.
Realm.isFrom(value: unknown, global: object): boolean
Check whether value was created by the realm whose global object is global. This is faster than comparing the result of Realm.globalOf(), as it can be called directly from optimized code. Added in v2.1.0.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | unknown | — | The value to check. |
global | object | — | The globalThis of the realm. |
Returns boolean — true if value is an object created by the realm of global, and false otherwise.
Types
EvaluateOptions
interface EvaluateOptions {
filename?: string
offset?: number
}See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.
Last updated on