@poe-platform/safe-js 0.1.381 → 0.1.382

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.
@@ -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
  }
@@ -15282,7 +15348,9 @@ async function arrayFromSandboxValues(args, budget, context) {
15282
15348
  let failure;
15283
15349
  const retained = {};
15284
15350
  budget.setRetainedValues(retained, () => [
15285
- items,
15351
+ // Once acquired, a rooted protocol iterator owns the remaining input. Keep
15352
+ // the original only for array-like reads or implicit unrooted iterators.
15353
+ iterator?.retainedValue === void 0 ? items : void 0,
15286
15354
  iteratorMethod,
15287
15355
  iterator?.retainedValue,
15288
15356
  mapFn,
@@ -21924,6 +21992,10 @@ function serializeCollectionProperties(value, encode, dataOnly = false) {
21924
21992
  function captureGuestHeapNode(value, encode) {
21925
21993
  if (isSandboxModuleNamespace(value))
21926
21994
  return { kind: "module-namespace", entries: Object.keys(value).map((key) => [key, encode(value[key])]) };
21995
+ if (isSandboxStringIterator(value)) {
21996
+ const cursor = stringIteratorState(value);
21997
+ return { kind: "string-iterator", input: encode(cursor.input), index: cursor.index, state: captureObjectState(value, encode) };
21998
+ }
21927
21999
  if (isRawJson(value)) return { kind: "raw-json", text: value.rawJSON };
21928
22000
  const intrinsic = getIntrinsicIdentity(value);
21929
22001
  if (intrinsic !== void 0) {
@@ -26870,7 +26942,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26870
26942
  createRawJson(node.text);
26871
26943
  return true;
26872
26944
  }
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;
26945
+ 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
26946
  const reference = (value, kinds) => {
26875
26947
  const ref = record3(value);
26876
26948
  fields(ref, ["kind", "id"]);
@@ -26928,6 +27000,13 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
26928
27000
  fields(node, ["kind", "id"], ["state"]);
26929
27001
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
26930
27002
  if (Object.hasOwn(node, "state")) state(node.state);
27003
+ } else if (node.kind === "string-iterator") {
27004
+ fields(node, ["kind", "input", "index", "state"]);
27005
+ const index = integer(node.index);
27006
+ if (typeof node.input !== "string" && !absent(node.input))
27007
+ throw new TypeError("Invalid String iterator state.");
27008
+ validateStringIteratorState({ input: typeof node.input === "string" ? node.input : void 0, index });
27009
+ state(node.state);
26931
27010
  } else if (node.kind === "array-iterator") {
26932
27011
  fields(node, ["kind", "source", "index", "method", "state"]);
26933
27012
  integer(node.index);
@@ -28734,7 +28813,7 @@ var structuredCloneErrorNames = ["Error", "EvalError", "RangeError", "ReferenceE
28734
28813
  function* cloneStructuredGraph(value, state, budget, depth = 0) {
28735
28814
  assertSandboxDataDepth(depth);
28736
28815
  budget.visitNode();
28737
- if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxArguments(value))
28816
+ if (typeof value === "symbol" || isSandboxModuleNamespace(value) || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxStringIterator(value) || isSandboxArguments(value))
28738
28817
  throw new DOMException("Value cannot be structured cloned.", "DataCloneError");
28739
28818
  if (typeof value !== "object" || value === null) return allocateProducedSandboxValue(value, budget);
28740
28819
  if (isLiveCapability(value)) throw new DOMException("Capabilities cannot be structured cloned.", "DataCloneError");
@@ -28921,6 +29000,7 @@ function measureSandboxData(values, options = {}) {
28921
29000
  return;
28922
29001
  }
28923
29002
  if (isSandboxArrayIterator(value)) visit(arrayIteratorState(value).source, depth + 1);
29003
+ if (isSandboxStringIterator(value)) visit(stringIteratorState(value).input, depth + 1);
28924
29004
  if (isSandboxRegExpIterator(value)) {
28925
29005
  const state = regexpIteratorState(value);
28926
29006
  visit(state.matcher, depth + 1);
@@ -29118,7 +29198,7 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
29118
29198
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
29119
29199
  return value;
29120
29200
  }
29121
- if (isSandboxArrayIterator(value)) {
29201
+ if (isSandboxArrayIterator(value) || isSandboxStringIterator(value)) {
29122
29202
  if (!cloneSandboxCollections) return value;
29123
29203
  throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
29124
29204
  }
@@ -29598,7 +29678,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
29598
29678
  if (isSandboxGenerator(value)) {
29599
29679
  throw new TypeError("Sandbox generators cannot cross into host values.");
29600
29680
  }
29601
- if (isSandboxArrayIterator(value)) throw new TypeError("Sandbox Array iterators cannot cross into host values.");
29681
+ if (isSandboxArrayIterator(value) || isSandboxStringIterator(value)) throw new TypeError("Sandbox iterators cannot cross into host values.");
29602
29682
  if (isSandboxCollectionIterator(value)) {
29603
29683
  throw new TypeError("Sandbox collection iterators cannot cross into host values.");
29604
29684
  }
@@ -43984,4 +44064,4 @@ export {
43984
44064
  FileSnapshotBackend,
43985
44065
  run
43986
44066
  };
43987
- //# sourceMappingURL=chunk-O3MW27ZJ.js.map
44067
+ //# sourceMappingURL=chunk-DRWLAPG6.js.map