Skip to Content
V8-wasm
API Reference

SES / Hardened JS

Hardened JavaScript Compartment, harden, and lockdown backed by disjoint V8-wasm realms

Import path: @browser-ports/v8-wasm/ses

@browser-ports/v8-wasm/ses — Hardened JavaScript (SES) Compartment, lockdown, and harden backed by real V8-wasm realms.

Because each Compartment executes in its own V8 Context with completely disjoint built-in intrinsics, cross-compartment primordial poisoning is structurally impossible without mutating host prototypes.

Compartment

Hardened JavaScript Compartment backed by a real V8-wasm GuestRealm.

Each compartment receives its own V8 Context with isolated global state and explicitly granted endowments.

Example:

import { Compartment, harden, lockdown } from '@browser-ports/v8-wasm/ses';

lockdown();
const api = harden({ version: 1, double: (n: number) => n * 2 });
using box = new Compartment({ api }, {}, { name: 'plugin-a' });
console.log(box.evaluate('api.double(21)')); // 42
new Compartment(endowments?: Record<string, unknown>, _modules?: Record<string, unknown>, options?: CompartmentOptions)

Creates a new Compartment with explicit global endowments and optional source transforms.

  • endowments (Record<string, unknown>) — Key-value map of globals injected into the compartment's globalThis.
  • _modules (Record<string, unknown>) — Reserved module map parameter for SES signature compatibility.
  • options (CompartmentOptions) — Compartment name, source transforms, and underlying GuestRealmOptions.

Properties

  • readonly globalThis: Record<PropertyKey, unknown>

    Live Proxy view of the compartment's isolated globalThis object.

  • readonly name: string

    Diagnostic name assigned to this compartment.

Methods

  • [dispose](): void

    Disposable protocol hook for using declarations.

  • dispose(): void

    Disposes the underlying V8-wasm GuestRealm.

  • evaluate(source: string): unknown

    Evaluates JavaScript source inside this compartment and marshals the result back.

    Returns: Marshaled completion value.

    Throws: TypeError if source is not a string.

    • source (string) — JavaScript source string to evaluate.

Functions

harden

function harden<T>(value: T): T

Transitively freezes value, its prototype chain, and all reachable own property values and accessor functions (Object.freeze graph traversal with cycle handling).

Mirrors Hardened JavaScript harden(value).

Returns: The same value reference after transitive freezing.

Parameters

  • value (T) — Object, function, or primitive to transitively freeze.

lockdown

function lockdown(_options?: LockdownOptions): void

SES lockdown() compatibility entrypoint.

Intentional no-op: each Compartment owns a separate V8-wasm Context with disjoint intrinsics, so cross-compartment primordial poisoning is structurally impossible.

Parameters

  • _options (LockdownOptions) — Optional SES lockdown options accepted for drop-in compatibility.

Interfaces & Types

CompartmentOptions

Configuration options for constructing a Hardened JS Compartment.

interface CompartmentOptions extends GuestRealmOptions {
  compileHook?: CompileHook;
  isolate?: Isolate;
  name?: string;
  transforms?: readonly (source: string) => string[];
}
  • compileHook — Optional source transform hook invoked before compilation.
  • isolate — Reuse an existing Isolate instead of creating a new dedicated Isolate.
  • name — Human-readable diagnostic name for the compartment (defaults to "<unknown>").
  • transforms — Ordered pipeline of source transformation functions applied before evaluation.

LockdownOptions

SES lockdown() configuration options accepted for API compatibility.

interface LockdownOptions {
  consoleTaming?: "safe" | "unsafe";
  domainTaming?: "safe" | "unsafe";
  errorTaming?: "safe" | "unsafe" | "unsafe-debug";
  errorTrapping?: "platform" | "exit" | "abort" | "report" | "none";
  evalTaming?: "safe-eval" | "unsafe-eval" | "no-eval";
  localeTaming?: "safe" | "unsafe";
  overrideTaming?: "moderate" | "min" | "severe";
  regExpTaming?: "safe" | "unsafe";
  stackFiltering?: "concise" | "verbose";
}
  • consoleTaming — Controls console taming mode.
  • domainTaming — Controls Node.js domain taming mode.
  • errorTaming — Controls stack/error exposure taming mode.
  • errorTrapping — Controls uncaught error trapping behavior.
  • evalTaming — Controls direct/indirect eval taming mode.
  • localeTaming — Controls locale-dependent method taming.
  • overrideTaming — Controls override-mistake mitigation strictness.
  • regExpTaming — Controls legacy RegExp static property taming.
  • stackFiltering — Controls stack trace verbosity.

On this page