@poe-platform/safe-js 0.1.296 → 0.1.298

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-2Y6SJCIT.js";
30
+ } from "./chunk-BGSPSHLP.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-BXVBZMIN.js.map
8252
+ //# sourceMappingURL=chunk-2MU4KXPO.js.map
@@ -6839,8 +6839,9 @@ function float32DataProperties(value) {
6839
6839
  if (Object.getOwnPropertySymbols(value).length > 0)
6840
6840
  throw new TypeError("Float32Array symbol properties are not supported.");
6841
6841
  const properties = [];
6842
- for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
6842
+ for (const key of Object.getOwnPropertyNames(value)) {
6843
6843
  if (isFloat32Index(key)) continue;
6844
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
6844
6845
  if (!("value" in descriptor))
6845
6846
  throw new TypeError(`Float32Array accessor property '${key}' is not supported.`);
6846
6847
  properties.push([key, descriptor]);
@@ -7163,11 +7164,28 @@ function nativeIterator(collection, method) {
7163
7164
  return collection.kind === "map" ? collection.entries[method]() : collection.values[method]();
7164
7165
  }
7165
7166
 
7166
- // packages/safe-js/src/interp/regexp-iterator.ts
7167
+ // packages/safe-js/src/interp/array-iterator.ts
7167
7168
  var states2 = /* @__PURE__ */ new WeakMap();
7168
- function isSandboxRegExpIterator(value) {
7169
+ function isSandboxArrayIterator(value) {
7169
7170
  return typeof value === "object" && value !== null && states2.has(value);
7170
7171
  }
7172
+ function restoreSandboxArrayIterator(state, target = /* @__PURE__ */ Object.create(null)) {
7173
+ if (!Number.isSafeInteger(state.index) || state.index < 0 || !["keys", "values", "entries"].includes(state.method) || state.source !== void 0 && (state.source === null || typeof state.source !== "object"))
7174
+ throw new TypeError("Invalid Array iterator state.");
7175
+ states2.set(target, { ...state });
7176
+ return target;
7177
+ }
7178
+ function arrayIteratorState(value) {
7179
+ const state = states2.get(value);
7180
+ if (state === void 0) throw new TypeError("Array iterator next requires an Array iterator receiver.");
7181
+ return state;
7182
+ }
7183
+
7184
+ // packages/safe-js/src/interp/regexp-iterator.ts
7185
+ var states3 = /* @__PURE__ */ new WeakMap();
7186
+ function isSandboxRegExpIterator(value) {
7187
+ return typeof value === "object" && value !== null && states3.has(value);
7188
+ }
7171
7189
  function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.create(null)) {
7172
7190
  if ((state.global !== void 0 || state.unicode !== void 0) && (typeof state.global !== "boolean" || typeof state.unicode !== "boolean"))
7173
7191
  throw new TypeError("Invalid RegExp iterator modes.");
@@ -7175,11 +7193,11 @@ function restoreSandboxRegExpIterator(state, target = /* @__PURE__ */ Object.cre
7175
7193
  throw new TypeError("Invalid RegExp iterator matcher.");
7176
7194
  if (!state.exhausted && (state.matcher === void 0 || state.input === void 0))
7177
7195
  throw new TypeError("A live RegExp iterator requires its matcher and input.");
7178
- states2.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
7196
+ states3.set(target, state.exhausted ? { ...state, matcher: void 0, input: void 0, exhausted: true } : { ...state });
7179
7197
  return target;
7180
7198
  }
7181
7199
  function regexpIteratorState(value) {
7182
- const state = states2.get(value);
7200
+ const state = states3.get(value);
7183
7201
  if (state === void 0) throw new TypeError("Expected a RegExp string iterator.");
7184
7202
  return state;
7185
7203
  }
@@ -7359,6 +7377,7 @@ function graphEntries(value) {
7359
7377
  }
7360
7378
  const entries = [];
7361
7379
  if (isSandboxCollectionIterator(value)) entries.push([".<collection>", collectionIteratorState(value).collection]);
7380
+ if (isSandboxArrayIterator(value)) entries.push([".<source>", arrayIteratorState(value).source]);
7362
7381
  if (isSandboxRegExpIterator(value)) entries.push([".<matcher>", regexpIteratorState(value).matcher]);
7363
7382
  for (const key of Object.keys(value)) {
7364
7383
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
@@ -9375,6 +9394,7 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9375
9394
  if (context.getProperty === void 0 || isGuestHostObject(value))
9376
9395
  return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
9377
9396
  if (getSandboxPropertyDescriptor(value, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
9397
+ if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
9378
9398
  if (!asyncProtocol) return getSandboxIterator(value, budget, context);
9379
9399
  if (isSandboxGenerator(value) && value.async)
9380
9400
  return getSandboxAsyncIterator(value, budget, context, signal);
@@ -9382,6 +9402,11 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
9382
9402
  return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
9383
9403
  }
9384
9404
  const factory = await context.getProperty(value, key);
9405
+ if (!asyncProtocol && factory === void 0 && Array.isArray(value) && !hasExplicitSandboxPrototype(value)) {
9406
+ const installed = getSandboxPropertyDescriptor(value, key, budget)?.value;
9407
+ if (typeof installed === "object" && installed !== null && getIntrinsicIdentity(installed) === JSON.stringify(["Array", "prototype", "values"]))
9408
+ return arrayIterator(value, context, budget);
9409
+ }
9385
9410
  if (!asyncProtocol && (isSandboxMap(value) || isSandboxSet(value)) && typeof factory === "object" && factory !== null && getIntrinsicIdentity(factory) === JSON.stringify(isSandboxMap(value) ? ["Map", "prototype", "entries"] : ["Set", "prototype", "values"])) {
9386
9411
  return getSandboxIterator(value, budget, context);
9387
9412
  }
@@ -10423,6 +10448,33 @@ function createDataCheckpoint(budget, context) {
10423
10448
  };
10424
10449
  }
10425
10450
 
10451
+ // packages/safe-js/src/interp/methods/array-iterator.ts
10452
+ async function nextArrayIterator(value, budget, context) {
10453
+ if (!isSandboxArrayIterator(value)) throw new TypeError("Array iterator next requires an Array iterator receiver.");
10454
+ const state = arrayIteratorState(value);
10455
+ const source = state.source;
10456
+ if (source === void 0) return { value: void 0, done: true };
10457
+ const index = state.index;
10458
+ const release = retainValues(budget, () => [value, source]);
10459
+ const read = (key) => context?.getProperty !== void 0 ? context.getProperty(source, key) : readPropertyDescriptor((isFloat32Array(source) ? Object.getOwnPropertyDescriptor(source, key) : void 0) ?? getSandboxPropertyDescriptor(source, key, budget) ?? { value: void 0 }, source, context);
10460
+ try {
10461
+ budget.visitNode();
10462
+ const number = isFloat32Array(source) ? float32Storage(source).length : await sandboxNumber(await read("length"), budget, context);
10463
+ const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
10464
+ if (index >= length) {
10465
+ state.source = void 0;
10466
+ return { value: void 0, done: true };
10467
+ }
10468
+ state.index = index + 1;
10469
+ if (state.method === "keys") return { value: index, done: false };
10470
+ const entry = await read(String(index));
10471
+ if (state.method === "entries") budget.allocateArrayLength(2);
10472
+ return { value: state.method === "entries" ? [index, entry] : entry, done: false };
10473
+ } finally {
10474
+ release();
10475
+ }
10476
+ }
10477
+
10426
10478
  // packages/safe-js/src/interp/globals/numeric-parsers.ts
10427
10479
  function createNumericParsers(budget) {
10428
10480
  return {
@@ -12729,8 +12781,8 @@ function allocateProducedValue(value, budget, seen) {
12729
12781
  return;
12730
12782
  }
12731
12783
  seen.add(value);
12732
- for (const entry of value) {
12733
- allocateProducedValue(entry, budget, seen);
12784
+ for (let index = 0; index < value.length; index++) {
12785
+ allocateProducedValue(value[index], budget, seen);
12734
12786
  }
12735
12787
  return;
12736
12788
  }
@@ -13115,6 +13167,48 @@ function createArrayGlobal(budget) {
13115
13167
  configurable: true
13116
13168
  });
13117
13169
  Object.defineProperty(prototype, "constructor", { value: constructor, writable: true, configurable: true });
13170
+ const iteratorPrototype = /* @__PURE__ */ Object.create(null);
13171
+ const iterablePrototype = /* @__PURE__ */ Object.create(null);
13172
+ Object.defineProperty(iterablePrototype, Symbol.iterator, { value: createSandboxClosure({
13173
+ guest: true,
13174
+ sandbox: true,
13175
+ name: "[Symbol.iterator]",
13176
+ length: 0,
13177
+ call: (_args, context) => context?.thisValue
13178
+ }), writable: true, configurable: true });
13179
+ setSandboxPrototype(iterablePrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
13180
+ setSandboxPrototype(iteratorPrototype, iterablePrototype);
13181
+ Object.defineProperties(iteratorPrototype, {
13182
+ next: { value: createSandboxClosure({
13183
+ guest: true,
13184
+ sandbox: true,
13185
+ name: "next",
13186
+ length: 0,
13187
+ call: (_args, context) => nextArrayIterator(context?.thisValue, budget, context)
13188
+ }), writable: true, configurable: true },
13189
+ [Symbol.toStringTag]: { value: "Array Iterator", configurable: true }
13190
+ });
13191
+ registerBuiltinIdentities(budget, { "%ArrayIteratorPrototype%": iteratorPrototype, "%IteratorPrototype%": iterablePrototype });
13192
+ registerIntrinsicObject(budget, iterablePrototype);
13193
+ registerIntrinsicObject(budget, iteratorPrototype);
13194
+ for (const method of ["keys", "values", "entries"]) {
13195
+ const closure = createSandboxClosure({
13196
+ guest: true,
13197
+ sandbox: true,
13198
+ name: method,
13199
+ length: 0,
13200
+ call: (_args, context) => {
13201
+ const receiver = context?.thisValue;
13202
+ if (receiver === null || receiver === void 0) throw new TypeError("Array iterator method requires a receiver.");
13203
+ const source = typeof receiver === "object" ? receiver : createSandboxBox(receiver);
13204
+ const iterator = restoreSandboxArrayIterator({ source, index: 0, method });
13205
+ setSandboxPrototype(iterator, iteratorPrototype, budget);
13206
+ return iterator;
13207
+ }
13208
+ });
13209
+ Object.defineProperty(prototype, method, { value: closure, writable: true, configurable: true });
13210
+ if (method === "values") Object.defineProperty(prototype, Symbol.iterator, { value: closure, writable: true, configurable: true });
13211
+ }
13118
13212
  for (const name of arrayMethodNames) {
13119
13213
  const method = createSandboxClosure({
13120
13214
  guest: true,
@@ -20011,6 +20105,16 @@ function captureGuestHeapNode(value, encode) {
20011
20105
  }
20012
20106
  if (isSandboxMap(value)) return { kind: "map", entries: [...value.entries].map(([key, entry]) => [encode(key), encode(entry)]), ...serializeCollectionProperties(value, encode) };
20013
20107
  if (isSandboxSet(value)) return { kind: "set", values: [...value.values].map(encode), ...serializeCollectionProperties(value, encode) };
20108
+ if (isSandboxArrayIterator(value)) {
20109
+ const cursor = arrayIteratorState(value);
20110
+ return {
20111
+ kind: "array-iterator",
20112
+ source: encode(cursor.source),
20113
+ index: cursor.index,
20114
+ method: cursor.method,
20115
+ state: captureObjectState(value, encode)
20116
+ };
20117
+ }
20014
20118
  const classOrigin = classOrigins.get(value);
20015
20119
  if (classOrigin !== void 0) {
20016
20120
  if (!classOrigin.initialized || classOrigin.node.nodeId === void 0)
@@ -24030,7 +24134,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24030
24134
  createRawJson(node.text);
24031
24135
  return true;
24032
24136
  }
24033
- if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "map", "set"].includes(String(node.kind))) return false;
24137
+ if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
24034
24138
  const reference = (value, kinds) => {
24035
24139
  const ref = record3(value);
24036
24140
  fields(ref, ["kind", "id"]);
@@ -24088,6 +24192,15 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
24088
24192
  fields(node, ["kind", "id"], ["state"]);
24089
24193
  if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
24090
24194
  if (Object.hasOwn(node, "state")) state(node.state);
24195
+ } else if (node.kind === "array-iterator") {
24196
+ fields(node, ["kind", "source", "index", "method", "state"]);
24197
+ integer(node.index);
24198
+ if (!["keys", "values", "entries"].includes(String(node.method))) throw new TypeError("Invalid Array iterator method.");
24199
+ if (!absent(node.source)) {
24200
+ const source = reference(node.source);
24201
+ if (source.kind === "scope-frame" || source.kind === "symbol") throw new TypeError("Invalid Array iterator source.");
24202
+ }
24203
+ state(node.state);
24091
24204
  } else if (node.kind === "guest-object" || node.kind === "guest-array") {
24092
24205
  fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
24093
24206
  if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
@@ -25942,6 +26055,7 @@ function measureSandboxData(values, options = {}) {
25942
26055
  }
25943
26056
  return;
25944
26057
  }
26058
+ if (isSandboxArrayIterator(value)) visit(arrayIteratorState(value).source, depth + 1);
25945
26059
  if (isSandboxRegExpIterator(value)) {
25946
26060
  const state = regexpIteratorState(value);
25947
26061
  visit(state.matcher, depth + 1);
@@ -26121,6 +26235,10 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
26121
26235
  if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxPromise(value)) {
26122
26236
  return value;
26123
26237
  }
26238
+ if (isSandboxArrayIterator(value)) {
26239
+ if (!cloneSandboxCollections) return value;
26240
+ throw new TypeError("Array iterators require a portable guest snapshot, not a data copy.");
26241
+ }
26124
26242
  if (isSandboxRegExpIterator(value)) {
26125
26243
  if (hasGuestObjectState(value)) throw new TypeError("Guest prototype links and custom descriptors cannot be copied as data.");
26126
26244
  if (!cloneSandboxCollections) return value;
@@ -26485,6 +26603,7 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
26485
26603
  if (isSandboxGenerator(value)) {
26486
26604
  throw new TypeError("Sandbox generators cannot cross into host values.");
26487
26605
  }
26606
+ if (isSandboxArrayIterator(value)) throw new TypeError("Sandbox Array iterators cannot cross into host values.");
26488
26607
  if (isSandboxCollectionIterator(value)) {
26489
26608
  throw new TypeError("Sandbox collection iterators cannot cross into host values.");
26490
26609
  }
@@ -26607,8 +26726,8 @@ function allocateSandboxValue2(value, budget, seen) {
26607
26726
  }
26608
26727
  seen.add(value);
26609
26728
  budget.allocateArrayLength(value.length);
26610
- for (const entry of value) {
26611
- allocateSandboxValue2(entry, budget, seen);
26729
+ for (let index = 0; index < value.length; index++) {
26730
+ allocateSandboxValue2(value[index], budget, seen);
26612
26731
  }
26613
26732
  return;
26614
26733
  }
@@ -40803,4 +40922,4 @@ export {
40803
40922
  FileSnapshotBackend,
40804
40923
  run
40805
40924
  };
40806
- //# sourceMappingURL=chunk-2Y6SJCIT.js.map
40925
+ //# sourceMappingURL=chunk-BGSPSHLP.js.map