jseption 0.0.5 → 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.
Files changed (90) hide show
  1. package/README.md +30 -6
  2. package/dist/atoms.d.ts +1 -0
  3. package/dist/atoms.js +2 -1
  4. package/dist/atoms.js.map +1 -1
  5. package/dist/builtins/base64.d.ts +14 -0
  6. package/dist/builtins/base64.js +219 -0
  7. package/dist/builtins/base64.js.map +1 -0
  8. package/dist/builtins/bigint.js +3 -3
  9. package/dist/builtins/bigint.js.map +1 -1
  10. package/dist/builtins/date.d.ts +1 -0
  11. package/dist/builtins/date.js +26 -12
  12. package/dist/builtins/date.js.map +1 -1
  13. package/dist/builtins/error.js +9 -0
  14. package/dist/builtins/error.js.map +1 -1
  15. package/dist/builtins/float16.d.ts +3 -0
  16. package/dist/builtins/float16.js +69 -0
  17. package/dist/builtins/float16.js.map +1 -0
  18. package/dist/builtins/function.js +2 -2
  19. package/dist/builtins/index.js +9 -6
  20. package/dist/builtins/index.js.map +1 -1
  21. package/dist/builtins/iterator.d.ts +2 -0
  22. package/dist/builtins/iterator.js +624 -0
  23. package/dist/builtins/iterator.js.map +1 -0
  24. package/dist/builtins/json.d.ts +13 -1
  25. package/dist/builtins/json.js +283 -211
  26. package/dist/builtins/json.js.map +1 -1
  27. package/dist/builtins/mapset.js +365 -6
  28. package/dist/builtins/mapset.js.map +1 -1
  29. package/dist/builtins/math.js +203 -3
  30. package/dist/builtins/math.js.map +1 -1
  31. package/dist/builtins/native.js +6 -6
  32. package/dist/builtins/object.js +9 -2
  33. package/dist/builtins/object.js.map +1 -1
  34. package/dist/builtins/promise.js +31 -11
  35. package/dist/builtins/promise.js.map +1 -1
  36. package/dist/builtins/proxy.js +2 -2
  37. package/dist/builtins/reflect.js +6 -2
  38. package/dist/builtins/reflect.js.map +1 -1
  39. package/dist/builtins/regexp.js +74 -3
  40. package/dist/builtins/regexp.js.map +1 -1
  41. package/dist/builtins/string.js +1 -1
  42. package/dist/builtins/symbol.js +1 -1
  43. package/dist/builtins/symbol.js.map +1 -1
  44. package/dist/builtins/typedarray.d.ts +4 -1
  45. package/dist/builtins/typedarray.js +325 -37
  46. package/dist/builtins/typedarray.js.map +1 -1
  47. package/dist/builtins/weakref.js +7 -7
  48. package/dist/embed.d.ts +5 -0
  49. package/dist/embed.js +36 -11
  50. package/dist/embed.js.map +1 -1
  51. package/dist/interpreter.js +15 -14
  52. package/dist/interpreter.js.map +1 -1
  53. package/dist/jit.d.ts +1 -0
  54. package/dist/jit.js +51 -13
  55. package/dist/jit.js.map +1 -1
  56. package/dist/jit_hook.d.ts +1 -0
  57. package/dist/jit_hook.js.map +1 -1
  58. package/dist/jit_runtime.d.ts +1 -1
  59. package/dist/jit_runtime.js +6 -6
  60. package/dist/jit_runtime.js.map +1 -1
  61. package/dist/jit_stack.d.ts +1 -0
  62. package/dist/jit_stack.js +2 -1
  63. package/dist/jit_stack.js.map +1 -1
  64. package/dist/jseption.d.ts +2 -0
  65. package/dist/jseption.js +1 -0
  66. package/dist/jseption.js.map +1 -1
  67. package/dist/membrane.d.ts +6 -0
  68. package/dist/membrane.js +7 -3
  69. package/dist/membrane.js.map +1 -1
  70. package/dist/module.js +5 -3
  71. package/dist/module.js.map +1 -1
  72. package/dist/parser.js +26 -9
  73. package/dist/parser.js.map +1 -1
  74. package/dist/print.d.ts +12 -0
  75. package/dist/print.js +494 -0
  76. package/dist/print.js.map +1 -0
  77. package/dist/qjs.js +13 -10
  78. package/dist/qjs.js.map +1 -1
  79. package/dist/quickjs.d.ts +8 -0
  80. package/dist/quickjs.js +132 -53
  81. package/dist/quickjs.js.map +1 -1
  82. package/dist/std.d.ts +4 -2
  83. package/dist/std.js +42 -8
  84. package/dist/std.js.map +1 -1
  85. package/dist/values.d.ts +31 -27
  86. package/dist/values.js.map +1 -1
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/dist/version.js.map +1 -1
  90. package/package.json +1 -1
@@ -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 */
@@ -513,7 +517,7 @@ class Membrane {
513
517
  return p.host;
514
518
  if (typeof v === 'function')
515
519
  return this.callable(v);
516
- if (JS_GetClassID(v) === 45 /* JSClassID.PROMISE */) {
520
+ if (JS_GetClassID(v) === 46 /* JSClassID.PROMISE */) {
517
521
  return guestPromiseToHostWith(this.ctx, v, x => this.fromGuest(x), e => (JS_GetClassID(e) === 3 /* JSClassID.ERROR */ ? guestErrorToHost(this.ctx, e) : this.fromGuest(e)));
518
522
  }
519
523
  return FROM_GUEST_DEFAULT;
@@ -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,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AAI,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 { 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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C,CAAC;YACH,CAAC;SACF,CAAC,aAAa,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAY,EAAE,CAAC,CAAC,CAAC;QACpC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,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/module.js CHANGED
@@ -414,7 +414,7 @@ function js_create_module_function(ctx, m) {
414
414
  const b = m.func_bytecode;
415
415
  /* create the module variables; the other variables are imported from other modules */
416
416
  const var_refs = b.closure_var.map(cv => cv.is_local ? new_var_ref_cell(cv.is_lexical ? JS_UNINITIALIZED : undefined) : null);
417
- const proto = ctx.class_proto[48 /* JSClassID.ASYNC_FUNCTION */] ?? ctx.function_proto;
417
+ const proto = ctx.class_proto[49 /* JSClassID.ASYNC_FUNCTION */] ?? ctx.function_proto;
418
418
  const f = js_closure_from_refs(ctx, b, var_refs, proto, false);
419
419
  if (JS_IsException(f))
420
420
  return -1;
@@ -890,10 +890,12 @@ function js_async_module_execution_rejected(ctx, module, error) {
890
890
  module.eval_exception = error;
891
891
  module.status = 5 /* JSModuleStatus.EVALUATED */;
892
892
  module.async_evaluation = false;
893
- for (const m of module.async_parent_modules)
894
- js_async_module_execution_rejected(ctx, m, error);
893
+ /* the module's own promise is rejected before its parents' (af16a97, after a
894
+ specification change) */
895
895
  if (module.promise !== undefined)
896
896
  JS_Call(ctx, module.resolving_funcs[1], undefined, [error]);
897
+ for (const m of module.async_parent_modules)
898
+ js_async_module_execution_rejected(ctx, m, error);
897
899
  }
898
900
  function js_async_module_execution_fulfilled(ctx, module) {
899
901
  if (module.status === 5 /* JSModuleStatus.EVALUATED */)