@poe-platform/safe-js 0.1.368 → 0.1.369
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-MIIX63EV.js → chunk-54LUHONC.js} +173 -82
- package/dist/safe-js/chunks/chunk-54LUHONC.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-YZVG2IAP.js → chunk-PO624I2M.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/interp/values.d.ts +13 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-MIIX63EV.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-YZVG2IAP.js.map → chunk-PO624I2M.js.map} +0 -0
|
@@ -7360,6 +7360,55 @@ function copyCollectionProperties(source, target, encode) {
|
|
|
7360
7360
|
if (!Object.isExtensible(properties)) Object.preventExtensions(target);
|
|
7361
7361
|
}
|
|
7362
7362
|
|
|
7363
|
+
// packages/safe-js/src/interp/resources.ts
|
|
7364
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7365
|
+
var runResources = new AsyncLocalStorage();
|
|
7366
|
+
function retainValues(budget, values) {
|
|
7367
|
+
const retained = {};
|
|
7368
|
+
budget.setRetainedValues(retained, values);
|
|
7369
|
+
const pending = runResources.getStore()?.referenceReleases;
|
|
7370
|
+
const release = () => {
|
|
7371
|
+
budget.setRetainedValues(retained, void 0);
|
|
7372
|
+
pending?.delete(release);
|
|
7373
|
+
};
|
|
7374
|
+
pending?.add(release);
|
|
7375
|
+
return release;
|
|
7376
|
+
}
|
|
7377
|
+
async function withRunResources(signal, execute) {
|
|
7378
|
+
const controller = new AbortController();
|
|
7379
|
+
const cancel = () => controller.abort(signal?.reason);
|
|
7380
|
+
const cleanups = /* @__PURE__ */ new Set();
|
|
7381
|
+
const resources = {
|
|
7382
|
+
signal: controller.signal,
|
|
7383
|
+
referenceReleases: /* @__PURE__ */ new Set(),
|
|
7384
|
+
add(close) {
|
|
7385
|
+
cleanups.add(close);
|
|
7386
|
+
}
|
|
7387
|
+
};
|
|
7388
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
7389
|
+
if (signal?.aborted) cancel();
|
|
7390
|
+
let result;
|
|
7391
|
+
let failure;
|
|
7392
|
+
let errors = [];
|
|
7393
|
+
try {
|
|
7394
|
+
result = await runResources.run(resources, execute);
|
|
7395
|
+
} catch (error) {
|
|
7396
|
+
failure = { reason: error };
|
|
7397
|
+
} finally {
|
|
7398
|
+
signal?.removeEventListener("abort", cancel);
|
|
7399
|
+
controller.abort(new Error("SafeJS run finished."));
|
|
7400
|
+
for (const release of resources.referenceReleases) release();
|
|
7401
|
+
resources.referenceReleases.clear();
|
|
7402
|
+
const outcomes = await Promise.allSettled(
|
|
7403
|
+
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
7404
|
+
);
|
|
7405
|
+
errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
7406
|
+
}
|
|
7407
|
+
if (failure !== void 0) throw failure.reason;
|
|
7408
|
+
if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
|
|
7409
|
+
return result;
|
|
7410
|
+
}
|
|
7411
|
+
|
|
7363
7412
|
// packages/safe-js/src/interp/collection-brands.ts
|
|
7364
7413
|
var sandboxMapBrand = /* @__PURE__ */ Symbol("SandboxMap");
|
|
7365
7414
|
var sandboxSetBrand = /* @__PURE__ */ Symbol("SandboxSet");
|
|
@@ -7654,55 +7703,6 @@ function graphEntries(value) {
|
|
|
7654
7703
|
// packages/safe-js/src/interp/generator-prototypes.ts
|
|
7655
7704
|
var generatorPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7656
7705
|
|
|
7657
|
-
// packages/safe-js/src/interp/resources.ts
|
|
7658
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7659
|
-
var runResources = new AsyncLocalStorage();
|
|
7660
|
-
function retainValues(budget, values) {
|
|
7661
|
-
const retained = {};
|
|
7662
|
-
budget.setRetainedValues(retained, values);
|
|
7663
|
-
const pending = runResources.getStore()?.referenceReleases;
|
|
7664
|
-
const release = () => {
|
|
7665
|
-
budget.setRetainedValues(retained, void 0);
|
|
7666
|
-
pending?.delete(release);
|
|
7667
|
-
};
|
|
7668
|
-
pending?.add(release);
|
|
7669
|
-
return release;
|
|
7670
|
-
}
|
|
7671
|
-
async function withRunResources(signal, execute) {
|
|
7672
|
-
const controller = new AbortController();
|
|
7673
|
-
const cancel = () => controller.abort(signal?.reason);
|
|
7674
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
7675
|
-
const resources = {
|
|
7676
|
-
signal: controller.signal,
|
|
7677
|
-
referenceReleases: /* @__PURE__ */ new Set(),
|
|
7678
|
-
add(close) {
|
|
7679
|
-
cleanups.add(close);
|
|
7680
|
-
}
|
|
7681
|
-
};
|
|
7682
|
-
signal?.addEventListener("abort", cancel, { once: true });
|
|
7683
|
-
if (signal?.aborted) cancel();
|
|
7684
|
-
let result;
|
|
7685
|
-
let failure;
|
|
7686
|
-
let errors = [];
|
|
7687
|
-
try {
|
|
7688
|
-
result = await runResources.run(resources, execute);
|
|
7689
|
-
} catch (error) {
|
|
7690
|
-
failure = { reason: error };
|
|
7691
|
-
} finally {
|
|
7692
|
-
signal?.removeEventListener("abort", cancel);
|
|
7693
|
-
controller.abort(new Error("SafeJS run finished."));
|
|
7694
|
-
for (const release of resources.referenceReleases) release();
|
|
7695
|
-
resources.referenceReleases.clear();
|
|
7696
|
-
const outcomes = await Promise.allSettled(
|
|
7697
|
-
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
7698
|
-
);
|
|
7699
|
-
errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
7700
|
-
}
|
|
7701
|
-
if (failure !== void 0) throw failure.reason;
|
|
7702
|
-
if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
|
|
7703
|
-
return result;
|
|
7704
|
-
}
|
|
7705
|
-
|
|
7706
7706
|
// packages/safe-js/src/interp/host-capabilities.ts
|
|
7707
7707
|
import { types as types6 } from "node:util";
|
|
7708
7708
|
var MAX_INDEXED_LENGTH = 65536;
|
|
@@ -25557,6 +25557,7 @@ function createRegexGlobals(options) {
|
|
|
25557
25557
|
|
|
25558
25558
|
// packages/safe-js/src/interp/globals/structured-clone.ts
|
|
25559
25559
|
var transferBuffer = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "transfer")?.value;
|
|
25560
|
+
var resizeBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize")?.value;
|
|
25560
25561
|
function createStructuredCloneGlobal(budget) {
|
|
25561
25562
|
return createSandboxClosure({
|
|
25562
25563
|
guest: true,
|
|
@@ -25627,37 +25628,67 @@ function cloneStructuredValue(value, transfers, budget, context) {
|
|
|
25627
25628
|
const buffers = /* @__PURE__ */ new WeakMap();
|
|
25628
25629
|
let clone;
|
|
25629
25630
|
const release = retainValues(budget, () => [value, clone, transfers]);
|
|
25630
|
-
|
|
25631
|
-
|
|
25632
|
-
|
|
25633
|
-
const length = arrayBufferLength(buffer);
|
|
25634
|
-
budget.allocateArrayLength(arrayBufferOptions(buffer)?.maxByteLength ?? length);
|
|
25635
|
-
transferSize += length + 1;
|
|
25636
|
-
if (arrayBufferDetached(buffer)) buffers.set(buffer, new ArrayBuffer(0));
|
|
25637
|
-
}
|
|
25638
|
-
budget.provisionDataUsage(transferSize)();
|
|
25639
|
-
clone = cloneSandboxValue(value, { compilation, resetRegexLastIndex: true, structuredClone: true, float32Buffers: buffers });
|
|
25640
|
-
assertSandboxGraphDepth(clone);
|
|
25641
|
-
assertStructuredCloneable(clone, /* @__PURE__ */ new WeakSet());
|
|
25642
|
-
allocateProducedSandboxValue(clone, budget);
|
|
25643
|
-
if (compilation !== parent) reconcileCompiledValues(budget, [clone], compilation);
|
|
25644
|
-
if (transfers.length > 0) {
|
|
25645
|
-
createDataCheckpoint(budget, context)(clone, 0, true);
|
|
25646
|
-
budget.visitNode(transferSize + transfers.length);
|
|
25647
|
-
budget.provisionDataUsage(transferBuffer === void 0 ? transferSize : transfers.length)();
|
|
25631
|
+
function* execute() {
|
|
25632
|
+
try {
|
|
25633
|
+
let transferSize = 0;
|
|
25648
25634
|
for (const buffer of transfers) {
|
|
25649
|
-
|
|
25650
|
-
|
|
25651
|
-
|
|
25652
|
-
|
|
25653
|
-
|
|
25635
|
+
const length = arrayBufferLength(buffer);
|
|
25636
|
+
budget.allocateArrayLength(arrayBufferOptions(buffer)?.maxByteLength ?? length);
|
|
25637
|
+
transferSize += length + 1;
|
|
25638
|
+
}
|
|
25639
|
+
budget.provisionDataUsage(transferSize)();
|
|
25640
|
+
for (const buffer of transfers) buffers.set(buffer, Reflect.construct(ArrayBuffer, [arrayBufferLength(buffer), arrayBufferOptions(buffer)]));
|
|
25641
|
+
const state = { seen: /* @__PURE__ */ new WeakMap(), compilation, resetRegexLastIndex: true, structuredClone: true, float32Buffers: buffers };
|
|
25642
|
+
clone = context?.invokeClosure === void 0 ? cloneSandboxValue(value, state) : yield* cloneStructuredGraph(value, state, budget);
|
|
25643
|
+
transferSize = 0;
|
|
25644
|
+
for (const buffer of transfers) {
|
|
25645
|
+
if (arrayBufferDetached(buffer)) continue;
|
|
25646
|
+
const length = arrayBufferLength(buffer);
|
|
25647
|
+
transferSize += length + 1;
|
|
25648
|
+
budget.allocateArrayLength(arrayBufferOptions(buffer)?.maxByteLength ?? length);
|
|
25649
|
+
const destination = buffers.get(buffer);
|
|
25650
|
+
budget.provisionDataUsage(Math.max(0, length - arrayBufferLength(destination)))();
|
|
25651
|
+
if (arrayBufferLength(destination) !== length) Reflect.apply(resizeBuffer2, destination, [length]);
|
|
25652
|
+
new Uint8Array(destination).set(new Uint8Array(buffer));
|
|
25653
|
+
}
|
|
25654
|
+
assertSandboxGraphDepth(clone);
|
|
25655
|
+
assertStructuredCloneable(clone, /* @__PURE__ */ new WeakSet());
|
|
25656
|
+
allocateProducedSandboxValue(clone, budget);
|
|
25657
|
+
if (compilation !== parent) reconcileCompiledValues(budget, [clone], compilation);
|
|
25658
|
+
if (transfers.length > 0) {
|
|
25659
|
+
createDataCheckpoint(budget, context)(clone, 0, true);
|
|
25660
|
+
budget.visitNode(transferSize + transfers.length);
|
|
25661
|
+
budget.provisionDataUsage(transferBuffer === void 0 ? transferSize : transfers.length)();
|
|
25662
|
+
for (const buffer of transfers) {
|
|
25663
|
+
if (arrayBufferDetached(buffer)) throw new DOMException("Cannot transfer a detached ArrayBuffer.", "DataCloneError");
|
|
25664
|
+
if (transferBuffer !== void 0) Reflect.apply(transferBuffer, buffer, [0]);
|
|
25665
|
+
else structuredClone(buffer, { transfer: [buffer] });
|
|
25666
|
+
if (!arrayBufferDetached(buffer)) throw new DOMException("ArrayBuffer cannot be transferred.", "DataCloneError");
|
|
25667
|
+
}
|
|
25668
|
+
}
|
|
25669
|
+
return clone;
|
|
25670
|
+
} finally {
|
|
25671
|
+
release();
|
|
25672
|
+
if (compilation !== parent) compilation.dispose();
|
|
25673
|
+
operation.release();
|
|
25654
25674
|
}
|
|
25655
|
-
return clone;
|
|
25656
|
-
} finally {
|
|
25657
|
-
release();
|
|
25658
|
-
if (compilation !== parent) compilation.dispose();
|
|
25659
|
-
operation.release();
|
|
25660
25675
|
}
|
|
25676
|
+
const iterator = execute();
|
|
25677
|
+
const first = iterator.next();
|
|
25678
|
+
if (first.done) return first.value;
|
|
25679
|
+
return (async () => {
|
|
25680
|
+
let step = first;
|
|
25681
|
+
try {
|
|
25682
|
+
while (!step.done) {
|
|
25683
|
+
const { descriptor, receiver } = step.value;
|
|
25684
|
+
createDataCheckpoint(budget, context)(receiver, 0, true);
|
|
25685
|
+
step = iterator.next(await readPropertyDescriptor(descriptor, receiver, context));
|
|
25686
|
+
}
|
|
25687
|
+
return step.value;
|
|
25688
|
+
} finally {
|
|
25689
|
+
iterator.return(void 0);
|
|
25690
|
+
}
|
|
25691
|
+
})();
|
|
25661
25692
|
}
|
|
25662
25693
|
function assertStructuredCloneable(value, seen) {
|
|
25663
25694
|
if (typeof value === "symbol") throw new DOMException("Cannot clone a symbol value.", "DataCloneError");
|
|
@@ -26034,7 +26065,7 @@ function createBigIntGlobal(budget) {
|
|
|
26034
26065
|
}
|
|
26035
26066
|
|
|
26036
26067
|
// packages/safe-js/src/interp/globals/array-buffer.ts
|
|
26037
|
-
var
|
|
26068
|
+
var resizeBuffer3 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resize")?.value;
|
|
26038
26069
|
var transferBuffer2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "transfer")?.value;
|
|
26039
26070
|
function createArrayBufferGlobal(budget) {
|
|
26040
26071
|
const prototype = /* @__PURE__ */ Object.create(null);
|
|
@@ -26076,7 +26107,7 @@ function createArrayBufferGlobal(budget) {
|
|
|
26076
26107
|
}
|
|
26077
26108
|
const target = context?.newTarget ?? constructor;
|
|
26078
26109
|
selected = await bridge.getProperty(target, "prototype");
|
|
26079
|
-
if (maxByteLength !== void 0 &&
|
|
26110
|
+
if (maxByteLength !== void 0 && resizeBuffer3 === void 0)
|
|
26080
26111
|
throw new TypeError("Resizable ArrayBuffer requires host runtime support.");
|
|
26081
26112
|
budget.allocateArrayLength(maxByteLength ?? length);
|
|
26082
26113
|
budget.provisionDataUsage(length + 1)();
|
|
@@ -26234,7 +26265,7 @@ function createArrayBufferGlobal(budget) {
|
|
|
26234
26265
|
length: 1,
|
|
26235
26266
|
call: async (args, context) => {
|
|
26236
26267
|
const receiver = context?.thisValue;
|
|
26237
|
-
if (
|
|
26268
|
+
if (resizeBuffer3 === void 0 || !isSandboxArrayBuffer(receiver) || arrayBufferOptions(receiver) === void 0)
|
|
26238
26269
|
throw new TypeError("ArrayBuffer resize requires a resizable buffer receiver.");
|
|
26239
26270
|
const release = retainValues(budget, () => [receiver, ...args]);
|
|
26240
26271
|
try {
|
|
@@ -26244,7 +26275,7 @@ function createArrayBufferGlobal(budget) {
|
|
|
26244
26275
|
throw new RangeError("Invalid ArrayBuffer resize length.");
|
|
26245
26276
|
budget.allocateArrayLength(length);
|
|
26246
26277
|
budget.provisionDataUsage(Math.max(length - arrayBufferLength(receiver), 0))();
|
|
26247
|
-
Reflect.apply(
|
|
26278
|
+
Reflect.apply(resizeBuffer3, receiver, [length]);
|
|
26248
26279
|
return void 0;
|
|
26249
26280
|
} finally {
|
|
26250
26281
|
release();
|
|
@@ -28334,6 +28365,66 @@ function allocateProducedSandboxValue(value, budget) {
|
|
|
28334
28365
|
allocateSandboxValue2(value, budget, /* @__PURE__ */ new WeakSet());
|
|
28335
28366
|
return value;
|
|
28336
28367
|
}
|
|
28368
|
+
function* cloneStructuredGraph(value, state, budget, depth = 0) {
|
|
28369
|
+
assertSandboxDataDepth(depth);
|
|
28370
|
+
budget.visitNode();
|
|
28371
|
+
if (typeof value === "symbol" || isSandboxClosure(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxArrayIterator(value) || isSandboxArguments(value))
|
|
28372
|
+
throw new DOMException("Value cannot be structured cloned.", "DataCloneError");
|
|
28373
|
+
if (typeof value !== "object" || value === null) return allocateProducedSandboxValue(value, budget);
|
|
28374
|
+
if (isLiveCapability(value)) throw new DOMException("Capabilities cannot be structured cloned.", "DataCloneError");
|
|
28375
|
+
const existing = state.seen.get(value);
|
|
28376
|
+
if (existing !== void 0) return existing;
|
|
28377
|
+
const map = isSandboxMap(value);
|
|
28378
|
+
const set = isSandboxSet(value);
|
|
28379
|
+
const array2 = isPlainArray(value);
|
|
28380
|
+
const plain = isPlainObject4(value) && !isSandboxRegex(value) && !isRawJson(value) && nativeBoxedValue(value) === void 0;
|
|
28381
|
+
if (!map && !set && !array2 && !plain) {
|
|
28382
|
+
const copy2 = copyToSandbox(value, state, "<root>", true, depth);
|
|
28383
|
+
allocateProducedSandboxValue(copy2, budget);
|
|
28384
|
+
return copy2;
|
|
28385
|
+
}
|
|
28386
|
+
if (array2) budget.allocateArrayLength(value.length);
|
|
28387
|
+
budget.provisionDataUsage(1)();
|
|
28388
|
+
const copy = map ? createSandboxMap() : set ? createSandboxSet() : array2 ? new Array(value.length) : createPlainObject(Object.getPrototypeOf(value) === null);
|
|
28389
|
+
state.seen.set(value, copy);
|
|
28390
|
+
const errorType = sandboxErrorTypes.get(value);
|
|
28391
|
+
if (errorType !== void 0) sandboxErrorTypes.set(copy, errorType);
|
|
28392
|
+
let pending;
|
|
28393
|
+
let current;
|
|
28394
|
+
const release = retainValues(budget, () => [value, copy, pending, current]);
|
|
28395
|
+
try {
|
|
28396
|
+
if (map && isSandboxMap(copy)) {
|
|
28397
|
+
budget.allocateArrayLength(value.entries.size);
|
|
28398
|
+
budget.provisionDataUsage(value.entries.size * 3 + 1)();
|
|
28399
|
+
const entries = [...value.entries];
|
|
28400
|
+
pending = entries;
|
|
28401
|
+
for (const [key, entry] of entries) {
|
|
28402
|
+
current = yield* cloneStructuredGraph(key, state, budget, depth + 1);
|
|
28403
|
+
copy.entries.set(current, yield* cloneStructuredGraph(entry, state, budget, depth + 1));
|
|
28404
|
+
}
|
|
28405
|
+
} else if (set && isSandboxSet(copy)) {
|
|
28406
|
+
budget.allocateArrayLength(value.values.size);
|
|
28407
|
+
budget.provisionDataUsage(value.values.size + 1)();
|
|
28408
|
+
const entries = [...value.values];
|
|
28409
|
+
pending = entries;
|
|
28410
|
+
for (const entry of entries) copy.values.add(yield* cloneStructuredGraph(entry, state, budget, depth + 1));
|
|
28411
|
+
} else {
|
|
28412
|
+
const keys = Object.keys(value);
|
|
28413
|
+
budget.allocateArrayLength(keys.length);
|
|
28414
|
+
budget.provisionDataUsage(keys.length + 1)();
|
|
28415
|
+
pending = keys;
|
|
28416
|
+
for (const key of keys) {
|
|
28417
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
28418
|
+
if (descriptor === void 0) continue;
|
|
28419
|
+
current = "value" in descriptor ? descriptor.value : yield { descriptor, receiver: value };
|
|
28420
|
+
defineOwnDataProperty(copy, key, yield* cloneStructuredGraph(current, state, budget, depth + 1));
|
|
28421
|
+
}
|
|
28422
|
+
}
|
|
28423
|
+
return copy;
|
|
28424
|
+
} finally {
|
|
28425
|
+
release();
|
|
28426
|
+
}
|
|
28427
|
+
}
|
|
28337
28428
|
function measureSandboxData(values, options = {}) {
|
|
28338
28429
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
28339
28430
|
const seenSymbols = /* @__PURE__ */ new Set();
|
|
@@ -43503,4 +43594,4 @@ export {
|
|
|
43503
43594
|
FileSnapshotBackend,
|
|
43504
43595
|
run
|
|
43505
43596
|
};
|
|
43506
|
-
//# sourceMappingURL=chunk-
|
|
43597
|
+
//# sourceMappingURL=chunk-54LUHONC.js.map
|