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