@poe-platform/safe-js 0.1.387 → 0.1.389
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-KSILYYRR.js → chunk-6Y27XODE.js} +174 -3
- package/dist/safe-js/chunks/chunk-6Y27XODE.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-D6I4WNJU.js → chunk-LUBKSEVF.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/dist/safe-js/snapshot/guest-heap.d.ts +5 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-KSILYYRR.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-D6I4WNJU.js.map → chunk-LUBKSEVF.js.map} +0 -0
|
@@ -8546,6 +8546,9 @@ function nextStringIterator(value, budget) {
|
|
|
8546
8546
|
return { value: entry, done: false };
|
|
8547
8547
|
}
|
|
8548
8548
|
|
|
8549
|
+
// packages/safe-js/src/interp/iterator-wrapper.ts
|
|
8550
|
+
var iteratorWrapperStates = /* @__PURE__ */ new WeakMap();
|
|
8551
|
+
|
|
8549
8552
|
// packages/safe-js/src/interp/raw-json.ts
|
|
8550
8553
|
var rawJsonValues = /* @__PURE__ */ new WeakSet();
|
|
8551
8554
|
function createRawJson(text) {
|
|
@@ -22030,6 +22033,9 @@ function serializeCollectionProperties(value, encode, dataOnly = false) {
|
|
|
22030
22033
|
|
|
22031
22034
|
// packages/safe-js/src/snapshot/guest-heap.ts
|
|
22032
22035
|
function captureGuestHeapNode(value, encode) {
|
|
22036
|
+
const wrapper = iteratorWrapperStates.get(value);
|
|
22037
|
+
if (wrapper !== void 0)
|
|
22038
|
+
return { kind: "iterator-wrapper", iterator: encode(wrapper.iterator), next: encode(wrapper.next), state: captureObjectState(value, encode) };
|
|
22033
22039
|
if (isSandboxModuleNamespace(value))
|
|
22034
22040
|
return { kind: "module-namespace", entries: Object.keys(value).map((key) => [key, encode(value[key])]) };
|
|
22035
22041
|
if (isSandboxStringIterator(value)) {
|
|
@@ -26347,6 +26353,159 @@ function createGeneratorPrototypes(budget) {
|
|
|
26347
26353
|
generatorPrototypes.set(budget, state);
|
|
26348
26354
|
}
|
|
26349
26355
|
|
|
26356
|
+
// packages/safe-js/src/interp/globals/iterator-from.ts
|
|
26357
|
+
function installIteratorFrom(constructor, budget) {
|
|
26358
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
26359
|
+
setSandboxPrototype(prototype, resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]'));
|
|
26360
|
+
for (const name of ["next", "return"]) {
|
|
26361
|
+
Object.defineProperty(prototype, name, { writable: true, configurable: true, value: createSandboxClosure({
|
|
26362
|
+
guest: true,
|
|
26363
|
+
sandbox: true,
|
|
26364
|
+
name,
|
|
26365
|
+
length: 0,
|
|
26366
|
+
call: async (_args, context) => {
|
|
26367
|
+
const receiver = context?.thisValue;
|
|
26368
|
+
const state = receiver !== null && typeof receiver === "object" ? iteratorWrapperStates.get(receiver) : void 0;
|
|
26369
|
+
if (state === void 0) throw new TypeError("Iterator wrapper method requires a branded receiver.");
|
|
26370
|
+
const method = name === "next" ? state.next : await read(state.iterator, "return", context);
|
|
26371
|
+
if (name === "return" && (method === void 0 || method === null)) return { value: void 0, done: true };
|
|
26372
|
+
if (!isSandboxClosure(method)) throw new TypeError("Iterator method must be callable.");
|
|
26373
|
+
return invokeBuiltinClosure(method, [], budget, context, state.iterator);
|
|
26374
|
+
}
|
|
26375
|
+
}) });
|
|
26376
|
+
}
|
|
26377
|
+
const from = createSandboxClosure({ guest: true, sandbox: true, name: "from", length: 1, call: async ([input], context) => {
|
|
26378
|
+
if (input === null || typeof input !== "object" && typeof input !== "string")
|
|
26379
|
+
throw new TypeError("Iterator.from requires an object or string.");
|
|
26380
|
+
let iterator = input;
|
|
26381
|
+
let next;
|
|
26382
|
+
const release = retainValues(budget, () => [input, iterator, next]);
|
|
26383
|
+
try {
|
|
26384
|
+
const method = await read(input, Symbol.iterator, context);
|
|
26385
|
+
if (method !== void 0 && method !== null) {
|
|
26386
|
+
if (!isSandboxClosure(method)) throw new TypeError("Symbol.iterator must be callable.");
|
|
26387
|
+
iterator = await invokeBuiltinClosure(method, [], budget, context, input);
|
|
26388
|
+
}
|
|
26389
|
+
if (iterator === null || typeof iterator !== "object") throw new TypeError("Iterator must be an object.");
|
|
26390
|
+
next = await read(iterator, "next", context);
|
|
26391
|
+
if (await ordinaryHasInstance(iterator, constructor, budget, context)) return iterator;
|
|
26392
|
+
const wrapper = /* @__PURE__ */ Object.create(null);
|
|
26393
|
+
iteratorWrapperStates.set(wrapper, { iterator, next });
|
|
26394
|
+
setSandboxPrototype(wrapper, prototype, budget);
|
|
26395
|
+
createDataCheckpoint(budget, context)(wrapper, 0, true);
|
|
26396
|
+
return wrapper;
|
|
26397
|
+
} finally {
|
|
26398
|
+
release();
|
|
26399
|
+
}
|
|
26400
|
+
} });
|
|
26401
|
+
Object.defineProperty(materializeFunctionProperties(constructor), "from", { value: from, writable: true, configurable: true });
|
|
26402
|
+
registerBuiltinIdentities(budget, { Iterator: constructor, "%WrapForValidIteratorPrototype%": prototype });
|
|
26403
|
+
registerIntrinsicFunction(budget, from);
|
|
26404
|
+
registerIntrinsicObject(budget, prototype);
|
|
26405
|
+
async function read(value, key, context) {
|
|
26406
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
26407
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
26408
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
|
|
26409
|
+
}
|
|
26410
|
+
}
|
|
26411
|
+
|
|
26412
|
+
// packages/safe-js/src/interp/globals/iterator-consumers.ts
|
|
26413
|
+
function installIteratorConsumers(prototype, budget) {
|
|
26414
|
+
for (const name of ["toArray", "reduce", "forEach", "some", "every", "find"]) {
|
|
26415
|
+
Object.defineProperty(prototype, name, { writable: true, configurable: true, value: createSandboxClosure({
|
|
26416
|
+
guest: true,
|
|
26417
|
+
sandbox: true,
|
|
26418
|
+
name,
|
|
26419
|
+
length: name === "toArray" ? 0 : 1,
|
|
26420
|
+
call: async (args, context) => {
|
|
26421
|
+
const receiver = context?.thisValue;
|
|
26422
|
+
if (receiver === null || typeof receiver !== "object") throw new TypeError("Iterator consumer requires an object.");
|
|
26423
|
+
const callback = args[0];
|
|
26424
|
+
let next;
|
|
26425
|
+
let accumulator = args[1];
|
|
26426
|
+
let value;
|
|
26427
|
+
const values = [];
|
|
26428
|
+
const release = retainValues(budget, () => [receiver, callback, next, accumulator, value, values]);
|
|
26429
|
+
const checkpoint = createDataCheckpoint(budget, context);
|
|
26430
|
+
const iterator = {
|
|
26431
|
+
asynchronous: true,
|
|
26432
|
+
next: async () => {
|
|
26433
|
+
if (!isSandboxClosure(next)) throw new TypeError("Iterator next must be callable.");
|
|
26434
|
+
const result = await invokeBuiltinClosure(next, [], budget, context, receiver);
|
|
26435
|
+
if (result === null || typeof result !== "object") throw new TypeError("Iterator result must be an object.");
|
|
26436
|
+
return result;
|
|
26437
|
+
},
|
|
26438
|
+
getOperation: async () => {
|
|
26439
|
+
const method = await read(receiver, "return", context);
|
|
26440
|
+
if (method === void 0 || method === null) return void 0;
|
|
26441
|
+
if (!isSandboxClosure(method)) throw new TypeError("Iterator return must be callable.");
|
|
26442
|
+
return async () => await invokeBuiltinClosure(method, [], budget, context, receiver);
|
|
26443
|
+
}
|
|
26444
|
+
};
|
|
26445
|
+
try {
|
|
26446
|
+
if (name !== "toArray" && !isSandboxClosure(callback)) {
|
|
26447
|
+
await closeIterator(iterator, true);
|
|
26448
|
+
throw new TypeError("Iterator callback must be callable.");
|
|
26449
|
+
}
|
|
26450
|
+
next = await read(receiver, "next", context);
|
|
26451
|
+
let initialized = name !== "reduce" || args.length > 1;
|
|
26452
|
+
let index = 0;
|
|
26453
|
+
while (true) {
|
|
26454
|
+
budget.visitNode();
|
|
26455
|
+
const result = await iterator.next();
|
|
26456
|
+
if (await read(result, "done", context)) {
|
|
26457
|
+
if (!initialized) throw new TypeError("Cannot reduce an empty iterator without an initial value.");
|
|
26458
|
+
if (name === "toArray") return values;
|
|
26459
|
+
if (name === "reduce") return accumulator;
|
|
26460
|
+
if (name === "some") return false;
|
|
26461
|
+
if (name === "every") return true;
|
|
26462
|
+
return void 0;
|
|
26463
|
+
}
|
|
26464
|
+
value = await read(result, "value", context);
|
|
26465
|
+
if (name === "toArray") {
|
|
26466
|
+
values.push(value);
|
|
26467
|
+
checkpoint(values, 0, true);
|
|
26468
|
+
} else if (!initialized) {
|
|
26469
|
+
accumulator = value;
|
|
26470
|
+
initialized = true;
|
|
26471
|
+
} else {
|
|
26472
|
+
let selected;
|
|
26473
|
+
try {
|
|
26474
|
+
selected = await invokeBuiltinClosure(
|
|
26475
|
+
callback,
|
|
26476
|
+
name === "reduce" ? [accumulator, value, index] : [value, index],
|
|
26477
|
+
budget,
|
|
26478
|
+
context,
|
|
26479
|
+
void 0
|
|
26480
|
+
);
|
|
26481
|
+
} catch (error) {
|
|
26482
|
+
if (!isFatalSandboxError(error)) await closeIterator(iterator, true);
|
|
26483
|
+
throw error;
|
|
26484
|
+
}
|
|
26485
|
+
if (name === "reduce") accumulator = selected;
|
|
26486
|
+
else if ((name === "some" || name === "find") && selected || name === "every" && !selected) {
|
|
26487
|
+
await closeIterator(iterator);
|
|
26488
|
+
return name === "find" ? value : name === "some";
|
|
26489
|
+
}
|
|
26490
|
+
}
|
|
26491
|
+
value = void 0;
|
|
26492
|
+
index++;
|
|
26493
|
+
}
|
|
26494
|
+
} finally {
|
|
26495
|
+
release();
|
|
26496
|
+
}
|
|
26497
|
+
}
|
|
26498
|
+
}) });
|
|
26499
|
+
}
|
|
26500
|
+
registerBuiltinIdentities(budget, { "%IteratorPrototype%": prototype });
|
|
26501
|
+
registerIntrinsicObject(budget, prototype);
|
|
26502
|
+
async function read(value, key, context) {
|
|
26503
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key);
|
|
26504
|
+
const descriptor = getSandboxPropertyDescriptor(value, key, budget);
|
|
26505
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, context);
|
|
26506
|
+
}
|
|
26507
|
+
}
|
|
26508
|
+
|
|
26350
26509
|
// packages/safe-js/src/interp/globals/iterator.ts
|
|
26351
26510
|
function createIteratorGlobal(budget) {
|
|
26352
26511
|
const prototype = resolveIntrinsicIdentity(budget, '["%IteratorPrototype%"]');
|
|
@@ -26384,6 +26543,8 @@ function createIteratorGlobal(budget) {
|
|
|
26384
26543
|
Object.defineProperty(prototype, "constructor", { get: accessorAdapter(getter, "get"), set: accessorAdapter(setter, "set"), configurable: true });
|
|
26385
26544
|
registerIntrinsicFunction(budget, getter);
|
|
26386
26545
|
registerIntrinsicFunction(budget, setter);
|
|
26546
|
+
installIteratorFrom(constructor, budget);
|
|
26547
|
+
installIteratorConsumers(prototype, budget);
|
|
26387
26548
|
registerIntrinsicFunction(budget, constructor);
|
|
26388
26549
|
registerIntrinsicObject(budget, prototype);
|
|
26389
26550
|
return constructor;
|
|
@@ -27089,7 +27250,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
27089
27250
|
createRawJson(node.text);
|
|
27090
27251
|
return true;
|
|
27091
27252
|
}
|
|
27092
|
-
if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-iterator", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
27253
|
+
if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "string-iterator", "iterator-wrapper", "guest-collection-iterator", "guest-regexp-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
27093
27254
|
const reference = (value, kinds) => {
|
|
27094
27255
|
const ref = record3(value);
|
|
27095
27256
|
fields(ref, ["kind", "id"]);
|
|
@@ -27143,7 +27304,12 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
27143
27304
|
});
|
|
27144
27305
|
return false;
|
|
27145
27306
|
}
|
|
27146
|
-
if (node.kind === "
|
|
27307
|
+
if (node.kind === "iterator-wrapper") {
|
|
27308
|
+
fields(node, ["kind", "iterator", "next", "state"]);
|
|
27309
|
+
const iterator = reference(node.iterator);
|
|
27310
|
+
if (iterator.kind === "symbol" || iterator.kind === "scope-frame") throw new TypeError("Invalid wrapped iterator.");
|
|
27311
|
+
state(node.state);
|
|
27312
|
+
} else if (node.kind === "intrinsic") {
|
|
27147
27313
|
fields(node, ["kind", "id"], ["state"]);
|
|
27148
27314
|
if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
|
|
27149
27315
|
if (Object.hasOwn(node, "state")) state(node.state);
|
|
@@ -29108,6 +29274,11 @@ function measureSandboxData(values, options = {}) {
|
|
|
29108
29274
|
}
|
|
29109
29275
|
return;
|
|
29110
29276
|
}
|
|
29277
|
+
const wrapperState = iteratorWrapperStates.get(value);
|
|
29278
|
+
if (wrapperState !== void 0) {
|
|
29279
|
+
visit(wrapperState.iterator, depth + 1);
|
|
29280
|
+
visit(wrapperState.next, depth + 1);
|
|
29281
|
+
}
|
|
29111
29282
|
if (isSandboxDate(value)) usage += 8;
|
|
29112
29283
|
if (isGuestHostObject(value)) {
|
|
29113
29284
|
usage += measureHostObjectData(value);
|
|
@@ -44237,4 +44408,4 @@ export {
|
|
|
44237
44408
|
FileSnapshotBackend,
|
|
44238
44409
|
run
|
|
44239
44410
|
};
|
|
44240
|
-
//# sourceMappingURL=chunk-
|
|
44411
|
+
//# sourceMappingURL=chunk-6Y27XODE.js.map
|