@poe-platform/safe-js 0.1.381 → 0.1.383

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-O3MW27ZJ.js";
30
+ } from "./chunk-XIEVJEAG.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-WEP4P7RG.js.map
8252
+ //# sourceMappingURL=chunk-LUFFFEON.js.map
@@ -8504,6 +8504,41 @@ function copyCollectionProperties(source, target, encode) {
8504
8504
  if (!Object.isExtensible(properties)) Object.preventExtensions(target);
8505
8505
  }
8506
8506
 
8507
+ // packages/safe-js/src/interp/string-iterator.ts
8508
+ var states4 = /* @__PURE__ */ new WeakMap();
8509
+ function isSandboxStringIterator(value) {
8510
+ return typeof value === "object" && value !== null && states4.has(value);
8511
+ }
8512
+ function restoreSandboxStringIterator(state, target = /* @__PURE__ */ Object.create(null)) {
8513
+ validateStringIteratorState(state);
8514
+ states4.set(target, { ...state });
8515
+ return target;
8516
+ }
8517
+ function validateStringIteratorState(state) {
8518
+ if (!Number.isSafeInteger(state.index) || state.index < 0 || (state.input === void 0 ? state.index !== 0 : typeof state.input !== "string" || state.index > state.input.length || state.index > 0 && state.input.codePointAt(state.index - 1) > 65535))
8519
+ throw new TypeError("Invalid String iterator state.");
8520
+ }
8521
+ function stringIteratorState(value) {
8522
+ const state = states4.get(value);
8523
+ if (state === void 0) throw new TypeError("String iterator next requires a String iterator receiver.");
8524
+ return state;
8525
+ }
8526
+ function nextStringIterator(value, budget) {
8527
+ if (!isSandboxStringIterator(value)) throw new TypeError("String iterator next requires a String iterator receiver.");
8528
+ const state = stringIteratorState(value);
8529
+ budget.visitNode();
8530
+ if (state.input === void 0) return { value: void 0, done: true };
8531
+ if (state.index >= state.input.length) {
8532
+ state.input = void 0;
8533
+ state.index = 0;
8534
+ return { value: void 0, done: true };
8535
+ }
8536
+ const width = state.input.codePointAt(state.index) > 65535 ? 2 : 1;
8537
+ const entry = budget.allocateString(state.input.slice(state.index, state.index + width));
8538
+ state.index += width;
8539
+ return { value: entry, done: false };
8540
+ }
8541
+
8507
8542
  // packages/safe-js/src/interp/raw-json.ts
8508
8543
  var rawJsonValues = /* @__PURE__ */ new WeakSet();
8509
8544
  function createRawJson(text) {
@@ -9746,7 +9781,8 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9746
9781
  const key = asyncProtocol ? Symbol.asyncIterator : Symbol.iterator;
9747
9782
  if (context.getProperty === void 0 || isGuestHostObject(value))
9748
9783
  return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
9749
- if (getSandboxPropertyDescriptor(value, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
9784
+ const lookupTarget = value !== void 0 && value !== null && typeof value !== "object" ? getBoxedPrototype(value, budget) : value;
9785
+ if (getSandboxPropertyDescriptor(lookupTarget, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
9750
9786
  if (isSandboxGenerator(value)) {
9751
9787
  if (!hasExplicitSandboxPrototype(value) && value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
9752
9788
  return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
@@ -13353,6 +13389,36 @@ function createPrimitiveConstructor(options, budget) {
13353
13389
  }
13354
13390
  for (const [name, value] of methods2)
13355
13391
  Object.defineProperty(prototype, name, { value, writable: true, configurable: true });
13392
+ if (kind === "string") {
13393
+ const iteratorPrototype = /* @__PURE__ */ Object.create(null);
13394
+ setSandboxPrototype(iteratorPrototype, resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]'));
13395
+ Object.defineProperties(iteratorPrototype, {
13396
+ next: { value: createSandboxClosure({
13397
+ guest: true,
13398
+ sandbox: true,
13399
+ name: "next",
13400
+ length: 0,
13401
+ call: (_args, context) => nextStringIterator(context?.thisValue, budget)
13402
+ }), writable: true, configurable: true },
13403
+ [Symbol.toStringTag]: { value: "String Iterator", configurable: true }
13404
+ });
13405
+ registerBuiltinIdentities(budget, { "%StringIteratorPrototype%": iteratorPrototype });
13406
+ registerIntrinsicObject(budget, iteratorPrototype);
13407
+ Object.defineProperty(prototype, Symbol.iterator, { value: createSandboxClosure({
13408
+ guest: true,
13409
+ sandbox: true,
13410
+ name: "[Symbol.iterator]",
13411
+ length: 0,
13412
+ call: async (_args, context) => {
13413
+ const receiver = context?.thisValue;
13414
+ if (receiver === null || receiver === void 0) throw new TypeError("String iterator requires a receiver.");
13415
+ const input = await sandboxString(receiver, budget, context);
13416
+ const iterator = restoreSandboxStringIterator({ input, index: 0 });
13417
+ setSandboxPrototype(iterator, iteratorPrototype, budget);
13418
+ return iterator;
13419
+ }
13420
+ }), writable: true, configurable: true });
13421
+ }
13356
13422
  installBoxedPrototype(budget, prototype, constructor);
13357
13423
  return constructor;
13358
13424
  }
@@ -14975,6 +15041,18 @@ function createArrayGlobal(budget) {
14975
15041
  const statics = {
14976
15042
  isArray: createSandboxClosure({ sandbox: true, name: "isArray", call: ([value]) => Array.isArray(value) }),
14977
15043
  from: createSandboxClosure({ sandbox: true, name: "from", call: (args, context) => arrayFromSandboxValues(args, budget, context) }),
15044
+ fromAsync: createSandboxClosure({
15045
+ guest: true,
15046
+ sandbox: true,
15047
+ name: "fromAsync",
15048
+ length: 1,
15049
+ call: (args, context) => executeAsyncFunction(
15050
+ (onSuspend) => arrayFromSandboxValues(args, budget, context, onSuspend),
15051
+ budget,
15052
+ void 0,
15053
+ context
15054
+ )
15055
+ }),
14978
15056
  of: createSandboxClosure({
14979
15057
  guest: true,
14980
15058
  sandbox: true,
@@ -15261,7 +15339,17 @@ function defineDataProperty(target, key, descriptor, budget, context, throwOnFai
15261
15339
  function isAssignableSandboxTarget(value) {
15262
15340
  return typeof value === "object" && value !== null && !isSandboxClosure(value) && !isSandboxGenerator(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isSandboxPromise(value) && !isSandboxRegex(value);
15263
15341
  }
15264
- async function arrayFromSandboxValues(args, budget, context) {
15342
+ async function arrayFromSandboxValues(args, budget, context, onSuspend) {
15343
+ const asyncProtocol = onSuspend !== void 0;
15344
+ const awaitAsync = async (pending) => {
15345
+ onSuspend();
15346
+ const leaveAwait = budget.enterAwait();
15347
+ try {
15348
+ return await suspendJob(pending);
15349
+ } finally {
15350
+ leaveAwait();
15351
+ }
15352
+ };
15265
15353
  const [items, mapFn, thisValue] = args;
15266
15354
  if (mapFn !== void 0 && !isSandboxClosure(mapFn)) {
15267
15355
  throw new TypeError("Array.from mapping callback must be a function.");
@@ -15270,11 +15358,11 @@ async function arrayFromSandboxValues(args, budget, context) {
15270
15358
  throw new TypeError("Array.from requires a non-null input.");
15271
15359
  }
15272
15360
  const read = (property) => context?.getProperty !== void 0 ? context.getProperty(items, property) : getSandboxDataProperty(items, property, budget);
15273
- const observableMethod = context?.getProperty !== void 0 && !isGuestHostObject(items) && getSandboxPropertyDescriptor(typeof items === "object" ? items : getBoxedPrototype(items, budget), Symbol.iterator, budget) !== void 0;
15361
+ const observableMethod = !asyncProtocol && context?.getProperty !== void 0 && !isGuestHostObject(items) && getSandboxPropertyDescriptor(typeof items === "object" ? items : getBoxedPrototype(items, budget), Symbol.iterator, budget) !== void 0;
15274
15362
  const iteratorMethod = observableMethod ? await context.getProperty(items, Symbol.iterator) : void 0;
15275
15363
  if (iteratorMethod !== null && iteratorMethod !== void 0 && !isSandboxClosure(iteratorMethod) && typeof iteratorMethod !== "function")
15276
15364
  throw new TypeError("Iterator method must be callable.");
15277
- let iterator = observableMethod ? void 0 : context === void 0 ? getSandboxIterator(items, budget) : await acquireSandboxIterator(items, budget, context);
15365
+ let iterator = observableMethod ? void 0 : context === void 0 ? asyncProtocol ? getSandboxAsyncIterator(items, budget) : getSandboxIterator(items, budget) : await acquireSandboxIterator(items, budget, context, asyncProtocol);
15278
15366
  const iterable = observableMethod ? iteratorMethod !== null && iteratorMethod !== void 0 : iterator !== void 0;
15279
15367
  const constructor = context?.thisValue;
15280
15368
  let result;
@@ -15282,10 +15370,13 @@ async function arrayFromSandboxValues(args, budget, context) {
15282
15370
  let failure;
15283
15371
  const retained = {};
15284
15372
  budget.setRetainedValues(retained, () => [
15285
- items,
15373
+ // Once acquired, a rooted protocol iterator owns the remaining input. Keep
15374
+ // the original only for array-like reads or implicit unrooted iterators.
15375
+ iterator?.retainedValue === void 0 ? items : void 0,
15286
15376
  iteratorMethod,
15287
15377
  iterator?.retainedValue,
15288
15378
  mapFn,
15379
+ thisValue,
15289
15380
  constructor,
15290
15381
  result,
15291
15382
  currentValue,
@@ -15328,17 +15419,19 @@ async function arrayFromSandboxValues(args, budget, context) {
15328
15419
  await closeOnThrow(error);
15329
15420
  }
15330
15421
  if (iterator !== void 0) {
15331
- const next = await iterator.next();
15422
+ const pending = Promise.resolve(iterator.next());
15423
+ const next = await (asyncProtocol ? awaitAsync(pending) : pending);
15332
15424
  if (typeof next !== "object" || next === null)
15333
15425
  throw new TypeError("Iterator result must be an object.");
15334
15426
  if ((await readIteratorResult(iterator, next, "done")).value) break;
15335
15427
  currentValue = (await readIteratorResult(iterator, next, "value")).value;
15336
15428
  } else {
15337
15429
  currentValue = await read(index);
15430
+ if (asyncProtocol) currentValue = await awaitAsync(awaitSandboxValue(currentValue, void 0, budget, context));
15338
15431
  }
15339
15432
  try {
15340
15433
  if (Array.isArray(result)) budget.allocateArrayLength(index + 1);
15341
- if (mapFn !== void 0)
15434
+ if (mapFn !== void 0) {
15342
15435
  currentValue = await invokeBuiltinClosure(
15343
15436
  mapFn,
15344
15437
  [currentValue, index],
@@ -15346,6 +15439,8 @@ async function arrayFromSandboxValues(args, budget, context) {
15346
15439
  context,
15347
15440
  thisValue
15348
15441
  );
15442
+ if (asyncProtocol) currentValue = await awaitAsync(awaitSandboxValue(currentValue, void 0, budget, context));
15443
+ }
15349
15444
  const key = String(index);
15350
15445
  const growth = key.length + 1 + (Array.isArray(result) ? Math.max(0, index + 1 - result.length) : 0) + (budget.limits.dataSize === void 0 ? 0 : measureSandboxData([currentValue]));
15351
15446
  budget.visitNode();
@@ -21924,6 +22019,10 @@ function serializeCollectionProperties(value, encode, dataOnly = false) {
21924
22019
  function captureGuestHeapNode(value, encode) {
21925
22020
  if (isSandboxModuleNamespace(value))
21926
22021
  return { kind: "module-namespace", entries: Object.keys(value).map((key) => [key, encode(value[key])]) };
22022
+ if (isSandboxStringIterator(value)) {
22023
+ const cursor = stringIteratorState(value);
22024
+ return { kind: "string-iterator", input: encode(cursor.input), index: cursor.index, state: captureObjectState(value, encode) };
22025
+ }
21927
22026
  if (isRawJson(value)) return { kind: "raw-json", text: value.rawJSON };
21928
22027
  const intrinsic = getIntrinsicIdentity(value);
21929
22028
  if (intrinsic !== void 0) {
@@ -26870,7 +26969,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26870
26969
  createRawJson(node.text);
26871
26970
  return true;
26872
26971
  }
26873
- if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
26972
+ if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-iterator", "map", "set"].includes(String(node.kind))) return false;
26874
26973
  const reference = (value, kinds) => {
26875
26974
  const ref = record3(value);
26876
26975
  fields(ref, ["kind", "id"]);
@@ -26928,6 +27027,13 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26928
27027
  fields(node, ["kind", "id"], ["state"]);
26929
27028
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
26930
27029
  if (Object.hasOwn(node, "state")) state(node.state);
27030
+ } else if (node.kind === "string-iterator") {
27031
+ fields(node, ["kind", "input", "index", "state"]);
27032
+ const index = integer(node.index);
27033
+ if (typeof node.input !== "string" && !absent(node.input))
27034
+ throw new TypeError("Invalid String iterator state.");
27035
+ validateStringIteratorState({ input: typeof node.input === "string" ? node.input : void 0, index });
27036
+ state(node.state);
26931
27037
  } else if (node.kind === "array-iterator") {
26932
27038
  fields(node, ["kind", "source", "index", "method", "state"]);
26933
27039
  integer(node.index);
@@ -28734,7 +28840,7 @@ var structuredCloneErrorNames = ["Error", "EvalError", "RangeError", "ReferenceE
28734
28840
  function* cloneStructuredGraph(value, state, budget, depth = 0) {
28735
28841
  assertSandboxDataDepth(depth);
28736
28842
  budget.visitNode();
28737
- if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxArguments(value))
28843
+ if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxStringIterator(value) || isSandboxArguments(value))
28738
28844
  throw new DOMException("Value cannot be structured cloned.", "DataCloneError");
28739
28845
  if (typeof value !== "object" || value === null) return allocateProducedSandboxValue(value, budget);
28740
28846
  if (isLiveCapability(value)) throw new DOMException("Capabilities cannot be structured cloned.", "DataCloneError");
@@ -28921,6 +29027,7 @@ function measureSandboxData(values, options = {}) {
28921
29027
  return;
28922
29028
  }
28923
29029
  if (isSandboxArrayIterator(value)) visit(arrayIteratorState(value).source, depth + 1);
29030
+ if (isSandboxStringIterator(value)) visit(stringIteratorState(value).input, depth + 1);
28924
29031
  if (isSandboxRegExpIterator(value)) {
28925
29032
  const state = regexpIteratorState(value);
28926
29033
  visit(state.matcher, depth + 1);
@@ -29118,7 +29225,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29118
29225
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
29119
29226
  return value;
29120
29227
  }
29121
- if (isSandboxArrayIterator(value)) {
29228
+ if (isSandboxArrayIterator(value) || isSandboxStringIterator(value)) {
29122
29229
  if (!cloneSandboxCollections) return value;
29123
29230
  throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
29124
29231
  }
@@ -29598,7 +29705,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
29598
29705
  if (isSandboxGenerator(value)) {
29599
29706
  throw new TypeError("Sandbox generators cannot cross into host values.");
29600
29707
  }
29601
- if (isSandboxArrayIterator(value)) throw new TypeError("Sandbox Array iterators cannot cross into host values.");
29708
+ if (isSandboxArrayIterator(value) || isSandboxStringIterator(value)) throw new TypeError("Sandbox iterators cannot cross into host values.");
29602
29709
  if (isSandboxCollectionIterator(value)) {
29603
29710
  throw new TypeError("Sandbox collection iterators cannot cross into host values.");
29604
29711
  }
@@ -43984,4 +44091,4 @@ export {
43984
44091
  FileSnapshotBackend,
43985
44092
  run
43986
44093
  };
43987
- //# sourceMappingURL=chunk-O3MW27ZJ.js.map
44094
+ //# sourceMappingURL=chunk-XIEVJEAG.js.map