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)')); // 42new 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'sglobalThis._modules(Record<string, unknown>) — Reserved module map parameter for SES signature compatibility.options(CompartmentOptions) — Compartment name, source transforms, and underlyingGuestRealmOptions.
Properties
-
readonly globalThis: Record<PropertyKey, unknown>Live
Proxyview of the compartment's isolatedglobalThisobject. -
readonly name: stringDiagnostic name assigned to this compartment.
Methods
-
[dispose](): voidDisposable protocol hook for
usingdeclarations. -
dispose(): voidDisposes the underlying V8-wasm
GuestRealm. -
evaluate(source: string): unknownEvaluates JavaScript
sourceinside this compartment and marshals the result back.Returns: Marshaled completion value.
Throws:
TypeErrorifsourceis not a string.source(string) — JavaScript source string to evaluate.
Functions
harden
function harden<T>(value: T): TTransitively 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): voidSES 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 existingIsolateinstead of creating a new dedicatedIsolate.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— Controlsconsoletaming mode.domainTaming— Controls Node.jsdomaintaming mode.errorTaming— Controls stack/error exposure taming mode.errorTrapping— Controls uncaught error trapping behavior.evalTaming— Controls direct/indirectevaltaming mode.localeTaming— Controls locale-dependent method taming.overrideTaming— Controls override-mistake mitigation strictness.regExpTaming— Controls legacyRegExpstatic property taming.stackFiltering— Controls stack trace verbosity.