hakojs
Version:
A secure, embeddable JavaScript engine that runs untrusted code inside WebAssembly sandboxes with fine-grained permissions and resource limits
82 lines • 3.12 kB
TypeScript
import { type ClassOptions, type HostCallbackFunction } from "../etc/types";
import type { VMContext } from "./context";
import { VMValue } from "./value";
/**
* Builder for creating C modules in the main context.
*/
export declare class CModuleBuilder implements Disposable {
private vmContext;
private modulePtr;
private exports;
private createdClasses;
private disposed;
private initializerHandler;
constructor(context: VMContext, name: string, initHandler: (initializer: CModuleInitializer) => void);
setPrivateValue(value: string | boolean | number | object): void;
getPrivateValue(): VMValue;
get context(): VMContext;
get pointer(): number;
get exportNames(): readonly string[];
get name(): string;
addExport(exportName: string): this;
addExports(exportNames: string[]): this;
/** @internal */
_registerClass(classObj: CModuleClass): void;
/** @internal */
_unregisterClass(classObj: CModuleClass): void;
private checkDisposed;
[Symbol.dispose](): void;
}
/**
* Initializer for C modules in the init handler context.
*/
export declare class CModuleInitializer implements Disposable {
private vmContext;
private modulePtr;
private parentBuilder;
private createdClasses;
private disposed;
constructor(context: VMContext, modulePtr: number);
/** @internal */
_setParentBuilder(builder: CModuleBuilder): void;
get context(): VMContext;
/** @internal */
get pointer(): number;
setPrivateValue(value: string | boolean | number | object): void;
getPrivateValue(): VMValue;
get name(): string;
setExport(exportName: string, value: unknown): void;
setExports(exports: Record<string, unknown>): void;
setFunction(exportName: string, fn: HostCallbackFunction<VMValue>): void;
/**
* Creates and exports a class with inheritance support.
* The constructor function receives the created instance, arguments, and new_target,
* and should initialize the instance (set properties, opaque data, etc.).
*/
setClass(name: string, constructorFn: (instance: VMValue, args: VMValue[], newTarget: VMValue) => void, options?: ClassOptions): void;
private checkDisposed;
/**
* Disposal is coordinated through CModuleBuilder to avoid double-disposal.
*/
[Symbol.dispose](): void;
}
export declare class CModuleClass implements Disposable {
private context;
private classId;
private proto;
private ctorFunction;
private disposed;
constructor(context: VMContext, name: string, constructorFn: (instance: VMValue, args: VMValue[], newTarget: VMValue) => void, options?: ClassOptions);
private setupClass;
private cleanup;
private checkDisposed;
get ctor(): VMValue;
get id(): number;
get prototype(): VMValue;
createInstance(opaque?: number): VMValue;
createInstanceWithPrototype(customProto: VMValue, opaque?: number): VMValue;
getOpaque(instance: VMValue): number;
isInstance(value: VMValue): boolean;
[Symbol.dispose](): void;
}
//# sourceMappingURL=cmodule.d.ts.map