jseption 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/builtins/typedarray.d.ts +3 -1
- package/dist/builtins/typedarray.js +23 -5
- package/dist/builtins/typedarray.js.map +1 -1
- package/dist/embed.d.ts +5 -0
- package/dist/embed.js +33 -8
- package/dist/embed.js.map +1 -1
- package/dist/membrane.d.ts +6 -0
- package/dist/membrane.js +6 -2
- package/dist/membrane.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
package/dist/embed.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export interface ToGuestOptions {
|
|
|
6
6
|
/** deep-convert the arguments guest code passes to a wrapped host function
|
|
7
7
|
* into plain host values (default: pass the guest values through) */
|
|
8
8
|
convertArgs?: boolean;
|
|
9
|
+
/** hand the guest host `ArrayBuffer`s, typed arrays and `DataView`s over
|
|
10
|
+
* the host memory itself rather than copies (default: copies). A
|
|
11
|
+
* `SharedArrayBuffer`, and a view over one, always crosses live: that is
|
|
12
|
+
* what it is for (a WebAssembly memory another thread fills). */
|
|
13
|
+
liveBuffers?: boolean;
|
|
9
14
|
}
|
|
10
15
|
export declare function isGuestValue(v: unknown): boolean;
|
|
11
16
|
export declare function drainJobs(ctx: JSContext): void;
|
package/dist/embed.js
CHANGED
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
import { JS_IsException, JS_IsObject, JS_GetClassID, JS_GetAnyOpaque, JS_NewObject, JS_NewArrayFrom, JS_NewCFunction, JS_Call, JS_CallConstructor, JS_Throw, JS_GetException, JS_GetPropertyStr, JS_SetPropertyStr, JS_ToString, JS_NewErrorNative, JS_ExecutePendingJob, JS_IsJobPending, js_meta, } from "./quickjs.js";
|
|
11
11
|
import { JS_NewPromiseCapability } from "./builtins/promise.js";
|
|
12
12
|
import { JS_NewDate } from "./builtins/date.js";
|
|
13
|
-
import { JS_NewArrayBufferCopy } from "./builtins/typedarray.js";
|
|
13
|
+
import { JS_NewArrayBufferCopy, JS_NewArrayBufferFrom, isSharedArrayBuffer } from "./builtins/typedarray.js";
|
|
14
|
+
/* the host getters of a view's buffer, offset and length: a guest view is a
|
|
15
|
+
host view re-prototyped, so its own `buffer` is the guest's getter */
|
|
16
|
+
const TA_PROTO = Object.getPrototypeOf(Uint8Array.prototype);
|
|
17
|
+
const hostGetter = (proto, key) => Object.getOwnPropertyDescriptor(proto, key).get;
|
|
18
|
+
const viewBuffer = (v) => (v instanceof DataView ? hostGetter(DataView.prototype, 'buffer') : hostGetter(TA_PROTO, 'buffer')).call(v);
|
|
19
|
+
const viewOffset = (v) => (v instanceof DataView ? hostGetter(DataView.prototype, 'byteOffset') : hostGetter(TA_PROTO, 'byteOffset')).call(v);
|
|
20
|
+
const viewLength = (v) => (v instanceof DataView ? hostGetter(DataView.prototype, 'byteLength') : hostGetter(TA_PROTO, 'length')).call(v);
|
|
21
|
+
/* the host constructor of a view: DataView, or the typed array kind */
|
|
22
|
+
const viewCtor = (v) => globalThis[v[Symbol.toStringTag]];
|
|
14
23
|
const HOST_INTRINSIC_PROTOS = new Set([
|
|
15
24
|
Object.prototype, Array.prototype, Function.prototype, Error.prototype, Date.prototype, RegExp.prototype,
|
|
16
25
|
Map.prototype, Set.prototype, Promise.prototype, ArrayBuffer.prototype,
|
|
@@ -122,11 +131,20 @@ function toGuestRec(ctx, v, opts, seen) {
|
|
|
122
131
|
s.add(toGuestRec(ctx, val, opts, seen));
|
|
123
132
|
return s;
|
|
124
133
|
}
|
|
125
|
-
if (o instanceof ArrayBuffer)
|
|
134
|
+
if (o instanceof ArrayBuffer || isSharedArrayBuffer(o)) {
|
|
135
|
+
if (opts.liveBuffers || isSharedArrayBuffer(o))
|
|
136
|
+
return remember(JS_NewArrayBufferFrom(ctx, o));
|
|
126
137
|
return remember(JS_NewArrayBufferCopy(ctx, new Uint8Array(o)));
|
|
138
|
+
}
|
|
127
139
|
if (ArrayBuffer.isView(o)) {
|
|
128
|
-
const buf = JS_NewArrayBufferCopy(ctx, new Uint8Array(o.buffer, o.byteOffset, o.byteLength));
|
|
129
140
|
const name = o[Symbol.toStringTag]; /* "Uint8Array", "DataView", ... */
|
|
141
|
+
const buffer = viewBuffer(o);
|
|
142
|
+
if (opts.liveBuffers || isSharedArrayBuffer(buffer)) {
|
|
143
|
+
/* a view over the same host memory, through one guest buffer per host buffer */
|
|
144
|
+
const buf = toGuestRec(ctx, buffer, opts, seen);
|
|
145
|
+
return remember(construct(ctx, name, [buf, viewOffset(o), viewLength(o)]));
|
|
146
|
+
}
|
|
147
|
+
const buf = JS_NewArrayBufferCopy(ctx, new Uint8Array(buffer, viewOffset(o), o.byteLength));
|
|
130
148
|
return remember(construct(ctx, name, [buf]));
|
|
131
149
|
}
|
|
132
150
|
const proto = Object.getPrototypeOf(o);
|
|
@@ -260,13 +278,20 @@ function fromGuestRec(ctx, v, seen, hook) {
|
|
|
260
278
|
return s;
|
|
261
279
|
}
|
|
262
280
|
case 19 /* JSClassID.ARRAY_BUFFER */:
|
|
263
|
-
/* the guest object
|
|
264
|
-
return new Uint8Array(
|
|
281
|
+
/* the guest object holds the host ArrayBuffer: copy it */
|
|
282
|
+
return new Uint8Array(JS_GetAnyOpaque(v).buffer).slice().buffer;
|
|
283
|
+
case 20 /* JSClassID.SHARED_ARRAY_BUFFER */:
|
|
284
|
+
/* shared memory is shared: the host buffer itself */
|
|
285
|
+
return JS_GetAnyOpaque(v).buffer;
|
|
265
286
|
}
|
|
266
287
|
if (ArrayBuffer.isView(o)) {
|
|
267
|
-
/* guest typed arrays are host views re-prototyped:
|
|
268
|
-
|
|
269
|
-
|
|
288
|
+
/* guest typed arrays are host views re-prototyped: a view over shared memory
|
|
289
|
+
stays over it; anything else is copied with the host constructor */
|
|
290
|
+
const Ctor = viewCtor(o) ?? Uint8Array;
|
|
291
|
+
const buffer = viewBuffer(o);
|
|
292
|
+
if (isSharedArrayBuffer(buffer))
|
|
293
|
+
return new Ctor(buffer, viewOffset(o), viewLength(o));
|
|
294
|
+
return new Ctor(o);
|
|
270
295
|
}
|
|
271
296
|
if (Array.isArray(o)) {
|
|
272
297
|
const a = [];
|
package/dist/embed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA;;;;;;;;oEAQoE;AAEpE,OAAO,EAC0B,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAC1F,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EACrF,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EACrF,oBAAoB,EAAE,eAAe,EAAE,OAAO,GAC/C,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAWjE,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS;IAC5C,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS;IACxG,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,SAAS;IACtE,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC;CAC5C,CAAC,CAAC;AAEH;2DAC2D;AAC3D,MAAM,UAAU,YAAY,CAAC,CAAU;IACrC,IAAI,OAAO,CAAC,KAAK,UAAU,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,E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AAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/* Embedding helpers: moving values between the host and the guest.\n *\n * Guest values are host values, but the sandbox requires that nothing the\n * guest can reach has a host intrinsic in its prototype chain. A host\n * object therefore cannot be handed to the guest as is: `toGuest` copies\n * plain data into guest objects, wraps host functions in guest functions,\n * and bridges host promises to guest promises. `fromGuest` does the\n * reverse so the host gets ordinary host objects (and can call guest\n * functions / await guest promises). Primitives cross unchanged. */\n\nimport {\n JSContext, JSValue, JSClassID, JS_IsException, JS_IsObject, JS_GetClassID, JS_GetAnyOpaque,\n JS_NewObject, JS_NewArrayFrom, JS_NewCFunction, JS_Call, JS_CallConstructor, JS_Throw,\n JS_GetException, JS_GetPropertyStr, JS_SetPropertyStr, JS_ToString, JS_NewErrorNative,\n JS_ExecutePendingJob, JS_IsJobPending, js_meta,\n} from './quickjs.ts';\nimport { JSErrorEnum } from './values.ts';\nimport { JS_NewPromiseCapability } from './builtins/promise.ts';\nimport { JS_NewDate } from './builtins/date.ts';\nimport { JS_NewArrayBufferCopy } from './builtins/typedarray.ts';\n\nexport interface ToGuestOptions {\n /** convert a host value the default rules reject (class instances); return\n * undefined to fall through to the TypeError */\n custom?: (ctx: JSContext, value: object) => JSValue | undefined;\n /** deep-convert the arguments guest code passes to a wrapped host function\n * into plain host values (default: pass the guest values through) */\n convertArgs?: boolean;\n}\n\nconst HOST_INTRINSIC_PROTOS = new Set<object>([\n Object.prototype, Array.prototype, Function.prototype, Error.prototype, Date.prototype, RegExp.prototype,\n Map.prototype, Set.prototype, Promise.prototype, ArrayBuffer.prototype,\n Object.getPrototypeOf(Uint8Array.prototype),\n]);\n\n/* true if the value is already safe to hand to the guest: engine metadata or\n a prototype chain that never reaches a host intrinsic */\nexport function isGuestValue(v: unknown): boolean {\n if (typeof v === 'function' || (typeof v === 'object' && v !== null)) {\n if (js_meta.has(v as object)) return true;\n let p: object | null = v as object;\n while (p !== null) {\n if (HOST_INTRINSIC_PROTOS.has(p) || p === globalThis) return false;\n p = Object.getPrototypeOf(p);\n }\n return true;\n }\n return true;\n}\n\n/* run the guest job queue (promise reactions) until it is empty */\nexport function drainJobs(ctx: JSContext): void {\n const rt = ctx.rt;\n const pctx = { ctx: null as JSContext | null };\n while (JS_IsJobPending(rt)) JS_ExecutePendingJob(rt, pctx);\n}\n\nfunction guestCtor(ctx: JSContext, name: string): JSValue {\n return JS_GetPropertyStr(ctx, ctx.global_obj, name);\n}\n\nfunction throwGuestException(ctx: JSContext): never {\n throw guestErrorToHost(ctx, JS_GetException(ctx));\n}\n\n/* convert a guest exception value into a host Error for host callers */\nexport function guestErrorToHost(ctx: JSContext, exc: JSValue): Error {\n if (JS_IsObject(exc) && JS_GetClassID(exc) === JSClassID.ERROR) {\n const o = exc as any;\n const err = new Error(String(o.message ?? ''));\n err.name = String(o.name ?? 'Error');\n if (typeof o.stack === 'string') (err as any).guestStack = o.stack;\n return err;\n }\n const err = new Error(typeof exc === 'string' ? exc : String(JS_ToString(ctx, exc)));\n (err as any).guestValue = exc;\n return err;\n}\n\nconst ERROR_KINDS: Record<string, JSErrorEnum> = {\n EvalError: JSErrorEnum.EVAL_ERROR, RangeError: JSErrorEnum.RANGE_ERROR, ReferenceError: JSErrorEnum.REFERENCE_ERROR,\n SyntaxError: JSErrorEnum.SYNTAX_ERROR, TypeError: JSErrorEnum.TYPE_ERROR, URIError: JSErrorEnum.URI_ERROR,\n};\n\n/* host value -> guest value */\nexport function toGuest(ctx: JSContext, value: unknown, opts: ToGuestOptions = {}): JSValue {\n return toGuestRec(ctx, value, opts, new Map());\n}\n\nfunction toGuestRec(ctx: JSContext, v: unknown, opts: ToGuestOptions, seen: Map<object, JSValue>): JSValue {\n switch (typeof v) {\n case 'undefined': case 'boolean': case 'number': case 'string': case 'bigint': case 'symbol':\n return v as JSValue;\n case 'function':\n if (isGuestValue(v)) return v as JSValue;\n return hostFunction(ctx, v as (...args: any[]) => unknown, (v as Function).name, (v as Function).length, opts);\n }\n if (v === null) return null;\n const o = v as any;\n if (isGuestValue(o)) return o;\n const cached = seen.get(o);\n if (cached !== undefined) return cached;\n const remember = (g: JSValue): JSValue => { seen.set(o, g); return g; };\n\n if (typeof o.then === 'function') return remember(hostPromise(ctx, o, opts));\n if (Array.isArray(o)) {\n const arr = JS_NewArrayFrom(ctx, []) as any;\n seen.set(o, arr);\n for (let i = 0; i < o.length; i++) arr[i] = toGuestRec(ctx, o[i], opts, seen);\n return arr;\n }\n if (o instanceof Date) return remember(JS_NewDate(ctx, o.getTime()));\n if (o instanceof RegExp) return remember(construct(ctx, 'RegExp', [o.source, o.flags]));\n if (o instanceof Error) {\n const kind = ERROR_KINDS[o.name] ?? JSErrorEnum.PLAIN_ERROR;\n const err = JS_NewErrorNative(ctx, kind, String(o.message));\n return remember(err);\n }\n if (o instanceof Map) {\n const m = construct(ctx, 'Map', []) as any;\n seen.set(o, m);\n for (const [k, val] of o) m.set(toGuestRec(ctx, k, opts, seen), toGuestRec(ctx, val, opts, seen));\n return m;\n }\n if (o instanceof Set) {\n const s = construct(ctx, 'Set', []) as any;\n seen.set(o, s);\n for (const val of o) s.add(toGuestRec(ctx, val, opts, seen));\n return s;\n }\n if (o instanceof ArrayBuffer) return remember(JS_NewArrayBufferCopy(ctx, new Uint8Array(o)));\n if (ArrayBuffer.isView(o)) {\n const buf = JS_NewArrayBufferCopy(ctx, new Uint8Array(o.buffer, o.byteOffset, o.byteLength));\n const name = (o as any)[Symbol.toStringTag] as string; /* \"Uint8Array\", \"DataView\", ... */\n return remember(construct(ctx, name, [buf]));\n }\n const proto = Object.getPrototypeOf(o);\n if (proto === Object.prototype || proto === null) {\n const g = JS_NewObject(ctx) as any;\n seen.set(o, g);\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k)!;\n if (!d.enumerable) continue;\n g[k] = toGuestRec(ctx, o[k], opts, seen);\n }\n return g;\n }\n if (opts.custom) {\n const r = opts.custom(ctx, o);\n if (r !== undefined) return remember(r);\n }\n throw new TypeError(`toGuest: cannot pass a host ${proto?.constructor?.name ?? 'object'} to the guest; ` +\n 'pass plain data, functions, promises, or provide a custom converter');\n}\n\nfunction construct(ctx: JSContext, ctorName: string, args: unknown[]): JSValue {\n const r = JS_CallConstructor(ctx, guestCtor(ctx, ctorName), args as JSValue[]);\n if (JS_IsException(r)) throwGuestException(ctx);\n return r;\n}\n\n/* a guest function that calls the host function. Host exceptions become\n guest errors; host return values (including promises) are converted. */\nexport function hostFunction(ctx: JSContext, fn: (...args: any[]) => unknown, name = fn.name || 'hostFunction',\n length = fn.length, opts: ToGuestOptions = {}): JSValue {\n return JS_NewCFunction(ctx, (ctx2: JSContext, this_val: JSValue, argv: JSValue[]) => {\n try {\n const args = opts.convertArgs ? argv.map(a => fromGuest(ctx2, a)) : argv;\n const self = opts.convertArgs ? fromGuest(ctx2, this_val) : this_val;\n return toGuest(ctx2, fn.apply(self, args), opts);\n } catch (e) {\n return JS_Throw(ctx2, toGuest(ctx2, e, opts));\n }\n }, name, length);\n}\n\n/* a guest promise that settles when the host promise does; guest jobs are\n run after the settlement so `await` continuations execute promptly */\nexport function hostPromise(ctx: JSContext, p: PromiseLike<unknown>, opts: ToGuestOptions = {}): JSValue {\n return hostPromiseWith(ctx, p, v => toGuest(ctx, v, opts), e => toGuest(ctx, e, opts));\n}\n\n/* hostPromise with the conversions supplied by the caller (the membrane\n converts results live); `reject` converts a rejection reason or an\n exception thrown by `resolve` */\nexport function hostPromiseWith(ctx: JSContext, p: PromiseLike<unknown>, resolve: (v: unknown) => JSValue,\n reject: (e: unknown) => JSValue): JSValue {\n const funcs: [JSValue, JSValue] = [undefined, undefined];\n const promise = JS_NewPromiseCapability(ctx, funcs);\n if (JS_IsException(promise)) throwGuestException(ctx);\n const settle = (ok: boolean, v: unknown) => {\n let fn = ok ? funcs[0] : funcs[1];\n let g: JSValue;\n try { g = ok ? resolve(v) : reject(v); } catch (e) { fn = funcs[1]; g = reject(e); }\n JS_Call(ctx, fn, undefined, [g]);\n drainJobs(ctx);\n };\n p.then(v => settle(true, v), e => settle(false, e));\n return promise;\n}\n\n/* define a global variable in the guest */\nexport function expose(ctx: JSContext, name: string, value: unknown, opts: ToGuestOptions = {}): void {\n if (JS_SetPropertyStr(ctx, ctx.global_obj, name, toGuest(ctx, value, opts)) < 0) throwGuestException(ctx);\n}\n\n/* guest value -> plain host value: objects and arrays are copied, guest\n functions become host functions (that call into the guest), guest\n promises become host promises, errors become host Errors */\nexport function fromGuest(ctx: JSContext, value: JSValue): unknown {\n return fromGuestRec(ctx, value, new Map(), undefined);\n}\n\n/* returned by a fromGuestWith hook to let the default conversion handle a value */\nexport const FROM_GUEST_DEFAULT: unique symbol = Symbol('fromGuest default');\nexport type FromGuestHook = (v: JSValue) => unknown;\n\n/* fromGuest with a hook that is offered every value first, at every depth\n (the membrane unwraps its proxies and wraps guest functions this way) */\nexport function fromGuestWith(ctx: JSContext, value: JSValue, hook: FromGuestHook): unknown {\n return fromGuestRec(ctx, value, new Map(), hook);\n}\n\nfunction fromGuestRec(ctx: JSContext, v: JSValue, seen: Map<object, unknown>, hook: FromGuestHook | undefined): unknown {\n if (hook !== undefined) {\n const r = hook(v);\n if (r !== FROM_GUEST_DEFAULT) return r;\n }\n if (typeof v === 'function') {\n return (...args: unknown[]) => {\n const r = JS_Call(ctx, v, undefined, args.map(a => toGuest(ctx, a)));\n if (JS_IsException(r)) throwGuestException(ctx);\n return fromGuest(ctx, r);\n };\n }\n if (typeof v !== 'object' || v === null) return v;\n const cached = seen.get(v);\n if (cached !== undefined) return cached;\n const o = v as any;\n switch (JS_GetClassID(v)) {\n case JSClassID.PROMISE:\n return guestPromiseToHost(ctx, v);\n case JSClassID.DATE:\n return new Date(JS_GetAnyOpaque(v) as number);\n case JSClassID.ERROR:\n return guestErrorToHost(ctx, v);\n case JSClassID.REGEXP:\n return new RegExp(o.source, o.flags);\n case JSClassID.MAP: {\n const m = new Map(); seen.set(v, m);\n for (const [k, val] of Map.prototype.entries.call(o)) m.set(fromGuestRec(ctx, k, seen, hook), fromGuestRec(ctx, val, seen, hook));\n return m;\n }\n case JSClassID.SET: {\n const s = new Set(); seen.set(v, s);\n for (const val of Set.prototype.values.call(o)) s.add(fromGuestRec(ctx, val, seen, hook));\n return s;\n }\n case JSClassID.ARRAY_BUFFER:\n /* the guest object is the host ArrayBuffer re-prototyped: copy it */\n return new Uint8Array(o as ArrayBuffer).slice().buffer;\n }\n if (ArrayBuffer.isView(o)) {\n /* guest typed arrays are host views re-prototyped: copy with the host constructor */\n const Ctor = (globalThis as any)[(o as any)[Symbol.toStringTag]];\n return Ctor ? new Ctor(o as any) : new Uint8Array(o as any);\n }\n if (Array.isArray(o)) {\n const a: unknown[] = []; seen.set(v, a);\n for (let i = 0; i < o.length; i++) a[i] = fromGuestRec(ctx, o[i], seen, hook);\n return a;\n }\n const r: Record<PropertyKey, unknown> = {}; seen.set(v, r);\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k)!;\n if (!d.enumerable) continue;\n r[k] = fromGuestRec(ctx, o[k], seen, hook);\n }\n return r;\n}\n\n/* a host promise that settles when the guest promise does */\nexport function guestPromiseToHost(ctx: JSContext, promise: JSValue): Promise<unknown> {\n return guestPromiseToHostWith(ctx, promise, v => fromGuest(ctx, v), e => fromGuestRejection(ctx, e));\n}\n\n/* guestPromiseToHost with the conversions supplied by the caller */\nexport function guestPromiseToHostWith(ctx: JSContext, promise: JSValue, convert: (v: JSValue) => unknown,\n convertRejection: (e: JSValue) => unknown): Promise<unknown> {\n return new Promise((resolve, reject) => {\n const then = JS_GetPropertyStr(ctx, promise, 'then');\n const settle = (fn: (x: unknown) => void, conv: (v: JSValue) => unknown, v: JSValue): JSValue => {\n try { fn(conv(v)); } catch (e) { reject(e); }\n return undefined;\n };\n const onFul = JS_NewCFunction(ctx, (_c, _t, argv) => settle(resolve, convert, argv[0]), 'resolve', 1);\n const onRej = JS_NewCFunction(ctx, (_c, _t, argv) => settle(reject, convertRejection, argv[0]), 'reject', 1);\n const r = JS_Call(ctx, then, promise, [onFul, onRej]);\n if (JS_IsException(r)) reject(guestErrorToHost(ctx, JS_GetException(ctx)));\n drainJobs(ctx);\n });\n}\n\nfunction fromGuestRejection(ctx: JSContext, reason: JSValue): unknown {\n if (JS_IsObject(reason) && JS_GetClassID(reason) === JSClassID.ERROR) return guestErrorToHost(ctx, reason);\n return fromGuest(ctx, reason);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA;;;;;;;;oEAQoE;AAEpE,OAAO,EAC0B,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAC1F,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EACrF,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EACrF,oBAAoB,EAAE,eAAe,EAAE,OAAO,GAC/C,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAgB7G;wEACwE;AACxE,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAW,CAAC;AACvE,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAE,CAAC,GAAI,CAAC;AACrG,MAAM,UAAU,GAAG,CAAC,CAAkB,EAAmC,EAAE,CACzE,CAAC,CAAC,YAAY,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,Q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,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QACtG,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC7G,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACtD,IAAI,cAAc,CAAC,CAAC,CAAC;YAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC3E,SAAS,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAc,EAAE,MAAe;IACzD,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,4BAAoB;QAAE,OAAO,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3G,OAAO,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/* Embedding helpers: moving values between the host and the guest.\n *\n * Guest values are host values, but the sandbox requires that nothing the\n * guest can reach has a host intrinsic in its prototype chain. A host\n * object therefore cannot be handed to the guest as is: `toGuest` copies\n * plain data into guest objects, wraps host functions in guest functions,\n * and bridges host promises to guest promises. `fromGuest` does the\n * reverse so the host gets ordinary host objects (and can call guest\n * functions / await guest promises). Primitives cross unchanged. */\n\nimport {\n JSContext, JSValue, JSClassID, JS_IsException, JS_IsObject, JS_GetClassID, JS_GetAnyOpaque,\n JS_NewObject, JS_NewArrayFrom, JS_NewCFunction, JS_Call, JS_CallConstructor, JS_Throw,\n JS_GetException, JS_GetPropertyStr, JS_SetPropertyStr, JS_ToString, JS_NewErrorNative,\n JS_ExecutePendingJob, JS_IsJobPending, js_meta,\n} from './quickjs.ts';\nimport { JSErrorEnum } from './values.ts';\nimport { JS_NewPromiseCapability } from './builtins/promise.ts';\nimport { JS_NewDate } from './builtins/date.ts';\nimport { JS_NewArrayBufferCopy, JS_NewArrayBufferFrom, isSharedArrayBuffer } from './builtins/typedarray.ts';\n\nexport interface ToGuestOptions {\n /** convert a host value the default rules reject (class instances); return\n * undefined to fall through to the TypeError */\n custom?: (ctx: JSContext, value: object) => JSValue | undefined;\n /** deep-convert the arguments guest code passes to a wrapped host function\n * into plain host values (default: pass the guest values through) */\n convertArgs?: boolean;\n /** hand the guest host `ArrayBuffer`s, typed arrays and `DataView`s over\n * the host memory itself rather than copies (default: copies). A\n * `SharedArrayBuffer`, and a view over one, always crosses live: that is\n * what it is for (a WebAssembly memory another thread fills). */\n liveBuffers?: boolean;\n}\n\n/* the host getters of a view's buffer, offset and length: a guest view is a\n host view re-prototyped, so its own `buffer` is the guest's getter */\nconst TA_PROTO = Object.getPrototypeOf(Uint8Array.prototype) as object;\nconst hostGetter = (proto: object, key: string) => Object.getOwnPropertyDescriptor(proto, key)!.get!;\nconst viewBuffer = (v: ArrayBufferView): ArrayBuffer | SharedArrayBuffer =>\n (v instanceof DataView ? hostGetter(DataView.prototype, 'buffer') : hostGetter(TA_PROTO, 'buffer')).call(v);\nconst viewOffset = (v: ArrayBufferView): number =>\n (v instanceof DataView ? hostGetter(DataView.prototype, 'byteOffset') : hostGetter(TA_PROTO, 'byteOffset')).call(v);\nconst viewLength = (v: ArrayBufferView): number =>\n (v instanceof DataView ? hostGetter(DataView.prototype, 'byteLength') : hostGetter(TA_PROTO, 'length')).call(v);\n/* the host constructor of a view: DataView, or the typed array kind */\nconst viewCtor = (v: ArrayBufferView): any => (globalThis as any)[(v as any)[Symbol.toStringTag] as string];\n\nconst HOST_INTRINSIC_PROTOS = new Set<object>([\n Object.prototype, Array.prototype, Function.prototype, Error.prototype, Date.prototype, RegExp.prototype,\n Map.prototype, Set.prototype, Promise.prototype, ArrayBuffer.prototype,\n Object.getPrototypeOf(Uint8Array.prototype),\n]);\n\n/* true if the value is already safe to hand to the guest: engine metadata or\n a prototype chain that never reaches a host intrinsic */\nexport function isGuestValue(v: unknown): boolean {\n if (typeof v === 'function' || (typeof v === 'object' && v !== null)) {\n if (js_meta.has(v as object)) return true;\n let p: object | null = v as object;\n while (p !== null) {\n if (HOST_INTRINSIC_PROTOS.has(p) || p === globalThis) return false;\n p = Object.getPrototypeOf(p);\n }\n return true;\n }\n return true;\n}\n\n/* run the guest job queue (promise reactions) until it is empty */\nexport function drainJobs(ctx: JSContext): void {\n const rt = ctx.rt;\n const pctx = { ctx: null as JSContext | null };\n while (JS_IsJobPending(rt)) JS_ExecutePendingJob(rt, pctx);\n}\n\nfunction guestCtor(ctx: JSContext, name: string): JSValue {\n return JS_GetPropertyStr(ctx, ctx.global_obj, name);\n}\n\nfunction throwGuestException(ctx: JSContext): never {\n throw guestErrorToHost(ctx, JS_GetException(ctx));\n}\n\n/* convert a guest exception value into a host Error for host callers */\nexport function guestErrorToHost(ctx: JSContext, exc: JSValue): Error {\n if (JS_IsObject(exc) && JS_GetClassID(exc) === JSClassID.ERROR) {\n const o = exc as any;\n const err = new Error(String(o.message ?? ''));\n err.name = String(o.name ?? 'Error');\n if (typeof o.stack === 'string') (err as any).guestStack = o.stack;\n return err;\n }\n const err = new Error(typeof exc === 'string' ? exc : String(JS_ToString(ctx, exc)));\n (err as any).guestValue = exc;\n return err;\n}\n\nconst ERROR_KINDS: Record<string, JSErrorEnum> = {\n EvalError: JSErrorEnum.EVAL_ERROR, RangeError: JSErrorEnum.RANGE_ERROR, ReferenceError: JSErrorEnum.REFERENCE_ERROR,\n SyntaxError: JSErrorEnum.SYNTAX_ERROR, TypeError: JSErrorEnum.TYPE_ERROR, URIError: JSErrorEnum.URI_ERROR,\n};\n\n/* host value -> guest value */\nexport function toGuest(ctx: JSContext, value: unknown, opts: ToGuestOptions = {}): JSValue {\n return toGuestRec(ctx, value, opts, new Map());\n}\n\nfunction toGuestRec(ctx: JSContext, v: unknown, opts: ToGuestOptions, seen: Map<object, JSValue>): JSValue {\n switch (typeof v) {\n case 'undefined': case 'boolean': case 'number': case 'string': case 'bigint': case 'symbol':\n return v as JSValue;\n case 'function':\n if (isGuestValue(v)) return v as JSValue;\n return hostFunction(ctx, v as (...args: any[]) => unknown, (v as Function).name, (v as Function).length, opts);\n }\n if (v === null) return null;\n const o = v as any;\n if (isGuestValue(o)) return o;\n const cached = seen.get(o);\n if (cached !== undefined) return cached;\n const remember = (g: JSValue): JSValue => { seen.set(o, g); return g; };\n\n if (typeof o.then === 'function') return remember(hostPromise(ctx, o, opts));\n if (Array.isArray(o)) {\n const arr = JS_NewArrayFrom(ctx, []) as any;\n seen.set(o, arr);\n for (let i = 0; i < o.length; i++) arr[i] = toGuestRec(ctx, o[i], opts, seen);\n return arr;\n }\n if (o instanceof Date) return remember(JS_NewDate(ctx, o.getTime()));\n if (o instanceof RegExp) return remember(construct(ctx, 'RegExp', [o.source, o.flags]));\n if (o instanceof Error) {\n const kind = ERROR_KINDS[o.name] ?? JSErrorEnum.PLAIN_ERROR;\n const err = JS_NewErrorNative(ctx, kind, String(o.message));\n return remember(err);\n }\n if (o instanceof Map) {\n const m = construct(ctx, 'Map', []) as any;\n seen.set(o, m);\n for (const [k, val] of o) m.set(toGuestRec(ctx, k, opts, seen), toGuestRec(ctx, val, opts, seen));\n return m;\n }\n if (o instanceof Set) {\n const s = construct(ctx, 'Set', []) as any;\n seen.set(o, s);\n for (const val of o) s.add(toGuestRec(ctx, val, opts, seen));\n return s;\n }\n if (o instanceof ArrayBuffer || isSharedArrayBuffer(o)) {\n if (opts.liveBuffers || isSharedArrayBuffer(o)) return remember(JS_NewArrayBufferFrom(ctx, o));\n return remember(JS_NewArrayBufferCopy(ctx, new Uint8Array(o)));\n }\n if (ArrayBuffer.isView(o)) {\n const name = (o as any)[Symbol.toStringTag] as string; /* \"Uint8Array\", \"DataView\", ... */\n const buffer = viewBuffer(o);\n if (opts.liveBuffers || isSharedArrayBuffer(buffer)) {\n /* a view over the same host memory, through one guest buffer per host buffer */\n const buf = toGuestRec(ctx, buffer, opts, seen);\n return remember(construct(ctx, name, [buf, viewOffset(o), viewLength(o)]));\n }\n const buf = JS_NewArrayBufferCopy(ctx, new Uint8Array(buffer, viewOffset(o), o.byteLength));\n return remember(construct(ctx, name, [buf]));\n }\n const proto = Object.getPrototypeOf(o);\n if (proto === Object.prototype || proto === null) {\n const g = JS_NewObject(ctx) as any;\n seen.set(o, g);\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k)!;\n if (!d.enumerable) continue;\n g[k] = toGuestRec(ctx, o[k], opts, seen);\n }\n return g;\n }\n if (opts.custom) {\n const r = opts.custom(ctx, o);\n if (r !== undefined) return remember(r);\n }\n throw new TypeError(`toGuest: cannot pass a host ${proto?.constructor?.name ?? 'object'} to the guest; ` +\n 'pass plain data, functions, promises, or provide a custom converter');\n}\n\nfunction construct(ctx: JSContext, ctorName: string, args: unknown[]): JSValue {\n const r = JS_CallConstructor(ctx, guestCtor(ctx, ctorName), args as JSValue[]);\n if (JS_IsException(r)) throwGuestException(ctx);\n return r;\n}\n\n/* a guest function that calls the host function. Host exceptions become\n guest errors; host return values (including promises) are converted. */\nexport function hostFunction(ctx: JSContext, fn: (...args: any[]) => unknown, name = fn.name || 'hostFunction',\n length = fn.length, opts: ToGuestOptions = {}): JSValue {\n return JS_NewCFunction(ctx, (ctx2: JSContext, this_val: JSValue, argv: JSValue[]) => {\n try {\n const args = opts.convertArgs ? argv.map(a => fromGuest(ctx2, a)) : argv;\n const self = opts.convertArgs ? fromGuest(ctx2, this_val) : this_val;\n return toGuest(ctx2, fn.apply(self, args), opts);\n } catch (e) {\n return JS_Throw(ctx2, toGuest(ctx2, e, opts));\n }\n }, name, length);\n}\n\n/* a guest promise that settles when the host promise does; guest jobs are\n run after the settlement so `await` continuations execute promptly */\nexport function hostPromise(ctx: JSContext, p: PromiseLike<unknown>, opts: ToGuestOptions = {}): JSValue {\n return hostPromiseWith(ctx, p, v => toGuest(ctx, v, opts), e => toGuest(ctx, e, opts));\n}\n\n/* hostPromise with the conversions supplied by the caller (the membrane\n converts results live); `reject` converts a rejection reason or an\n exception thrown by `resolve` */\nexport function hostPromiseWith(ctx: JSContext, p: PromiseLike<unknown>, resolve: (v: unknown) => JSValue,\n reject: (e: unknown) => JSValue): JSValue {\n const funcs: [JSValue, JSValue] = [undefined, undefined];\n const promise = JS_NewPromiseCapability(ctx, funcs);\n if (JS_IsException(promise)) throwGuestException(ctx);\n const settle = (ok: boolean, v: unknown) => {\n let fn = ok ? funcs[0] : funcs[1];\n let g: JSValue;\n try { g = ok ? resolve(v) : reject(v); } catch (e) { fn = funcs[1]; g = reject(e); }\n JS_Call(ctx, fn, undefined, [g]);\n drainJobs(ctx);\n };\n p.then(v => settle(true, v), e => settle(false, e));\n return promise;\n}\n\n/* define a global variable in the guest */\nexport function expose(ctx: JSContext, name: string, value: unknown, opts: ToGuestOptions = {}): void {\n if (JS_SetPropertyStr(ctx, ctx.global_obj, name, toGuest(ctx, value, opts)) < 0) throwGuestException(ctx);\n}\n\n/* guest value -> plain host value: objects and arrays are copied, guest\n functions become host functions (that call into the guest), guest\n promises become host promises, errors become host Errors */\nexport function fromGuest(ctx: JSContext, value: JSValue): unknown {\n return fromGuestRec(ctx, value, new Map(), undefined);\n}\n\n/* returned by a fromGuestWith hook to let the default conversion handle a value */\nexport const FROM_GUEST_DEFAULT: unique symbol = Symbol('fromGuest default');\nexport type FromGuestHook = (v: JSValue) => unknown;\n\n/* fromGuest with a hook that is offered every value first, at every depth\n (the membrane unwraps its proxies and wraps guest functions this way) */\nexport function fromGuestWith(ctx: JSContext, value: JSValue, hook: FromGuestHook): unknown {\n return fromGuestRec(ctx, value, new Map(), hook);\n}\n\nfunction fromGuestRec(ctx: JSContext, v: JSValue, seen: Map<object, unknown>, hook: FromGuestHook | undefined): unknown {\n if (hook !== undefined) {\n const r = hook(v);\n if (r !== FROM_GUEST_DEFAULT) return r;\n }\n if (typeof v === 'function') {\n return (...args: unknown[]) => {\n const r = JS_Call(ctx, v, undefined, args.map(a => toGuest(ctx, a)));\n if (JS_IsException(r)) throwGuestException(ctx);\n return fromGuest(ctx, r);\n };\n }\n if (typeof v !== 'object' || v === null) return v;\n const cached = seen.get(v);\n if (cached !== undefined) return cached;\n const o = v as any;\n switch (JS_GetClassID(v)) {\n case JSClassID.PROMISE:\n return guestPromiseToHost(ctx, v);\n case JSClassID.DATE:\n return new Date(JS_GetAnyOpaque(v) as number);\n case JSClassID.ERROR:\n return guestErrorToHost(ctx, v);\n case JSClassID.REGEXP:\n return new RegExp(o.source, o.flags);\n case JSClassID.MAP: {\n const m = new Map(); seen.set(v, m);\n for (const [k, val] of Map.prototype.entries.call(o)) m.set(fromGuestRec(ctx, k, seen, hook), fromGuestRec(ctx, val, seen, hook));\n return m;\n }\n case JSClassID.SET: {\n const s = new Set(); seen.set(v, s);\n for (const val of Set.prototype.values.call(o)) s.add(fromGuestRec(ctx, val, seen, hook));\n return s;\n }\n case JSClassID.ARRAY_BUFFER:\n /* the guest object holds the host ArrayBuffer: copy it */\n return new Uint8Array((JS_GetAnyOpaque(v) as { buffer: ArrayBuffer }).buffer).slice().buffer;\n case JSClassID.SHARED_ARRAY_BUFFER:\n /* shared memory is shared: the host buffer itself */\n return (JS_GetAnyOpaque(v) as { buffer: SharedArrayBuffer }).buffer;\n }\n if (ArrayBuffer.isView(o)) {\n /* guest typed arrays are host views re-prototyped: a view over shared memory\n stays over it; anything else is copied with the host constructor */\n const Ctor = viewCtor(o) ?? Uint8Array;\n const buffer = viewBuffer(o);\n if (isSharedArrayBuffer(buffer)) return new Ctor(buffer, viewOffset(o), viewLength(o));\n return new Ctor(o as any);\n }\n if (Array.isArray(o)) {\n const a: unknown[] = []; seen.set(v, a);\n for (let i = 0; i < o.length; i++) a[i] = fromGuestRec(ctx, o[i], seen, hook);\n return a;\n }\n const r: Record<PropertyKey, unknown> = {}; seen.set(v, r);\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k)!;\n if (!d.enumerable) continue;\n r[k] = fromGuestRec(ctx, o[k], seen, hook);\n }\n return r;\n}\n\n/* a host promise that settles when the guest promise does */\nexport function guestPromiseToHost(ctx: JSContext, promise: JSValue): Promise<unknown> {\n return guestPromiseToHostWith(ctx, promise, v => fromGuest(ctx, v), e => fromGuestRejection(ctx, e));\n}\n\n/* guestPromiseToHost with the conversions supplied by the caller */\nexport function guestPromiseToHostWith(ctx: JSContext, promise: JSValue, convert: (v: JSValue) => unknown,\n convertRejection: (e: JSValue) => unknown): Promise<unknown> {\n return new Promise((resolve, reject) => {\n const then = JS_GetPropertyStr(ctx, promise, 'then');\n const settle = (fn: (x: unknown) => void, conv: (v: JSValue) => unknown, v: JSValue): JSValue => {\n try { fn(conv(v)); } catch (e) { reject(e); }\n return undefined;\n };\n const onFul = JS_NewCFunction(ctx, (_c, _t, argv) => settle(resolve, convert, argv[0]), 'resolve', 1);\n const onRej = JS_NewCFunction(ctx, (_c, _t, argv) => settle(reject, convertRejection, argv[0]), 'reject', 1);\n const r = JS_Call(ctx, then, promise, [onFul, onRej]);\n if (JS_IsException(r)) reject(guestErrorToHost(ctx, JS_GetException(ctx)));\n drainJobs(ctx);\n });\n}\n\nfunction fromGuestRejection(ctx: JSContext, reason: JSValue): unknown {\n if (JS_IsObject(reason) && JS_GetClassID(reason) === JSClassID.ERROR) return guestErrorToHost(ctx, reason);\n return fromGuest(ctx, reason);\n}\n"]}
|
package/dist/membrane.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ export interface MembranePolicy {
|
|
|
6
6
|
/** let the guest set, define and delete properties on host objects
|
|
7
7
|
* (default false: read-only) */
|
|
8
8
|
writable?: boolean;
|
|
9
|
+
/** hand the guest `ArrayBuffer`s, typed arrays and `DataView`s reached
|
|
10
|
+
* through the root over the host memory itself, not copies (default
|
|
11
|
+
* copies; a `SharedArrayBuffer` always crosses live). For a
|
|
12
|
+
* `WebAssembly.Memory` the guest drives: `memory.buffer` is then the
|
|
13
|
+
* module's memory, and what the guest writes the module reads. */
|
|
14
|
+
liveBuffers?: boolean;
|
|
9
15
|
}
|
|
10
16
|
/** the guest view of a host value: primitives as is, host objects and
|
|
11
17
|
* functions as live membrane proxies (see docs/MEMBRANE.md) */
|
package/dist/membrane.js
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
* See docs/MEMBRANE.md. */
|
|
40
40
|
import { JS_IsException, JS_GetException, JS_NewCFunction, JS_Call, JS_Throw, JS_NewArrayFrom, JS_NewErrorNative, JS_SetPropertyStr, JS_GetClassID, js_meta, } from "./quickjs.js";
|
|
41
41
|
import { toGuest, drainJobs, guestErrorToHost, hostPromiseWith, guestPromiseToHostWith, fromGuestWith, FROM_GUEST_DEFAULT, } from "./embed.js";
|
|
42
|
+
import { isSharedArrayBuffer } from "./builtins/typedarray.js";
|
|
42
43
|
import { JS_NewDate } from "./builtins/date.js";
|
|
43
44
|
/* ------------------------------------------------------------------ */
|
|
44
45
|
/* host intrinsics, collected once at module load */
|
|
@@ -171,10 +172,12 @@ class Membrane {
|
|
|
171
172
|
hasInstanceFns = new WeakMap();
|
|
172
173
|
guestSymbols = new WeakSet(); /* symbols the guest handed to the host */
|
|
173
174
|
writable;
|
|
175
|
+
liveBuffers;
|
|
174
176
|
allowFn;
|
|
175
177
|
constructor(ctx, policy) {
|
|
176
178
|
this.ctx = ctx;
|
|
177
179
|
this.writable = policy.writable === true;
|
|
180
|
+
this.liveBuffers = policy.liveBuffers === true;
|
|
178
181
|
this.allowFn = typeof policy.allow === 'function' ? policy.allow.bind(policy) : undefined;
|
|
179
182
|
}
|
|
180
183
|
/* ---------------- host -> guest ---------------- */
|
|
@@ -224,8 +227,9 @@ class Membrane {
|
|
|
224
227
|
return JS_NewDate(this.ctx, Date.prototype.getTime.call(o));
|
|
225
228
|
if (o instanceof Error)
|
|
226
229
|
return this.errorToGuest(o);
|
|
227
|
-
if (o instanceof RegExp || o instanceof ArrayBuffer || ArrayBuffer.isView(o))
|
|
228
|
-
return toGuest(this.ctx, o);
|
|
230
|
+
if (o instanceof RegExp || o instanceof ArrayBuffer || isSharedArrayBuffer(o) || ArrayBuffer.isView(o)) {
|
|
231
|
+
return toGuest(this.ctx, o, { liveBuffers: this.liveBuffers });
|
|
232
|
+
}
|
|
229
233
|
return this.wrap(o);
|
|
230
234
|
}
|
|
231
235
|
/* a well-known or registered symbol, or one the guest gave to the host */
|
package/dist/membrane.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membrane.js","sourceRoot":"","sources":["../src/membrane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAsC2B;AAE3B,OAAO,EAC0B,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAClG,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,OAAO,GAC9E,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,aAAa,EAAE,kBAAkB,GACjH,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAWhD,wEAAwE;AACxE,0EAA0E;AAE1E,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,eAAc,CAAC,CAAC,CAAC,WAAuB,CAAC;AAC1F,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAK,CAAC,CAAC,CAAC,WAAuB,CAAC;AACzF,MAAM,sBAAsB,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,SAAS,CAAC,MAAK,CAAC,CAAC,CAAC,WAAuB,CAAC;AAEpG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C,CAAC;AACjD,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,UAAU,CAAC,GAAc,EAAE,IAAY,EAAE,IAAa,EAAE,MAAuB;IAC7F,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACxD,MAAM,gBAAgB,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/* The membrane: live host objects for the guest.\n *\n * `toGuest`/`expose` (src/embed.ts) copy plain data and wrap functions; a\n * host class instance is refused. The membrane instead hands the guest a\n * live view of a host object graph: every host object or function the guest\n * reaches from a root crosses as a host `Proxy` whose handler lives here.\n * Each trap forwards the operation to the host object and converts what\n * comes back the same way, so nested objects, method results and\n * constructed instances are proxied lazily.\n *\n * A membrane proxy is not a guest Proxy (src/builtins/proxy.ts): the guest\n * Proxy calls guest handler code, while this handler is host code that must\n * never return a host value. The proxy's target is a private dummy (an empty\n * null-prototype object, or an empty function for callables) so the host\n * Proxy invariants never force a host value out, and the proxy has no engine\n * metadata, so the engine treats it as an ordinary object or host function\n * (`Reflect.get`, `Reflect.apply`, ... on it run the traps).\n *\n * The sandbox rules (always on; a policy can only narrow them):\n * 1. host intrinsics (Function and its async/generator variants, eval,\n * globalThis, Reflect, Proxy, Object, the Error constructors, the\n * intrinsic prototypes, the methods of Object, Reflect, Object.prototype\n * and Function.prototype) are never wrapped: they read as undefined, or\n * raise a guest TypeError where a value is required;\n * 2. constructor, prototype, __proto__, caller, callee, arguments and the\n * legacy __define/lookup{G,S}etter__ read as undefined; the prototype of\n * a proxy is the guest Object.prototype (Function.prototype for\n * callables); writes are refused unless the policy is writable, and\n * setPrototypeOf / preventExtensions are always refused;\n * 3. lookups stop at the host Object.prototype / Function.prototype and\n * continue on the guest's own, so call/apply/bind/toString/hasOwnProperty\n * are the guest intrinsics operating on the proxy, never host methods;\n * 4. getters run on the host, their results are converted like any value;\n * 5. only the well-known symbols iterator, asyncIterator, toStringTag and\n * toPrimitive (and hasInstance, answered by the membrane) are forwarded;\n * host symbols are neither listed nor returned;\n * 6. `policy.allow(target, key)` filters every key-based operation.\n *\n * See docs/MEMBRANE.md. */\n\nimport {\n JSContext, JSValue, JSClassID, JS_IsException, JS_GetException, JS_NewCFunction, JS_Call, JS_Throw,\n JS_NewArrayFrom, JS_NewErrorNative, JS_SetPropertyStr, JS_GetClassID, js_meta,\n} from './quickjs.ts';\nimport { JSErrorEnum } from './values.ts';\nimport {\n toGuest, drainJobs, guestErrorToHost, hostPromiseWith, guestPromiseToHostWith, fromGuestWith, FROM_GUEST_DEFAULT,\n} from './embed.ts';\nimport { JS_NewDate } from './builtins/date.ts';\n\nexport interface MembranePolicy {\n /** called for every key-based operation (read, `in`, own keys, descriptors,\n * writes) on the host object `target`; any result but `true` hides the key */\n allow?(target: object, key: PropertyKey): boolean;\n /** let the guest set, define and delete properties on host objects\n * (default false: read-only) */\n writable?: boolean;\n}\n\n/* ------------------------------------------------------------------ */\n/* host intrinsics, collected once at module load */\n\nconst AsyncFunction = Object.getPrototypeOf(async function () {}).constructor as Function;\nconst GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor as Function;\nconst AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor as Function;\n\n/* never wrapped, never returned to the guest */\nconst FORBIDDEN = new Set<unknown>();\n/* the host prototype walk stops here and continues on the guest prototype */\nconst WALK_STOP = new Set<unknown>([Object.prototype, Function.prototype, globalThis]);\n\nfunction forbid(v: unknown): void {\n if ((typeof v === 'object' && v !== null) || typeof v === 'function') FORBIDDEN.add(v);\n}\n\n/* the functions stored on an object (values and accessors) */\nfunction forbidMembers(o: object): void {\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k);\n if (!d) continue;\n if (typeof d.value === 'function') forbid(d.value);\n forbid(d.get);\n forbid(d.set);\n }\n}\n\n(function collectIntrinsics() {\n const g = globalThis as Record<string, unknown>;\n for (const v of [Function, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, eval, globalThis, Reflect, Proxy, Object]) forbid(v);\n /* the host error constructors expose stack-trace hooks (captureStackTrace,\n prepareStackTrace) that can hand out host frames */\n for (const name of ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',\n 'AggregateError', 'SuppressedError']) forbid(g[name]);\n /* the prototype of every standard constructor */\n const ctors = ['Object', 'Function', 'Array', 'String', 'Number', 'Boolean', 'Symbol', 'BigInt', 'Error', 'EvalError',\n 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', 'AggregateError', 'SuppressedError', 'Date',\n 'RegExp', 'Map', 'Set', 'WeakMap', 'WeakSet', 'WeakRef', 'FinalizationRegistry', 'Promise', 'ArrayBuffer',\n 'SharedArrayBuffer', 'DataView', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array',\n 'Int32Array', 'Uint32Array', 'Float16Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array',\n 'Iterator', 'AsyncIterator', 'DisposableStack', 'AsyncDisposableStack'];\n for (const name of ctors) {\n const c = g[name] as { prototype?: unknown } | undefined;\n if (typeof c === 'function') forbid(c.prototype);\n }\n const TypedArray = Object.getPrototypeOf(Int8Array) as Function;\n forbid(TypedArray); forbid(TypedArray.prototype);\n for (const F of [AsyncFunction, GeneratorFunction, AsyncGeneratorFunction]) {\n forbid(F.prototype); /* %AsyncFunction.prototype%, %GeneratorFunction.prototype%, ... */\n forbid((F.prototype as { prototype?: unknown }).prototype); /* %GeneratorPrototype%, %AsyncGeneratorPrototype% */\n }\n const arrayIter = Object.getPrototypeOf([][Symbol.iterator]());\n forbid(arrayIter);\n forbid(Object.getPrototypeOf(arrayIter)); /* %IteratorPrototype% */\n forbid(Object.getPrototypeOf(Object.getPrototypeOf((async function* () {})()))); /* %AsyncGeneratorPrototype% */\n forbid(Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf((async function* () {})())))); /* %AsyncIteratorPrototype% */\n forbid(Object.getPrototypeOf(new Map().entries()));\n forbid(Object.getPrototypeOf(new Set().values()));\n forbid(Object.getPrototypeOf(''[Symbol.iterator]()));\n forbid(Object.getPrototypeOf(/a/[Symbol.matchAll]('a')));\n /* %ThrowTypeError% and the methods that reach code, prototypes or properties\n of arbitrary objects */\n forbid(Reflect.getOwnPropertyDescriptor(Function.prototype, 'caller')?.get);\n for (const o of [Object, Reflect, Proxy, Object.prototype, Function.prototype]) forbidMembers(o);\n})();\n\nconst BLOCKED_KEYS = new Set<PropertyKey>([\n 'constructor', 'prototype', '__proto__', 'caller', 'callee', 'arguments',\n '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__',\n]);\n\nconst WELL_KNOWN_SYMBOLS = new Set<symbol>(\n Reflect.ownKeys(Symbol).map(k => (Symbol as unknown as Record<PropertyKey, unknown>)[k])\n .filter((v): v is symbol => typeof v === 'symbol'));\n/* the well-known symbols forwarded as keys */\nconst FORWARDED_SYMBOLS = new Set<symbol>([Symbol.iterator, Symbol.asyncIterator, Symbol.toStringTag, Symbol.toPrimitive]);\n\nconst ERROR_KINDS: [Function, JSErrorEnum][] = [\n [TypeError, JSErrorEnum.TYPE_ERROR], [RangeError, JSErrorEnum.RANGE_ERROR], [SyntaxError, JSErrorEnum.SYNTAX_ERROR],\n [ReferenceError, JSErrorEnum.REFERENCE_ERROR], [URIError, JSErrorEnum.URI_ERROR], [EvalError, JSErrorEnum.EVAL_ERROR],\n];\nconst STANDARD_ERROR_NAMES = new Set(['Error', 'TypeError', 'RangeError', 'SyntaxError', 'ReferenceError', 'URIError', 'EvalError']);\n\nfunction isHostConstructor(f: Function): boolean {\n try {\n Reflect.construct(String, [], f);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isObjectLike(v: unknown): v is object {\n return (typeof v === 'object' && v !== null) || typeof v === 'function';\n}\n\n/* ------------------------------------------------------------------ */\n/* registries shared by every membrane */\n\n/* membrane proxy -> the host object it stands for */\nconst proxyHost = new WeakMap<object, { host: object; membrane: Membrane }>();\n/* host callable made for a guest function -> that guest function */\nconst callableGuest = new WeakMap<Function, JSValue>();\n/* host Error thrown to host code for a guest exception -> the guest exception */\nconst thrownGuest = new WeakMap<object, JSValue>();\n/* one membrane per context and policy */\nconst membranes = new WeakMap<JSContext, { plain?: Membrane; byPolicy: WeakMap<MembranePolicy, Membrane> }>();\n/* membrane traps running now, per runtime. Compiled guest code pushes no interpreter frame, so\n when it calls into host code through a proxy, `rt.current_stack_frame` is null although guest\n code is on the stack; this count is what tells a guest callback the host calls back that it is\n not the outermost call */\nconst trapDepth = new WeakMap<object, number>();\n\nfunction membraneFor(ctx: JSContext, policy: MembranePolicy | undefined): Membrane {\n let e = membranes.get(ctx);\n if (!e) { e = { byPolicy: new WeakMap() }; membranes.set(ctx, e); }\n if (policy === undefined) return (e.plain ??= new Membrane(ctx, {}));\n let m = e.byPolicy.get(policy);\n if (!m) { m = new Membrane(ctx, policy); e.byPolicy.set(policy, m); }\n return m;\n}\n\n/* ------------------------------------------------------------------ */\n\nclass Membrane {\n private readonly proxies = new WeakMap<object, object>(); /* host object -> proxy */\n private readonly callables = new WeakMap<object, Function>(); /* guest function -> host callable */\n private readonly hasInstanceFns = new WeakMap<object, JSValue>();\n private readonly guestSymbols = new WeakSet<symbol>(); /* symbols the guest handed to the host */\n private readonly writable: boolean;\n private readonly allowFn: ((target: object, key: PropertyKey) => boolean) | undefined;\n\n constructor(readonly ctx: JSContext, policy: MembranePolicy) {\n this.writable = policy.writable === true;\n this.allowFn = typeof policy.allow === 'function' ? policy.allow.bind(policy) : undefined;\n }\n\n /* ---------------- host -> guest ---------------- */\n\n toGuest(v: unknown, seen?: Map<object, JSValue>): JSValue {\n switch (typeof v) {\n case 'undefined': case 'boolean': case 'number': case 'string': case 'bigint':\n return v as JSValue;\n case 'symbol':\n return this.symbolCrosses(v) ? v : undefined;\n }\n if (v === null) return null;\n const o = v as object;\n if (FORBIDDEN.has(o)) return undefined;\n const p = proxyHost.get(o);\n if (p !== undefined) return p.membrane.ctx === this.ctx ? o : this.toGuest(p.host, seen);\n if (typeof o === 'function') {\n const g = callableGuest.get(o);\n if (g !== undefined) return g;\n }\n if (this.isGuestOwned(o)) return o;\n if (o instanceof Promise) {\n return hostPromiseWith(this.ctx, o, r => this.toGuest(r), e => this.thrownToGuest(e));\n }\n if (Array.isArray(o)) {\n /* arrays are snapshots: a fresh guest array whose elements are converted */\n seen ??= new Map();\n const cached = seen.get(o);\n if (cached !== undefined) return cached;\n const arr = JS_NewArrayFrom(this.ctx, []) as unknown as JSValue[];\n seen.set(o, arr);\n const len = o.length;\n for (let i = 0; i < len; i++) arr[i] = this.toGuest(o[i], seen);\n return arr;\n }\n if (o instanceof Date) return JS_NewDate(this.ctx, Date.prototype.getTime.call(o));\n if (o instanceof Error) return this.errorToGuest(o);\n if (o instanceof RegExp || o instanceof ArrayBuffer || ArrayBuffer.isView(o)) return toGuest(this.ctx, o);\n return this.wrap(o);\n }\n\n /* a well-known or registered symbol, or one the guest gave to the host */\n private symbolCrosses(s: symbol): boolean {\n return WELL_KNOWN_SYMBOLS.has(s) || Symbol.keyFor(s) !== undefined || this.guestSymbols.has(s);\n }\n\n /* an engine object, or an object whose prototype chain reaches this\n context's guest Object.prototype / Function.prototype */\n private isGuestOwned(o: object): boolean {\n if (js_meta.has(o)) return true;\n try {\n return this.chainReachesGuest(o);\n } catch {\n return false; /* a host proxy whose getPrototypeOf throws */\n }\n }\n\n private chainReachesGuest(o: object): boolean {\n const ctx = this.ctx;\n const op = ctx.class_proto[JSClassID.OBJECT], fp = ctx.function_proto;\n let p: object | null = Reflect.getPrototypeOf(o);\n for (let i = 0; i < 64 && p !== null; i++) {\n if (p === op || p === fp) return true;\n if (WALK_STOP.has(p) || FORBIDDEN.has(p) || proxyHost.has(p)) return false;\n p = Reflect.getPrototypeOf(p);\n }\n return false;\n }\n\n private errorToGuest(e: Error): JSValue {\n let kind = JSErrorEnum.PLAIN_ERROR;\n for (const [C, k] of ERROR_KINDS) if (e instanceof C) { kind = k; break; }\n let message = '', name: unknown;\n try { const m = e.message; message = typeof m === 'string' ? m : ''; name = e.name; } catch { /* hostile getter */ }\n const g = JS_NewErrorNative(this.ctx, kind, message);\n if (kind === JSErrorEnum.PLAIN_ERROR && typeof name === 'string' && !STANDARD_ERROR_NAMES.has(name)) {\n Reflect.defineProperty(g, 'name', { value: name, writable: true, enumerable: false, configurable: true });\n }\n return g;\n }\n\n /* convert anything the host threw into a value to throw in the guest; the\n host exception object itself never crosses */\n thrownToGuest(e: unknown): JSValue {\n if (isObjectLike(e)) {\n const g = thrownGuest.get(e);\n if (g !== undefined) return g; /* a guest exception that passed through host code */\n if (proxyHost.has(e) || this.isGuestOwned(e)) return e as JSValue; /* thrown by guest code */\n if (e instanceof Error) return this.errorToGuest(e);\n let message = 'host exception';\n try {\n const m = (e as { message?: unknown }).message;\n if (typeof m === 'string') message = m;\n } catch { /* hostile getter */ }\n return JS_NewErrorNative(this.ctx, JSErrorEnum.PLAIN_ERROR, message);\n }\n if (typeof e === 'symbol') return this.symbolCrosses(e) ? e : undefined;\n return e as JSValue;\n }\n\n private guestTypeError(message: string): JSValue {\n return JS_NewErrorNative(this.ctx, JSErrorEnum.TYPE_ERROR, message);\n }\n\n /* the proxy for a host object (one per host object) */\n wrap(host: object): object {\n const cached = this.proxies.get(host);\n if (cached !== undefined) return cached;\n let target: object;\n const callable = typeof host === 'function';\n if (callable) {\n /* constructible or not like the host function; no own properties, so\n no target invariant constrains the traps */\n const f: Function = isHostConstructor(host as Function) ? Function.prototype.bind.call(function () {}, null) : () => {};\n Reflect.deleteProperty(f, 'name');\n Reflect.deleteProperty(f, 'length');\n Reflect.setPrototypeOf(f, null);\n target = f;\n } else {\n target = Object.create(null);\n }\n const proxy = new Proxy(target, this.handler(host, callable));\n this.proxies.set(host, proxy);\n proxyHost.set(proxy, { host, membrane: this });\n return proxy;\n }\n\n private keyAllowed(host: object, key: PropertyKey): boolean {\n if (typeof key === 'symbol') {\n if (WELL_KNOWN_SYMBOLS.has(key) && !FORWARDED_SYMBOLS.has(key)) return false;\n } else if (BLOCKED_KEYS.has(key)) {\n return false;\n }\n return this.allowFn === undefined || this.allowFn(host, key) === true;\n }\n\n /* listed by ownKeys: host symbols other than the forwarded well-known ones stay hidden */\n private keyListed(host: object, key: string | symbol): boolean {\n if (typeof key === 'symbol' && !FORWARDED_SYMBOLS.has(key) && !this.guestSymbols.has(key)) return false;\n return this.keyAllowed(host, key);\n }\n\n /* walk the host prototype chain up to (not including) the host\n Object.prototype / Function.prototype */\n private lookup(host: object, key: PropertyKey): PropertyDescriptor | undefined {\n let o: object | null = host;\n for (let depth = 0; o !== null && depth < 10000; depth++) {\n if (WALK_STOP.has(o)) return undefined;\n const d = Reflect.getOwnPropertyDescriptor(o, key);\n if (d !== undefined) return d;\n o = Reflect.getPrototypeOf(o);\n }\n return undefined;\n }\n\n private hostOf(v: unknown, fallback: object): object {\n return isObjectLike(v) ? proxyHost.get(v)?.host ?? fallback : fallback;\n }\n\n private hasInstance(host: object): JSValue {\n let f = this.hasInstanceFns.get(host);\n if (f === undefined) {\n f = JS_NewCFunction(this.ctx, (ctx, _this, argv) => {\n const v = argv[0];\n const h = isObjectLike(v) ? proxyHost.get(v)?.host : undefined;\n if (h === undefined) return false;\n try {\n return h instanceof (host as Function);\n } catch (e) {\n return JS_Throw(ctx, this.thrownToGuest(e));\n }\n }, '[Symbol.hasInstance]', 1);\n this.hasInstanceFns.set(host, f);\n }\n return f;\n }\n\n private handler(host: object, callable: boolean): ProxyHandler<object> {\n const m = this;\n const ctx = this.ctx;\n const guestProto = () => (callable ? ctx.function_proto : ctx.class_proto[JSClassID.OBJECT]) as object;\n /* every trap converts what the host throws, and counts as guest code on the stack while it\n runs host code */\n const rt = ctx.rt;\n const guard = <A extends unknown[], R>(fn: (...args: A) => R) => (...args: A): R => {\n trapDepth.set(rt, (trapDepth.get(rt) ?? 0) + 1);\n try {\n return fn(...args);\n } catch (e) {\n throw m.thrownToGuest(e);\n } finally {\n trapDepth.set(rt, trapDepth.get(rt)! - 1);\n }\n };\n const refuse = (what: string, key?: PropertyKey): never => {\n const k = key === undefined ? '' : ` '${typeof key === 'symbol' ? key.description ?? 'symbol' : key}'`;\n throw m.guestTypeError(`cannot ${what}${k}: host object is read-only`);\n };\n const proxyOf = () => m.proxies.get(host);\n\n return {\n get: guard((_t: object, key: PropertyKey, receiver: unknown) => {\n if (callable && key === Symbol.hasInstance) return m.hasInstance(host);\n if (!m.keyAllowed(host, key)) return undefined;\n const d = m.lookup(host, key);\n if (d === undefined) return Reflect.get(guestProto(), key, receiver);\n if ('value' in d) return m.toGuest(d.value);\n if (d.get === undefined) return undefined;\n return m.toGuest(Reflect.apply(d.get, m.hostOf(receiver, host), []));\n }),\n has: guard((_t: object, key: PropertyKey) => {\n if (callable && key === Symbol.hasInstance) return true;\n if (!m.keyAllowed(host, key)) return false;\n if (m.lookup(host, key) !== undefined) return true;\n return Reflect.has(guestProto(), key);\n }),\n ownKeys: guard((_t: object) => Reflect.ownKeys(host).filter(k => m.keyListed(host, k))),\n getOwnPropertyDescriptor: guard((_t: object, key: PropertyKey) => {\n if (!m.keyAllowed(host, key)) return undefined;\n const d = Reflect.getOwnPropertyDescriptor(host, key);\n if (d === undefined) return undefined;\n if ('value' in d) {\n return { value: m.toGuest(d.value), writable: m.writable && d.writable === true, enumerable: d.enumerable === true, configurable: true };\n }\n return {\n get: d.get === undefined ? undefined : m.toGuest(d.get) as (() => unknown) | undefined,\n set: d.set === undefined || !m.writable ? undefined : m.toGuest(d.set) as ((v: unknown) => void) | undefined,\n enumerable: d.enumerable === true, configurable: true,\n };\n }),\n set: guard((_t: object, key: PropertyKey, value: unknown, receiver: unknown) => {\n if (receiver !== proxyOf() && !(isObjectLike(receiver) && proxyHost.has(receiver))) {\n /* a guest object inheriting from the proxy: the property lands on it */\n return Reflect.defineProperty(receiver as object, key, { value, writable: true, enumerable: true, configurable: true });\n }\n if (!m.writable || !m.keyAllowed(host, key)) refuse('assign to property', key);\n return Reflect.set(host, key, m.fromGuest(value as JSValue), m.hostOf(receiver, host));\n }),\n defineProperty: guard((_t: object, key: PropertyKey, desc: PropertyDescriptor) => {\n if (!m.writable || !m.keyAllowed(host, key)) refuse('define property', key);\n if (desc.configurable === false) throw m.guestTypeError('cannot define a non-configurable property on a host object');\n const hd: PropertyDescriptor = {};\n if ('value' in desc) hd.value = m.fromGuest(desc.value as JSValue);\n if ('get' in desc) hd.get = m.fromGuest(desc.get as JSValue) as () => unknown;\n if ('set' in desc) hd.set = m.fromGuest(desc.set as JSValue) as (v: unknown) => void;\n if ('writable' in desc) hd.writable = desc.writable;\n if ('enumerable' in desc) hd.enumerable = desc.enumerable;\n hd.configurable = true;\n return Reflect.defineProperty(host, key, hd);\n }),\n deleteProperty: guard((_t: object, key: PropertyKey) => {\n if (!m.writable || !m.keyAllowed(host, key)) refuse('delete property', key);\n return Reflect.deleteProperty(host, key);\n }),\n getPrototypeOf: () => guestProto(),\n setPrototypeOf: () => false,\n isExtensible: () => true,\n preventExtensions: () => false,\n apply: guard((_t: object, thisArg: unknown, args: unknown[]) => {\n const hostThis = thisArg === ctx.global_obj ? undefined : m.fromGuest(thisArg as JSValue);\n const hostArgs = args.map(a => m.fromGuest(a as JSValue));\n return m.toGuest(Reflect.apply(host as Function, hostThis, hostArgs));\n }),\n construct: guard((_t: object, args: unknown[], newTarget: unknown) => {\n if (newTarget !== proxyOf()) throw m.guestTypeError('host constructors cannot be subclassed from the guest');\n const r = m.toGuest(Reflect.construct(host as Function, args.map(a => m.fromGuest(a as JSValue))));\n if (!isObjectLike(r)) throw m.guestTypeError('host constructor returned a value that cannot cross the membrane');\n return r;\n }),\n };\n }\n\n /* ---------------- guest -> host ---------------- */\n\n fromGuest(v: JSValue): unknown {\n return fromGuestWith(this.ctx, v, x => this.fromGuestHook(x));\n }\n\n private fromGuestHook(v: JSValue): unknown {\n if (typeof v === 'symbol') {\n if (!WELL_KNOWN_SYMBOLS.has(v) && Symbol.keyFor(v) === undefined) this.guestSymbols.add(v);\n return v;\n }\n if (!isObjectLike(v)) return FROM_GUEST_DEFAULT;\n const p = proxyHost.get(v);\n if (p !== undefined) return p.host;\n if (typeof v === 'function') return this.callable(v);\n if (JS_GetClassID(v) === JSClassID.PROMISE) {\n return guestPromiseToHostWith(this.ctx, v, x => this.fromGuest(x),\n e => (JS_GetClassID(e) === JSClassID.ERROR ? guestErrorToHost(this.ctx, e) : this.fromGuest(e)));\n }\n return FROM_GUEST_DEFAULT;\n }\n\n /* a host function that runs the guest function (one per guest function) */\n private callable(fn: JSValue): Function {\n const cached = this.callables.get(fn as object);\n if (cached !== undefined) return cached;\n const m = this;\n const ctx = this.ctx;\n const c = {\n guestCallback(this: unknown, ...args: unknown[]): unknown {\n /* outermost: no guest code below this call, neither an interpreter frame nor a membrane\n trap (the way compiled guest code reaches host code) */\n const outermost = ctx.rt.current_stack_frame === null && (trapDepth.get(ctx.rt) ?? 0) === 0;\n try {\n const r = JS_Call(ctx, fn, m.toGuest(this), args.map(a => m.toGuest(a)));\n if (JS_IsException(r)) {\n const exc = JS_GetException(ctx);\n const he = guestErrorToHost(ctx, exc);\n thrownGuest.set(he, exc);\n throw he;\n }\n return m.fromGuest(r);\n } finally {\n /* called from host code outside any guest call (an event, a timer, a\n promise reaction): run the guest jobs the callback queued */\n if (outermost) drainJobs(ctx);\n }\n },\n }.guestCallback;\n this.callables.set(fn as object, c);\n callableGuest.set(c, fn);\n return c;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* public API */\n\n/** the guest view of a host value: primitives as is, host objects and\n * functions as live membrane proxies (see docs/MEMBRANE.md) */\nexport function toGuestLive(ctx: JSContext, value: unknown, policy?: MembranePolicy): JSValue {\n if (FORBIDDEN.has(value)) throw new TypeError('toGuestLive: refusing to hand a host intrinsic to the guest');\n return membraneFor(ctx, policy).toGuest(value);\n}\n\n/** define the global `name` in the guest as a live view of `root` */\nexport function exposeLive(ctx: JSContext, name: string, root: unknown, policy?: MembranePolicy): void {\n const g = toGuestLive(ctx, root, policy);\n if (JS_SetPropertyStr(ctx, ctx.global_obj, name, g) < 0) {\n throw guestErrorToHost(ctx, JS_GetException(ctx));\n }\n}\n\n/** true if `value` is a membrane proxy */\nexport function isLiveProxy(value: unknown): boolean {\n return isObjectLike(value) && proxyHost.has(value);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"membrane.js","sourceRoot":"","sources":["../src/membrane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAsC2B;AAE3B,OAAO,EAC0B,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAClG,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,OAAO,GAC9E,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,aAAa,EAAE,kBAAkB,GACjH,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAiBhD,wEAAwE;AACxE,0EAA0E;AAE1E,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,eAAc,CAAC,CAAC,CAAC,WAAuB,CAAC;AAC1F,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,MA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,CAAC,CAAC;QACzB,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAED,wEAAwE;AACxE,0EAA0E;AAE1E;gEACgE;AAChE,MAAM,UAAU,WAAW,CAAC,GAAc,EAAE,KAAc,EAAE,MAAuB;IACjF,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,6DAA6D,CAAC,CAAC;IAC7G,OAAO,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,UAAU,CAAC,GAAc,EAAE,IAAY,EAAE,IAAa,EAAE,MAAuB;IAC7F,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACxD,MAAM,gBAAgB,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/* The membrane: live host objects for the guest.\n *\n * `toGuest`/`expose` (src/embed.ts) copy plain data and wrap functions; a\n * host class instance is refused. The membrane instead hands the guest a\n * live view of a host object graph: every host object or function the guest\n * reaches from a root crosses as a host `Proxy` whose handler lives here.\n * Each trap forwards the operation to the host object and converts what\n * comes back the same way, so nested objects, method results and\n * constructed instances are proxied lazily.\n *\n * A membrane proxy is not a guest Proxy (src/builtins/proxy.ts): the guest\n * Proxy calls guest handler code, while this handler is host code that must\n * never return a host value. The proxy's target is a private dummy (an empty\n * null-prototype object, or an empty function for callables) so the host\n * Proxy invariants never force a host value out, and the proxy has no engine\n * metadata, so the engine treats it as an ordinary object or host function\n * (`Reflect.get`, `Reflect.apply`, ... on it run the traps).\n *\n * The sandbox rules (always on; a policy can only narrow them):\n * 1. host intrinsics (Function and its async/generator variants, eval,\n * globalThis, Reflect, Proxy, Object, the Error constructors, the\n * intrinsic prototypes, the methods of Object, Reflect, Object.prototype\n * and Function.prototype) are never wrapped: they read as undefined, or\n * raise a guest TypeError where a value is required;\n * 2. constructor, prototype, __proto__, caller, callee, arguments and the\n * legacy __define/lookup{G,S}etter__ read as undefined; the prototype of\n * a proxy is the guest Object.prototype (Function.prototype for\n * callables); writes are refused unless the policy is writable, and\n * setPrototypeOf / preventExtensions are always refused;\n * 3. lookups stop at the host Object.prototype / Function.prototype and\n * continue on the guest's own, so call/apply/bind/toString/hasOwnProperty\n * are the guest intrinsics operating on the proxy, never host methods;\n * 4. getters run on the host, their results are converted like any value;\n * 5. only the well-known symbols iterator, asyncIterator, toStringTag and\n * toPrimitive (and hasInstance, answered by the membrane) are forwarded;\n * host symbols are neither listed nor returned;\n * 6. `policy.allow(target, key)` filters every key-based operation.\n *\n * See docs/MEMBRANE.md. */\n\nimport {\n JSContext, JSValue, JSClassID, JS_IsException, JS_GetException, JS_NewCFunction, JS_Call, JS_Throw,\n JS_NewArrayFrom, JS_NewErrorNative, JS_SetPropertyStr, JS_GetClassID, js_meta,\n} from './quickjs.ts';\nimport { JSErrorEnum } from './values.ts';\nimport {\n toGuest, drainJobs, guestErrorToHost, hostPromiseWith, guestPromiseToHostWith, fromGuestWith, FROM_GUEST_DEFAULT,\n} from './embed.ts';\nimport { isSharedArrayBuffer } from './builtins/typedarray.ts';\nimport { JS_NewDate } from './builtins/date.ts';\n\nexport interface MembranePolicy {\n /** called for every key-based operation (read, `in`, own keys, descriptors,\n * writes) on the host object `target`; any result but `true` hides the key */\n allow?(target: object, key: PropertyKey): boolean;\n /** let the guest set, define and delete properties on host objects\n * (default false: read-only) */\n writable?: boolean;\n /** hand the guest `ArrayBuffer`s, typed arrays and `DataView`s reached\n * through the root over the host memory itself, not copies (default\n * copies; a `SharedArrayBuffer` always crosses live). For a\n * `WebAssembly.Memory` the guest drives: `memory.buffer` is then the\n * module's memory, and what the guest writes the module reads. */\n liveBuffers?: boolean;\n}\n\n/* ------------------------------------------------------------------ */\n/* host intrinsics, collected once at module load */\n\nconst AsyncFunction = Object.getPrototypeOf(async function () {}).constructor as Function;\nconst GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor as Function;\nconst AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor as Function;\n\n/* never wrapped, never returned to the guest */\nconst FORBIDDEN = new Set<unknown>();\n/* the host prototype walk stops here and continues on the guest prototype */\nconst WALK_STOP = new Set<unknown>([Object.prototype, Function.prototype, globalThis]);\n\nfunction forbid(v: unknown): void {\n if ((typeof v === 'object' && v !== null) || typeof v === 'function') FORBIDDEN.add(v);\n}\n\n/* the functions stored on an object (values and accessors) */\nfunction forbidMembers(o: object): void {\n for (const k of Reflect.ownKeys(o)) {\n const d = Reflect.getOwnPropertyDescriptor(o, k);\n if (!d) continue;\n if (typeof d.value === 'function') forbid(d.value);\n forbid(d.get);\n forbid(d.set);\n }\n}\n\n(function collectIntrinsics() {\n const g = globalThis as Record<string, unknown>;\n for (const v of [Function, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, eval, globalThis, Reflect, Proxy, Object]) forbid(v);\n /* the host error constructors expose stack-trace hooks (captureStackTrace,\n prepareStackTrace) that can hand out host frames */\n for (const name of ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',\n 'AggregateError', 'SuppressedError']) forbid(g[name]);\n /* the prototype of every standard constructor */\n const ctors = ['Object', 'Function', 'Array', 'String', 'Number', 'Boolean', 'Symbol', 'BigInt', 'Error', 'EvalError',\n 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', 'AggregateError', 'SuppressedError', 'Date',\n 'RegExp', 'Map', 'Set', 'WeakMap', 'WeakSet', 'WeakRef', 'FinalizationRegistry', 'Promise', 'ArrayBuffer',\n 'SharedArrayBuffer', 'DataView', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array',\n 'Int32Array', 'Uint32Array', 'Float16Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array',\n 'Iterator', 'AsyncIterator', 'DisposableStack', 'AsyncDisposableStack'];\n for (const name of ctors) {\n const c = g[name] as { prototype?: unknown } | undefined;\n if (typeof c === 'function') forbid(c.prototype);\n }\n const TypedArray = Object.getPrototypeOf(Int8Array) as Function;\n forbid(TypedArray); forbid(TypedArray.prototype);\n for (const F of [AsyncFunction, GeneratorFunction, AsyncGeneratorFunction]) {\n forbid(F.prototype); /* %AsyncFunction.prototype%, %GeneratorFunction.prototype%, ... */\n forbid((F.prototype as { prototype?: unknown }).prototype); /* %GeneratorPrototype%, %AsyncGeneratorPrototype% */\n }\n const arrayIter = Object.getPrototypeOf([][Symbol.iterator]());\n forbid(arrayIter);\n forbid(Object.getPrototypeOf(arrayIter)); /* %IteratorPrototype% */\n forbid(Object.getPrototypeOf(Object.getPrototypeOf((async function* () {})()))); /* %AsyncGeneratorPrototype% */\n forbid(Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf((async function* () {})())))); /* %AsyncIteratorPrototype% */\n forbid(Object.getPrototypeOf(new Map().entries()));\n forbid(Object.getPrototypeOf(new Set().values()));\n forbid(Object.getPrototypeOf(''[Symbol.iterator]()));\n forbid(Object.getPrototypeOf(/a/[Symbol.matchAll]('a')));\n /* %ThrowTypeError% and the methods that reach code, prototypes or properties\n of arbitrary objects */\n forbid(Reflect.getOwnPropertyDescriptor(Function.prototype, 'caller')?.get);\n for (const o of [Object, Reflect, Proxy, Object.prototype, Function.prototype]) forbidMembers(o);\n})();\n\nconst BLOCKED_KEYS = new Set<PropertyKey>([\n 'constructor', 'prototype', '__proto__', 'caller', 'callee', 'arguments',\n '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__',\n]);\n\nconst WELL_KNOWN_SYMBOLS = new Set<symbol>(\n Reflect.ownKeys(Symbol).map(k => (Symbol as unknown as Record<PropertyKey, unknown>)[k])\n .filter((v): v is symbol => typeof v === 'symbol'));\n/* the well-known symbols forwarded as keys */\nconst FORWARDED_SYMBOLS = new Set<symbol>([Symbol.iterator, Symbol.asyncIterator, Symbol.toStringTag, Symbol.toPrimitive]);\n\nconst ERROR_KINDS: [Function, JSErrorEnum][] = [\n [TypeError, JSErrorEnum.TYPE_ERROR], [RangeError, JSErrorEnum.RANGE_ERROR], [SyntaxError, JSErrorEnum.SYNTAX_ERROR],\n [ReferenceError, JSErrorEnum.REFERENCE_ERROR], [URIError, JSErrorEnum.URI_ERROR], [EvalError, JSErrorEnum.EVAL_ERROR],\n];\nconst STANDARD_ERROR_NAMES = new Set(['Error', 'TypeError', 'RangeError', 'SyntaxError', 'ReferenceError', 'URIError', 'EvalError']);\n\nfunction isHostConstructor(f: Function): boolean {\n try {\n Reflect.construct(String, [], f);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isObjectLike(v: unknown): v is object {\n return (typeof v === 'object' && v !== null) || typeof v === 'function';\n}\n\n/* ------------------------------------------------------------------ */\n/* registries shared by every membrane */\n\n/* membrane proxy -> the host object it stands for */\nconst proxyHost = new WeakMap<object, { host: object; membrane: Membrane }>();\n/* host callable made for a guest function -> that guest function */\nconst callableGuest = new WeakMap<Function, JSValue>();\n/* host Error thrown to host code for a guest exception -> the guest exception */\nconst thrownGuest = new WeakMap<object, JSValue>();\n/* one membrane per context and policy */\nconst membranes = new WeakMap<JSContext, { plain?: Membrane; byPolicy: WeakMap<MembranePolicy, Membrane> }>();\n/* membrane traps running now, per runtime. Compiled guest code pushes no interpreter frame, so\n when it calls into host code through a proxy, `rt.current_stack_frame` is null although guest\n code is on the stack; this count is what tells a guest callback the host calls back that it is\n not the outermost call */\nconst trapDepth = new WeakMap<object, number>();\n\nfunction membraneFor(ctx: JSContext, policy: MembranePolicy | undefined): Membrane {\n let e = membranes.get(ctx);\n if (!e) { e = { byPolicy: new WeakMap() }; membranes.set(ctx, e); }\n if (policy === undefined) return (e.plain ??= new Membrane(ctx, {}));\n let m = e.byPolicy.get(policy);\n if (!m) { m = new Membrane(ctx, policy); e.byPolicy.set(policy, m); }\n return m;\n}\n\n/* ------------------------------------------------------------------ */\n\nclass Membrane {\n private readonly proxies = new WeakMap<object, object>(); /* host object -> proxy */\n private readonly callables = new WeakMap<object, Function>(); /* guest function -> host callable */\n private readonly hasInstanceFns = new WeakMap<object, JSValue>();\n private readonly guestSymbols = new WeakSet<symbol>(); /* symbols the guest handed to the host */\n private readonly writable: boolean;\n private readonly liveBuffers: boolean;\n private readonly allowFn: ((target: object, key: PropertyKey) => boolean) | undefined;\n\n constructor(readonly ctx: JSContext, policy: MembranePolicy) {\n this.writable = policy.writable === true;\n this.liveBuffers = policy.liveBuffers === true;\n this.allowFn = typeof policy.allow === 'function' ? policy.allow.bind(policy) : undefined;\n }\n\n /* ---------------- host -> guest ---------------- */\n\n toGuest(v: unknown, seen?: Map<object, JSValue>): JSValue {\n switch (typeof v) {\n case 'undefined': case 'boolean': case 'number': case 'string': case 'bigint':\n return v as JSValue;\n case 'symbol':\n return this.symbolCrosses(v) ? v : undefined;\n }\n if (v === null) return null;\n const o = v as object;\n if (FORBIDDEN.has(o)) return undefined;\n const p = proxyHost.get(o);\n if (p !== undefined) return p.membrane.ctx === this.ctx ? o : this.toGuest(p.host, seen);\n if (typeof o === 'function') {\n const g = callableGuest.get(o);\n if (g !== undefined) return g;\n }\n if (this.isGuestOwned(o)) return o;\n if (o instanceof Promise) {\n return hostPromiseWith(this.ctx, o, r => this.toGuest(r), e => this.thrownToGuest(e));\n }\n if (Array.isArray(o)) {\n /* arrays are snapshots: a fresh guest array whose elements are converted */\n seen ??= new Map();\n const cached = seen.get(o);\n if (cached !== undefined) return cached;\n const arr = JS_NewArrayFrom(this.ctx, []) as unknown as JSValue[];\n seen.set(o, arr);\n const len = o.length;\n for (let i = 0; i < len; i++) arr[i] = this.toGuest(o[i], seen);\n return arr;\n }\n if (o instanceof Date) return JS_NewDate(this.ctx, Date.prototype.getTime.call(o));\n if (o instanceof Error) return this.errorToGuest(o);\n if (o instanceof RegExp || o instanceof ArrayBuffer || isSharedArrayBuffer(o) || ArrayBuffer.isView(o)) {\n return toGuest(this.ctx, o, { liveBuffers: this.liveBuffers });\n }\n return this.wrap(o);\n }\n\n /* a well-known or registered symbol, or one the guest gave to the host */\n private symbolCrosses(s: symbol): boolean {\n return WELL_KNOWN_SYMBOLS.has(s) || Symbol.keyFor(s) !== undefined || this.guestSymbols.has(s);\n }\n\n /* an engine object, or an object whose prototype chain reaches this\n context's guest Object.prototype / Function.prototype */\n private isGuestOwned(o: object): boolean {\n if (js_meta.has(o)) return true;\n try {\n return this.chainReachesGuest(o);\n } catch {\n return false; /* a host proxy whose getPrototypeOf throws */\n }\n }\n\n private chainReachesGuest(o: object): boolean {\n const ctx = this.ctx;\n const op = ctx.class_proto[JSClassID.OBJECT], fp = ctx.function_proto;\n let p: object | null = Reflect.getPrototypeOf(o);\n for (let i = 0; i < 64 && p !== null; i++) {\n if (p === op || p === fp) return true;\n if (WALK_STOP.has(p) || FORBIDDEN.has(p) || proxyHost.has(p)) return false;\n p = Reflect.getPrototypeOf(p);\n }\n return false;\n }\n\n private errorToGuest(e: Error): JSValue {\n let kind = JSErrorEnum.PLAIN_ERROR;\n for (const [C, k] of ERROR_KINDS) if (e instanceof C) { kind = k; break; }\n let message = '', name: unknown;\n try { const m = e.message; message = typeof m === 'string' ? m : ''; name = e.name; } catch { /* hostile getter */ }\n const g = JS_NewErrorNative(this.ctx, kind, message);\n if (kind === JSErrorEnum.PLAIN_ERROR && typeof name === 'string' && !STANDARD_ERROR_NAMES.has(name)) {\n Reflect.defineProperty(g, 'name', { value: name, writable: true, enumerable: false, configurable: true });\n }\n return g;\n }\n\n /* convert anything the host threw into a value to throw in the guest; the\n host exception object itself never crosses */\n thrownToGuest(e: unknown): JSValue {\n if (isObjectLike(e)) {\n const g = thrownGuest.get(e);\n if (g !== undefined) return g; /* a guest exception that passed through host code */\n if (proxyHost.has(e) || this.isGuestOwned(e)) return e as JSValue; /* thrown by guest code */\n if (e instanceof Error) return this.errorToGuest(e);\n let message = 'host exception';\n try {\n const m = (e as { message?: unknown }).message;\n if (typeof m === 'string') message = m;\n } catch { /* hostile getter */ }\n return JS_NewErrorNative(this.ctx, JSErrorEnum.PLAIN_ERROR, message);\n }\n if (typeof e === 'symbol') return this.symbolCrosses(e) ? e : undefined;\n return e as JSValue;\n }\n\n private guestTypeError(message: string): JSValue {\n return JS_NewErrorNative(this.ctx, JSErrorEnum.TYPE_ERROR, message);\n }\n\n /* the proxy for a host object (one per host object) */\n wrap(host: object): object {\n const cached = this.proxies.get(host);\n if (cached !== undefined) return cached;\n let target: object;\n const callable = typeof host === 'function';\n if (callable) {\n /* constructible or not like the host function; no own properties, so\n no target invariant constrains the traps */\n const f: Function = isHostConstructor(host as Function) ? Function.prototype.bind.call(function () {}, null) : () => {};\n Reflect.deleteProperty(f, 'name');\n Reflect.deleteProperty(f, 'length');\n Reflect.setPrototypeOf(f, null);\n target = f;\n } else {\n target = Object.create(null);\n }\n const proxy = new Proxy(target, this.handler(host, callable));\n this.proxies.set(host, proxy);\n proxyHost.set(proxy, { host, membrane: this });\n return proxy;\n }\n\n private keyAllowed(host: object, key: PropertyKey): boolean {\n if (typeof key === 'symbol') {\n if (WELL_KNOWN_SYMBOLS.has(key) && !FORWARDED_SYMBOLS.has(key)) return false;\n } else if (BLOCKED_KEYS.has(key)) {\n return false;\n }\n return this.allowFn === undefined || this.allowFn(host, key) === true;\n }\n\n /* listed by ownKeys: host symbols other than the forwarded well-known ones stay hidden */\n private keyListed(host: object, key: string | symbol): boolean {\n if (typeof key === 'symbol' && !FORWARDED_SYMBOLS.has(key) && !this.guestSymbols.has(key)) return false;\n return this.keyAllowed(host, key);\n }\n\n /* walk the host prototype chain up to (not including) the host\n Object.prototype / Function.prototype */\n private lookup(host: object, key: PropertyKey): PropertyDescriptor | undefined {\n let o: object | null = host;\n for (let depth = 0; o !== null && depth < 10000; depth++) {\n if (WALK_STOP.has(o)) return undefined;\n const d = Reflect.getOwnPropertyDescriptor(o, key);\n if (d !== undefined) return d;\n o = Reflect.getPrototypeOf(o);\n }\n return undefined;\n }\n\n private hostOf(v: unknown, fallback: object): object {\n return isObjectLike(v) ? proxyHost.get(v)?.host ?? fallback : fallback;\n }\n\n private hasInstance(host: object): JSValue {\n let f = this.hasInstanceFns.get(host);\n if (f === undefined) {\n f = JS_NewCFunction(this.ctx, (ctx, _this, argv) => {\n const v = argv[0];\n const h = isObjectLike(v) ? proxyHost.get(v)?.host : undefined;\n if (h === undefined) return false;\n try {\n return h instanceof (host as Function);\n } catch (e) {\n return JS_Throw(ctx, this.thrownToGuest(e));\n }\n }, '[Symbol.hasInstance]', 1);\n this.hasInstanceFns.set(host, f);\n }\n return f;\n }\n\n private handler(host: object, callable: boolean): ProxyHandler<object> {\n const m = this;\n const ctx = this.ctx;\n const guestProto = () => (callable ? ctx.function_proto : ctx.class_proto[JSClassID.OBJECT]) as object;\n /* every trap converts what the host throws, and counts as guest code on the stack while it\n runs host code */\n const rt = ctx.rt;\n const guard = <A extends unknown[], R>(fn: (...args: A) => R) => (...args: A): R => {\n trapDepth.set(rt, (trapDepth.get(rt) ?? 0) + 1);\n try {\n return fn(...args);\n } catch (e) {\n throw m.thrownToGuest(e);\n } finally {\n trapDepth.set(rt, trapDepth.get(rt)! - 1);\n }\n };\n const refuse = (what: string, key?: PropertyKey): never => {\n const k = key === undefined ? '' : ` '${typeof key === 'symbol' ? key.description ?? 'symbol' : key}'`;\n throw m.guestTypeError(`cannot ${what}${k}: host object is read-only`);\n };\n const proxyOf = () => m.proxies.get(host);\n\n return {\n get: guard((_t: object, key: PropertyKey, receiver: unknown) => {\n if (callable && key === Symbol.hasInstance) return m.hasInstance(host);\n if (!m.keyAllowed(host, key)) return undefined;\n const d = m.lookup(host, key);\n if (d === undefined) return Reflect.get(guestProto(), key, receiver);\n if ('value' in d) return m.toGuest(d.value);\n if (d.get === undefined) return undefined;\n return m.toGuest(Reflect.apply(d.get, m.hostOf(receiver, host), []));\n }),\n has: guard((_t: object, key: PropertyKey) => {\n if (callable && key === Symbol.hasInstance) return true;\n if (!m.keyAllowed(host, key)) return false;\n if (m.lookup(host, key) !== undefined) return true;\n return Reflect.has(guestProto(), key);\n }),\n ownKeys: guard((_t: object) => Reflect.ownKeys(host).filter(k => m.keyListed(host, k))),\n getOwnPropertyDescriptor: guard((_t: object, key: PropertyKey) => {\n if (!m.keyAllowed(host, key)) return undefined;\n const d = Reflect.getOwnPropertyDescriptor(host, key);\n if (d === undefined) return undefined;\n if ('value' in d) {\n return { value: m.toGuest(d.value), writable: m.writable && d.writable === true, enumerable: d.enumerable === true, configurable: true };\n }\n return {\n get: d.get === undefined ? undefined : m.toGuest(d.get) as (() => unknown) | undefined,\n set: d.set === undefined || !m.writable ? undefined : m.toGuest(d.set) as ((v: unknown) => void) | undefined,\n enumerable: d.enumerable === true, configurable: true,\n };\n }),\n set: guard((_t: object, key: PropertyKey, value: unknown, receiver: unknown) => {\n if (receiver !== proxyOf() && !(isObjectLike(receiver) && proxyHost.has(receiver))) {\n /* a guest object inheriting from the proxy: the property lands on it */\n return Reflect.defineProperty(receiver as object, key, { value, writable: true, enumerable: true, configurable: true });\n }\n if (!m.writable || !m.keyAllowed(host, key)) refuse('assign to property', key);\n return Reflect.set(host, key, m.fromGuest(value as JSValue), m.hostOf(receiver, host));\n }),\n defineProperty: guard((_t: object, key: PropertyKey, desc: PropertyDescriptor) => {\n if (!m.writable || !m.keyAllowed(host, key)) refuse('define property', key);\n if (desc.configurable === false) throw m.guestTypeError('cannot define a non-configurable property on a host object');\n const hd: PropertyDescriptor = {};\n if ('value' in desc) hd.value = m.fromGuest(desc.value as JSValue);\n if ('get' in desc) hd.get = m.fromGuest(desc.get as JSValue) as () => unknown;\n if ('set' in desc) hd.set = m.fromGuest(desc.set as JSValue) as (v: unknown) => void;\n if ('writable' in desc) hd.writable = desc.writable;\n if ('enumerable' in desc) hd.enumerable = desc.enumerable;\n hd.configurable = true;\n return Reflect.defineProperty(host, key, hd);\n }),\n deleteProperty: guard((_t: object, key: PropertyKey) => {\n if (!m.writable || !m.keyAllowed(host, key)) refuse('delete property', key);\n return Reflect.deleteProperty(host, key);\n }),\n getPrototypeOf: () => guestProto(),\n setPrototypeOf: () => false,\n isExtensible: () => true,\n preventExtensions: () => false,\n apply: guard((_t: object, thisArg: unknown, args: unknown[]) => {\n const hostThis = thisArg === ctx.global_obj ? undefined : m.fromGuest(thisArg as JSValue);\n const hostArgs = args.map(a => m.fromGuest(a as JSValue));\n return m.toGuest(Reflect.apply(host as Function, hostThis, hostArgs));\n }),\n construct: guard((_t: object, args: unknown[], newTarget: unknown) => {\n if (newTarget !== proxyOf()) throw m.guestTypeError('host constructors cannot be subclassed from the guest');\n const r = m.toGuest(Reflect.construct(host as Function, args.map(a => m.fromGuest(a as JSValue))));\n if (!isObjectLike(r)) throw m.guestTypeError('host constructor returned a value that cannot cross the membrane');\n return r;\n }),\n };\n }\n\n /* ---------------- guest -> host ---------------- */\n\n fromGuest(v: JSValue): unknown {\n return fromGuestWith(this.ctx, v, x => this.fromGuestHook(x));\n }\n\n private fromGuestHook(v: JSValue): unknown {\n if (typeof v === 'symbol') {\n if (!WELL_KNOWN_SYMBOLS.has(v) && Symbol.keyFor(v) === undefined) this.guestSymbols.add(v);\n return v;\n }\n if (!isObjectLike(v)) return FROM_GUEST_DEFAULT;\n const p = proxyHost.get(v);\n if (p !== undefined) return p.host;\n if (typeof v === 'function') return this.callable(v);\n if (JS_GetClassID(v) === JSClassID.PROMISE) {\n return guestPromiseToHostWith(this.ctx, v, x => this.fromGuest(x),\n e => (JS_GetClassID(e) === JSClassID.ERROR ? guestErrorToHost(this.ctx, e) : this.fromGuest(e)));\n }\n return FROM_GUEST_DEFAULT;\n }\n\n /* a host function that runs the guest function (one per guest function) */\n private callable(fn: JSValue): Function {\n const cached = this.callables.get(fn as object);\n if (cached !== undefined) return cached;\n const m = this;\n const ctx = this.ctx;\n const c = {\n guestCallback(this: unknown, ...args: unknown[]): unknown {\n /* outermost: no guest code below this call, neither an interpreter frame nor a membrane\n trap (the way compiled guest code reaches host code) */\n const outermost = ctx.rt.current_stack_frame === null && (trapDepth.get(ctx.rt) ?? 0) === 0;\n try {\n const r = JS_Call(ctx, fn, m.toGuest(this), args.map(a => m.toGuest(a)));\n if (JS_IsException(r)) {\n const exc = JS_GetException(ctx);\n const he = guestErrorToHost(ctx, exc);\n thrownGuest.set(he, exc);\n throw he;\n }\n return m.fromGuest(r);\n } finally {\n /* called from host code outside any guest call (an event, a timer, a\n promise reaction): run the guest jobs the callback queued */\n if (outermost) drainJobs(ctx);\n }\n },\n }.guestCallback;\n this.callables.set(fn as object, c);\n callableGuest.set(c, fn);\n return c;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* public API */\n\n/** the guest view of a host value: primitives as is, host objects and\n * functions as live membrane proxies (see docs/MEMBRANE.md) */\nexport function toGuestLive(ctx: JSContext, value: unknown, policy?: MembranePolicy): JSValue {\n if (FORBIDDEN.has(value)) throw new TypeError('toGuestLive: refusing to hand a host intrinsic to the guest');\n return membraneFor(ctx, policy).toGuest(value);\n}\n\n/** define the global `name` in the guest as a live view of `root` */\nexport function exposeLive(ctx: JSContext, name: string, root: unknown, policy?: MembranePolicy): void {\n const g = toGuestLive(ctx, root, policy);\n if (JS_SetPropertyStr(ctx, ctx.global_obj, name, g) < 0) {\n throw guestErrorToHost(ctx, JS_GetException(ctx));\n }\n}\n\n/** true if `value` is a membrane proxy */\nexport function isLiveProxy(value: unknown): boolean {\n return isObjectLike(value) && proxyHost.has(value);\n}\n"]}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const JSEPTION_VERSION = "0.0.
|
|
1
|
+
export declare const JSEPTION_VERSION = "0.0.7";
|
package/dist/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* The jseption package version, kept equal to package.json by the npm "version" script
|
|
2
2
|
(scripts/sync-version.mjs) and checked by tests/bytecode.test.ts. Serialized bytecode
|
|
3
3
|
records it and only loads in the same version. */
|
|
4
|
-
export const JSEPTION_VERSION = '0.0.
|
|
4
|
+
export const JSEPTION_VERSION = '0.0.7';
|
|
5
5
|
//# sourceMappingURL=version.js.map
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;oDAEoD;AACpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC","sourcesContent":["/* The jseption package version, kept equal to package.json by the npm \"version\" script\n (scripts/sync-version.mjs) and checked by tests/bytecode.test.ts. Serialized bytecode\n records it and only loads in the same version. */\nexport const JSEPTION_VERSION = '0.0.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;oDAEoD;AACpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC","sourcesContent":["/* The jseption package version, kept equal to package.json by the npm \"version\" script\n (scripts/sync-version.mjs) and checked by tests/bytecode.test.ts. Serialized bytecode\n records it and only loads in the same version. */\nexport const JSEPTION_VERSION = '0.0.7';\n"]}
|
package/package.json
CHANGED