@poe-platform/safe-js 0.1.724 → 0.1.725

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 (46) hide show
  1. package/README.md +3 -0
  2. package/dist/safe-js/chunks/{chunk-E5VQVLWF.js → chunk-6YSHQ5ET.js} +2 -2
  3. package/dist/safe-js/chunks/{chunk-GM32LIKF.js → chunk-ECTNNLWN.js} +3 -3
  4. package/dist/safe-js/chunks/{chunk-WYY65M7Z.js → chunk-FYSWUSHN.js} +2 -2
  5. package/dist/safe-js/chunks/{chunk-CSRNI5HI.js → chunk-K6F5QLZQ.js} +2 -2
  6. package/dist/safe-js/chunks/{chunk-GYT2ECWI.js → chunk-O2CPPE6M.js} +2 -2
  7. package/dist/safe-js/chunks/{chunk-5M2P3GUC.js → chunk-PKRGP34X.js} +36 -9
  8. package/dist/safe-js/chunks/chunk-PKRGP34X.js.map +7 -0
  9. package/dist/safe-js/chunks/{chunk-ZHJPXLUJ.js → chunk-QU2F65UQ.js} +68 -10
  10. package/dist/safe-js/chunks/{chunk-ZHJPXLUJ.js.map → chunk-QU2F65UQ.js.map} +2 -2
  11. package/dist/safe-js/chunks/{chunk-TMRO2MK6.js → chunk-V2ESZF34.js} +3 -3
  12. package/dist/safe-js/chunks/{chunk-2DISWAVU.js → chunk-Y7LSEUWV.js} +2 -2
  13. package/dist/safe-js/chunks/{chunk-BYX6GUCC.js → chunk-YRALPIEZ.js} +2 -2
  14. package/dist/safe-js/chunks/{cli-runtime-PHNOLXPN.js → cli-runtime-5HVEFMDB.js} +10 -10
  15. package/dist/safe-js/chunks/{dump-HAU2HFBZ.js → dump-VKSKINUI.js} +3 -3
  16. package/dist/safe-js/chunks/{fs-6PHK3Q3V.js → fs-CZ2TAPHK.js} +3 -3
  17. package/dist/safe-js/chunks/{harness-E3FVGKIR.js → harness-WNABEKDH.js} +3 -3
  18. package/dist/safe-js/chunks/{mcp-HGLB4YOP.js → mcp-ZZDGN5CA.js} +3 -3
  19. package/dist/safe-js/chunks/{migration-file-4GNB4HDL.js → migration-file-QVT4W464.js} +4 -4
  20. package/dist/safe-js/chunks/{restore-ZFU4NJOM.js → restore-PTIQHGKI.js} +4 -4
  21. package/dist/safe-js/chunks/{run-AAOCYT5M.js → run-WNR7QYUJ.js} +6 -6
  22. package/dist/safe-js/chunks/{runtime-modules-OPLHKWMC.js → runtime-modules-YEOG62RU.js} +3 -3
  23. package/dist/safe-js/cli.js +2 -2
  24. package/dist/safe-js/core.js +5 -5
  25. package/dist/safe-js/extensions.d.ts +2 -0
  26. package/dist/safe-js/index.js +10 -10
  27. package/dist/safe-js/interp/host-bridge.d.ts +1 -1
  28. package/package.json +2 -2
  29. package/dist/safe-js/chunks/chunk-5M2P3GUC.js.map +0 -7
  30. /package/dist/safe-js/chunks/{chunk-E5VQVLWF.js.map → chunk-6YSHQ5ET.js.map} +0 -0
  31. /package/dist/safe-js/chunks/{chunk-GM32LIKF.js.map → chunk-ECTNNLWN.js.map} +0 -0
  32. /package/dist/safe-js/chunks/{chunk-WYY65M7Z.js.map → chunk-FYSWUSHN.js.map} +0 -0
  33. /package/dist/safe-js/chunks/{chunk-CSRNI5HI.js.map → chunk-K6F5QLZQ.js.map} +0 -0
  34. /package/dist/safe-js/chunks/{chunk-GYT2ECWI.js.map → chunk-O2CPPE6M.js.map} +0 -0
  35. /package/dist/safe-js/chunks/{chunk-TMRO2MK6.js.map → chunk-V2ESZF34.js.map} +0 -0
  36. /package/dist/safe-js/chunks/{chunk-2DISWAVU.js.map → chunk-Y7LSEUWV.js.map} +0 -0
  37. /package/dist/safe-js/chunks/{chunk-BYX6GUCC.js.map → chunk-YRALPIEZ.js.map} +0 -0
  38. /package/dist/safe-js/chunks/{cli-runtime-PHNOLXPN.js.map → cli-runtime-5HVEFMDB.js.map} +0 -0
  39. /package/dist/safe-js/chunks/{dump-HAU2HFBZ.js.map → dump-VKSKINUI.js.map} +0 -0
  40. /package/dist/safe-js/chunks/{fs-6PHK3Q3V.js.map → fs-CZ2TAPHK.js.map} +0 -0
  41. /package/dist/safe-js/chunks/{harness-E3FVGKIR.js.map → harness-WNABEKDH.js.map} +0 -0
  42. /package/dist/safe-js/chunks/{mcp-HGLB4YOP.js.map → mcp-ZZDGN5CA.js.map} +0 -0
  43. /package/dist/safe-js/chunks/{migration-file-4GNB4HDL.js.map → migration-file-QVT4W464.js.map} +0 -0
  44. /package/dist/safe-js/chunks/{restore-ZFU4NJOM.js.map → restore-PTIQHGKI.js.map} +0 -0
  45. /package/dist/safe-js/chunks/{run-AAOCYT5M.js.map → run-WNR7QYUJ.js.map} +0 -0
  46. /package/dist/safe-js/chunks/{runtime-modules-OPLHKWMC.js.map → runtime-modules-YEOG62RU.js.map} +0 -0
package/README.md CHANGED
@@ -324,6 +324,7 @@ Supply your own bounded `journal`; this does not add browser console behavior. W
324
324
  | `invokeCallback(callback, { thisValue?, args? })` | Invoke a captured guest function with the realm's state, cancellation and budgets. Same operation as on the realm. |
325
325
  | `startCallback(callback, { thisValue?, args? })` | Return separate `synchronous` and `result` promises for the same realm-owned invocation. Also available on the realm. |
326
326
  | `releaseCallback(callback)` | Revoke the callback and release its retained guest state. |
327
+ | `retainCallbackArguments(operation)` | During setup, give each call independent callback wrappers in its copied arguments. Requires declared and granted `guest:retain`. The host owns these wrappers and releases each with `releaseCallback`; aliases within one call still share a wrapper. |
327
328
  | `retainGuestArguments(operation, from)` | During setup, opt an operation into opaque argument references starting at the zero-based index `from`. Requires declared and granted `guest:retain`. Earlier arguments keep normal conversion; live host methods preserve the declaration. |
328
329
  | `releaseGuestReference(reference)` | Revoke one reference and release its retained state. Also available on the realm. |
329
330
  | `nestedOperation(fn)` | During setup, mark a host operation authorized to run nested source. Requires declared and granted `source:nested`. |
@@ -333,6 +334,8 @@ Use `expandos: { maxKeys, maxKeyCodeUnits, assertActive? }` to allow guest assig
333
334
 
334
335
  For a timer-shaped `schedule(callback, delay, ...args)`, register `context.retainGuestArguments(schedule, 2)`. The host receives normal callback/delay values and opaque `GuestReference` handles for the remaining arguments. Pass those handles to `context.invokeCallback(callback, { args })` to recover the original guest objects and observe mutations made after scheduling. References also work as callback receivers and host return values, including cycles, closures, primitives and live host objects.
335
336
 
337
+ Also register `context.retainCallbackArguments(schedule)` when each scheduled task owns its callback. Different calls then receive independently releasable wrappers, even for the same guest function; normal exports keep their shared callback identity. Release a timer's wrapper after cancellation or after all its invocation phases settle. Copied callbacks count against `limits.callbacks` and data budgets. Argument-copy failure or synchronous host failure revokes that call's owned wrappers; asynchronous operations must release theirs in host cleanup. Returning a wrapper to guest code preserves the original function identity and does not release it.
338
+
336
339
  For a trusted native buffer such as WebAssembly memory, use `context.createArrayBufferReference(buffer)` and return the handle from a host property or operation. Guest ArrayBuffer views then share its bytes with the host, preserving identity and bidirectional writes. Ordinary host buffers still copy. Shared, resizable, detached, subclassed and proxy buffers reject, as do buffers with own properties or symbols. After native memory growth detaches the old buffer, create a new reference to the new buffer; the old reference continues to denote the detached buffer.
337
340
 
338
341
  Release each reference when the host no longer needs it; returning it does not release it. Retained graphs count against data budgets and `limits.guestReferences`. Synchronous native failure releases references captured for that call; asynchronous operations must release theirs in host cleanup. Close revokes all remaining references. Handles cannot be inspected, used in another realm, or serialized into replay/error data. Unmarked operations still copy values.
@@ -5,7 +5,7 @@ import {
5
5
  accessDeniedSystemError,
6
6
  declareBudgetedHostOperation,
7
7
  declareHostOperation
8
- } from "./chunk-ZHJPXLUJ.js";
8
+ } from "./chunk-QU2F65UQ.js";
9
9
 
10
10
  // packages/safe-js/src/modules/fs.ts
11
11
  import { constants as nodeFsConstants } from "node:fs";
@@ -721,4 +721,4 @@ export {
721
721
  FS_OPTION_SURFACE,
722
722
  makeFsModule
723
723
  };
724
- //# sourceMappingURL=chunk-E5VQVLWF.js.map
724
+ //# sourceMappingURL=chunk-6YSHQ5ET.js.map
@@ -7,7 +7,7 @@ import {
7
7
  validateMigrationReconciliation,
8
8
  validateMigrationSemantics,
9
9
  validateSnapshotMigration
10
- } from "./chunk-2DISWAVU.js";
10
+ } from "./chunk-Y7LSEUWV.js";
11
11
  import {
12
12
  DUMP_FORMAT_VERSION,
13
13
  EXECUTION_SEMANTICS,
@@ -17,7 +17,7 @@ import {
17
17
  serializeSafeJSSnapshot,
18
18
  validateDumpEnvelope,
19
19
  validateSnapshotData
20
- } from "./chunk-ZHJPXLUJ.js";
20
+ } from "./chunk-QU2F65UQ.js";
21
21
  import {
22
22
  parseModule
23
23
  } from "./chunk-KOO6YGQG.js";
@@ -179,4 +179,4 @@ export {
179
179
  migrateSnapshot,
180
180
  migrateSnapshotFile
181
181
  };
182
- //# sourceMappingURL=chunk-GM32LIKF.js.map
182
+ //# sourceMappingURL=chunk-ECTNNLWN.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SnapshotNotReadyError,
3
3
  serializeSafeJSSnapshot
4
- } from "./chunk-ZHJPXLUJ.js";
4
+ } from "./chunk-QU2F65UQ.js";
5
5
  import {
6
6
  SandboxError
7
7
  } from "./chunk-KOO6YGQG.js";
@@ -195,4 +195,4 @@ export {
195
195
  dumpCurrent,
196
196
  serializeRunSnapshot
197
197
  };
198
- //# sourceMappingURL=chunk-WYY65M7Z.js.map
198
+ //# sourceMappingURL=chunk-FYSWUSHN.js.map
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  declareHostOperation,
8
8
  runResources
9
- } from "./chunk-ZHJPXLUJ.js";
9
+ } from "./chunk-QU2F65UQ.js";
10
10
  import {
11
11
  hostErrorData
12
12
  } from "./chunk-KOO6YGQG.js";
@@ -402,4 +402,4 @@ function isPlainObjectRecord(value) {
402
402
  export {
403
403
  makeMcpModule
404
404
  };
405
- //# sourceMappingURL=chunk-CSRNI5HI.js.map
405
+ //# sourceMappingURL=chunk-K6F5QLZQ.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  deepCopyToSandbox
3
- } from "./chunk-ZHJPXLUJ.js";
3
+ } from "./chunk-QU2F65UQ.js";
4
4
 
5
5
  // packages/safe-js/src/modules/harness.ts
6
6
  function makeHarnessModule(frontmatter, meta) {
@@ -52,4 +52,4 @@ ${prompt}`;
52
52
  export {
53
53
  makeHarnessModule
54
54
  };
55
- //# sourceMappingURL=chunk-GYT2ECWI.js.map
55
+ //# sourceMappingURL=chunk-O2CPPE6M.js.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  restore
3
- } from "./chunk-TMRO2MK6.js";
3
+ } from "./chunk-V2ESZF34.js";
4
4
  import {
5
5
  attachDumpController,
6
6
  createDumpController
7
- } from "./chunk-WYY65M7Z.js";
7
+ } from "./chunk-FYSWUSHN.js";
8
8
  import {
9
9
  getOwnErrorCode,
10
10
  hasOwnErrorCode
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  hashParsedAst,
14
14
  hashSource
15
- } from "./chunk-2DISWAVU.js";
15
+ } from "./chunk-Y7LSEUWV.js";
16
16
  import {
17
17
  DUMP_FORMAT_VERSION,
18
18
  EXECUTION_SEMANTICS,
@@ -100,7 +100,7 @@ import {
100
100
  withSandboxPromiseRejectionTracker,
101
101
  wrapCallerInjectedBindings,
102
102
  wrapCancelableBindings
103
- } from "./chunk-ZHJPXLUJ.js";
103
+ } from "./chunk-QU2F65UQ.js";
104
104
  import {
105
105
  Budget,
106
106
  CompileScope,
@@ -751,6 +751,7 @@ var RealmState = class {
751
751
  guestReferences = /* @__PURE__ */ new Map();
752
752
  retainedOperations = /* @__PURE__ */ new WeakMap();
753
753
  nestedOperations = /* @__PURE__ */ new WeakMap();
754
+ callbackOperations = /* @__PURE__ */ new WeakMap();
754
755
  convertedModules = /* @__PURE__ */ new Map();
755
756
  nativeConversions = { seen: /* @__PURE__ */ new WeakMap() };
756
757
  modules;
@@ -784,15 +785,27 @@ var RealmState = class {
784
785
  };
785
786
  captureArguments = (operation, args, copy) => {
786
787
  const from = this.retainedOperations.get(operation)?.from ?? args.length;
787
- const values = copy(args.slice(0, from));
788
+ const owned = this.callbackOperations.has(operation) ? /* @__PURE__ */ new Map() : void 0;
788
789
  const captured = [];
789
790
  const rollback = () => {
790
791
  for (const reference of captured) {
791
792
  revokeGuestReference(reference, this);
792
793
  this.guestReferences.delete(reference);
793
794
  }
795
+ for (const callback of owned?.values() ?? []) {
796
+ revokeGuestCallback(callback, this);
797
+ this.callbacks.delete(callback);
798
+ }
794
799
  };
795
800
  try {
801
+ const values = copy(args.slice(0, from), owned === void 0 ? void 0 : (closure) => {
802
+ let callback = owned.get(closure);
803
+ if (callback === void 0) {
804
+ callback = this.wrapCallback(closure, true);
805
+ owned.set(closure, callback);
806
+ }
807
+ return callback;
808
+ });
796
809
  for (const value of args.slice(from)) {
797
810
  this.checkCollection(
798
811
  this.guestReferences.size + 1,
@@ -1053,9 +1066,9 @@ var RealmState = class {
1053
1066
  }
1054
1067
  return object;
1055
1068
  };
1056
- wrapCallback = (closure) => {
1069
+ wrapCallback = (closure, owned = false) => {
1057
1070
  this.assertOpen();
1058
- const existing = this.callbackCache.get(closure);
1071
+ const existing = owned ? void 0 : this.callbackCache.get(closure);
1059
1072
  if (existing !== void 0 && this.callbacks.has(existing)) return existing;
1060
1073
  this.checkCollection(this.callbacks.size + 1, this.limits.callbacks, "callback");
1061
1074
  const invokeCallback = this.invokeCallback;
@@ -1063,7 +1076,7 @@ var RealmState = class {
1063
1076
  return invokeCallback(callback, { args, thisValue: this });
1064
1077
  };
1065
1078
  this.callbacks.set(callback, closure);
1066
- this.callbackCache.set(closure, callback);
1079
+ if (!owned) this.callbackCache.set(closure, callback);
1067
1080
  registerGuestCallback(callback, {
1068
1081
  owner: this,
1069
1082
  closure,
@@ -1221,6 +1234,20 @@ var RealmState = class {
1221
1234
  invokeCallback: this.invokeCallback,
1222
1235
  releaseCallback: this.releaseCallback,
1223
1236
  releaseGuestReference: this.releaseGuestReference,
1237
+ retainCallbackArguments: (operation) => {
1238
+ this.assertOpen();
1239
+ if (!extension.manifest.capabilities?.includes("guest:retain"))
1240
+ throw new TypeError("Retaining callbacks requires the guest:retain grant.");
1241
+ if (typeof operation !== "function")
1242
+ throw new TypeError("Retained callback operation must be a function.");
1243
+ if (this.scope !== void 0)
1244
+ throw new TypeError("Retained callback operations must be registered during setup.");
1245
+ const owner = this.callbackOperations.get(operation);
1246
+ if (owner !== void 0 && owner !== extension)
1247
+ throw new TypeError("Retained callback operation already belongs to another extension.");
1248
+ this.callbackOperations.set(operation, extension);
1249
+ return operation;
1250
+ },
1224
1251
  retainGuestArguments: (operation, from) => {
1225
1252
  this.assertOpen();
1226
1253
  if (!extension.manifest.capabilities?.includes("guest:retain"))
@@ -2798,4 +2825,4 @@ export {
2798
2825
  UnhandledRejectionError,
2799
2826
  run
2800
2827
  };
2801
- //# sourceMappingURL=chunk-5M2P3GUC.js.map
2828
+ //# sourceMappingURL=chunk-PKRGP34X.js.map