poe-code 14.0.79 → 14.0.80
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/index.js +252 -100
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-B3AL4KJ3.js → chunk-34G5WW2O.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-BGSPSHLP.js → chunk-M4L3EZHL.js} +220 -93
- package/packages/safe-js/dist/chunks/chunk-M4L3EZHL.js.map +7 -0
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/graph-depth.js +2 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/generator-properties.d.ts +3 -0
- package/packages/safe-js/dist/interp/generator-properties.js +9 -0
- package/packages/safe-js/dist/interp/globals/function.d.ts +2 -0
- package/packages/safe-js/dist/interp/globals/function.js +24 -0
- package/packages/safe-js/dist/interp/globals/object-array.js +9 -6
- package/packages/safe-js/dist/interp/globals/object.js +2 -1
- package/packages/safe-js/dist/interp/globals.js +2 -0
- package/packages/safe-js/dist/interp/interpreter.js +13 -7
- package/packages/safe-js/dist/interp/iteration.js +37 -4
- package/packages/safe-js/dist/interp/methods/function.d.ts +4 -1
- package/packages/safe-js/dist/interp/methods/function.js +2 -2
- package/packages/safe-js/dist/interp/object-model.d.ts +1 -0
- package/packages/safe-js/dist/interp/object-model.js +67 -17
- package/packages/safe-js/dist/interp/string-coercion.js +3 -2
- package/packages/safe-js/dist/interp/values.js +21 -3
- package/packages/safe-js/dist/snapshot/guest-heap-validation.js +3 -1
- package/packages/safe-js/dist/snapshot/guest-heap.d.ts +1 -0
- package/packages/safe-js/dist/snapshot/guest-heap.js +4 -0
- package/packages/safe-js/dist/snapshot/restore.js +8 -0
- package/packages/safe-js/dist/chunks/chunk-BGSPSHLP.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-B3AL4KJ3.js.map → chunk-34G5WW2O.js.map} +0 -0
|
@@ -7013,6 +7013,17 @@ function serializedDateTime(value) {
|
|
|
7013
7013
|
// packages/safe-js/src/interp/internal-symbols.ts
|
|
7014
7014
|
var internalSymbols = /* @__PURE__ */ new Set();
|
|
7015
7015
|
|
|
7016
|
+
// packages/safe-js/src/interp/generator-properties.ts
|
|
7017
|
+
var generatorGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7018
|
+
function getGeneratorProperties(value) {
|
|
7019
|
+
let properties = generatorGuestProperties.get(value);
|
|
7020
|
+
if (properties === void 0) {
|
|
7021
|
+
properties = /* @__PURE__ */ Object.create(null);
|
|
7022
|
+
generatorGuestProperties.set(value, properties);
|
|
7023
|
+
}
|
|
7024
|
+
return properties;
|
|
7025
|
+
}
|
|
7026
|
+
|
|
7016
7027
|
// packages/safe-js/src/interp/regexp-properties.ts
|
|
7017
7028
|
var regexGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
7018
7029
|
function getRegexProperties(value) {
|
|
@@ -7355,7 +7366,7 @@ function walkGraphDepth(root, rootPath, assertDepth) {
|
|
|
7355
7366
|
}
|
|
7356
7367
|
}
|
|
7357
7368
|
function graphEntries(value) {
|
|
7358
|
-
const properties = regexGuestProperties.get(value);
|
|
7369
|
+
const properties = regexGuestProperties.get(value) ?? generatorGuestProperties.get(value);
|
|
7359
7370
|
if (properties !== void 0) return Reflect.ownKeys(properties).flatMap((key) => {
|
|
7360
7371
|
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
7361
7372
|
return "value" in descriptor ? [[`.${String(key)}`, descriptor.value]] : [];
|
|
@@ -7387,6 +7398,55 @@ function graphEntries(value) {
|
|
|
7387
7398
|
return entries;
|
|
7388
7399
|
}
|
|
7389
7400
|
|
|
7401
|
+
// packages/safe-js/src/interp/resources.ts
|
|
7402
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7403
|
+
var runResources = new AsyncLocalStorage();
|
|
7404
|
+
function retainValues(budget, values) {
|
|
7405
|
+
const retained = {};
|
|
7406
|
+
budget.setRetainedValues(retained, values);
|
|
7407
|
+
const pending = runResources.getStore()?.referenceReleases;
|
|
7408
|
+
const release = () => {
|
|
7409
|
+
budget.setRetainedValues(retained, void 0);
|
|
7410
|
+
pending?.delete(release);
|
|
7411
|
+
};
|
|
7412
|
+
pending?.add(release);
|
|
7413
|
+
return release;
|
|
7414
|
+
}
|
|
7415
|
+
async function withRunResources(signal, execute) {
|
|
7416
|
+
const controller = new AbortController();
|
|
7417
|
+
const cancel = () => controller.abort(signal?.reason);
|
|
7418
|
+
const cleanups = /* @__PURE__ */ new Set();
|
|
7419
|
+
const resources = {
|
|
7420
|
+
signal: controller.signal,
|
|
7421
|
+
referenceReleases: /* @__PURE__ */ new Set(),
|
|
7422
|
+
add(close) {
|
|
7423
|
+
cleanups.add(close);
|
|
7424
|
+
}
|
|
7425
|
+
};
|
|
7426
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
7427
|
+
if (signal?.aborted) cancel();
|
|
7428
|
+
let result;
|
|
7429
|
+
let failure;
|
|
7430
|
+
let errors = [];
|
|
7431
|
+
try {
|
|
7432
|
+
result = await runResources.run(resources, execute);
|
|
7433
|
+
} catch (error) {
|
|
7434
|
+
failure = { reason: error };
|
|
7435
|
+
} finally {
|
|
7436
|
+
signal?.removeEventListener("abort", cancel);
|
|
7437
|
+
controller.abort(new Error("SafeJS run finished."));
|
|
7438
|
+
for (const release of resources.referenceReleases) release();
|
|
7439
|
+
resources.referenceReleases.clear();
|
|
7440
|
+
const outcomes = await Promise.allSettled(
|
|
7441
|
+
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
7442
|
+
);
|
|
7443
|
+
errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
7444
|
+
}
|
|
7445
|
+
if (failure !== void 0) throw failure.reason;
|
|
7446
|
+
if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
|
|
7447
|
+
return result;
|
|
7448
|
+
}
|
|
7449
|
+
|
|
7390
7450
|
// packages/safe-js/src/interp/symbols.ts
|
|
7391
7451
|
var wellKnownSymbols = Object.freeze({
|
|
7392
7452
|
iterator: Symbol.iterator,
|
|
@@ -7802,6 +7862,7 @@ function namedKeys(state) {
|
|
|
7802
7862
|
// packages/safe-js/src/interp/object-model.ts
|
|
7803
7863
|
var guestClosures = /* @__PURE__ */ new WeakSet();
|
|
7804
7864
|
var functionProperties = /* @__PURE__ */ new WeakMap();
|
|
7865
|
+
var functionPropertyRevisions = /* @__PURE__ */ new WeakMap();
|
|
7805
7866
|
var prototypes = /* @__PURE__ */ new WeakMap();
|
|
7806
7867
|
var intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7807
7868
|
var boxedPrototypes = /* @__PURE__ */ new WeakMap();
|
|
@@ -7810,6 +7871,7 @@ var collectionPrototypes = /* @__PURE__ */ new WeakMap();
|
|
|
7810
7871
|
var promisePrototypes = /* @__PURE__ */ new WeakMap();
|
|
7811
7872
|
var datePrototypes = /* @__PURE__ */ new WeakMap();
|
|
7812
7873
|
var arrayPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7874
|
+
var functionPrototypes = /* @__PURE__ */ new WeakMap();
|
|
7813
7875
|
var initialArrayMethods = /* @__PURE__ */ new WeakMap();
|
|
7814
7876
|
var initialRegexDescriptors = /* @__PURE__ */ new WeakMap();
|
|
7815
7877
|
var intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
|
|
@@ -7845,9 +7907,23 @@ function materializeFunctionProperties(closure) {
|
|
|
7845
7907
|
descriptorObjects.add(prototype);
|
|
7846
7908
|
Object.defineProperty(properties, "prototype", { value: prototype, writable: true });
|
|
7847
7909
|
}
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7910
|
+
const state = { revision: 0 };
|
|
7911
|
+
const tracked = new Proxy(properties, {
|
|
7912
|
+
defineProperty(target, key, descriptor) {
|
|
7913
|
+
const changed = Reflect.defineProperty(target, key, descriptor);
|
|
7914
|
+
if (changed) state.revision++;
|
|
7915
|
+
return changed;
|
|
7916
|
+
},
|
|
7917
|
+
deleteProperty(target, key) {
|
|
7918
|
+
const changed = Reflect.deleteProperty(target, key);
|
|
7919
|
+
if (changed) state.revision++;
|
|
7920
|
+
return changed;
|
|
7921
|
+
}
|
|
7922
|
+
});
|
|
7923
|
+
functionPropertyRevisions.set(tracked, state);
|
|
7924
|
+
descriptorObjects.add(tracked);
|
|
7925
|
+
functionProperties.set(closure, tracked);
|
|
7926
|
+
return tracked;
|
|
7851
7927
|
}
|
|
7852
7928
|
function getGuestFunctionProperty(closure, key) {
|
|
7853
7929
|
let properties = functionProperties.get(closure);
|
|
@@ -7865,6 +7941,12 @@ function installObjectPrototype(budget, prototype, constructor) {
|
|
|
7865
7941
|
intrinsicPrototypes.set(budget, prototype);
|
|
7866
7942
|
registerIntrinsicPrototype(budget, prototype, constructor);
|
|
7867
7943
|
}
|
|
7944
|
+
function installFunctionPrototype(budget, prototype) {
|
|
7945
|
+
functionPrototypes.set(budget, prototype);
|
|
7946
|
+
registerBuiltinIdentities(budget, { "%FunctionPrototype%": prototype });
|
|
7947
|
+
registerIntrinsicFunction(budget, prototype);
|
|
7948
|
+
registerIntrinsicObject(budget, materializeFunctionProperties(prototype));
|
|
7949
|
+
}
|
|
7868
7950
|
function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
|
|
7869
7951
|
let state = boxedPrototypes.get(budget);
|
|
7870
7952
|
if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
|
|
@@ -7951,6 +8033,9 @@ function trackIntrinsicState(budget, root, owner, targets) {
|
|
|
7951
8033
|
explicit: hasExplicitSandboxPrototype(target)
|
|
7952
8034
|
})).map((record4) => ({
|
|
7953
8035
|
...record4,
|
|
8036
|
+
revision: functionPropertyRevisions.get(record4.value),
|
|
8037
|
+
capturedRevision: -1,
|
|
8038
|
+
captured: [],
|
|
7954
8039
|
extensible: Object.isExtensible(record4.value),
|
|
7955
8040
|
descriptors: new Map(Reflect.ownKeys(record4.value).map((key) => [key, Object.getOwnPropertyDescriptor(record4.value, key)]))
|
|
7956
8041
|
}));
|
|
@@ -7966,14 +8051,21 @@ function trackIntrinsicState(budget, root, owner, targets) {
|
|
|
7966
8051
|
);
|
|
7967
8052
|
budget.setRetainedValues(root, () => {
|
|
7968
8053
|
const retained = [];
|
|
7969
|
-
for (const
|
|
8054
|
+
for (const record4 of records) {
|
|
8055
|
+
const { target, value, descriptors: descriptors2, prototype: parent, revision } = record4;
|
|
7970
8056
|
const currentPrototype = getSandboxPrototype(target);
|
|
7971
8057
|
if (currentPrototype !== parent) retained.push(currentPrototype);
|
|
7972
|
-
|
|
7973
|
-
const
|
|
7974
|
-
|
|
7975
|
-
|
|
8058
|
+
if (revision === void 0 || revision.revision !== record4.capturedRevision) {
|
|
8059
|
+
const captured = [];
|
|
8060
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
8061
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
8062
|
+
if (unchanged(descriptors2.get(key), descriptor)) continue;
|
|
8063
|
+
captured.push(key, descriptor.value, ...retainedAccessorClosures(descriptor));
|
|
8064
|
+
}
|
|
8065
|
+
record4.captured = captured;
|
|
8066
|
+
record4.capturedRevision = revision?.revision ?? -1;
|
|
7976
8067
|
}
|
|
8068
|
+
for (const item of record4.captured) retained.push(item);
|
|
7977
8069
|
}
|
|
7978
8070
|
return retained;
|
|
7979
8071
|
});
|
|
@@ -7989,11 +8081,14 @@ function releaseObjectPrototype(budget) {
|
|
|
7989
8081
|
promisePrototypes.delete(budget);
|
|
7990
8082
|
datePrototypes.delete(budget);
|
|
7991
8083
|
arrayPrototypes.delete(budget);
|
|
8084
|
+
functionPrototypes.delete(budget);
|
|
7992
8085
|
initialRegexDescriptors.delete(budget);
|
|
7993
8086
|
intrinsicPrototypes.delete(budget);
|
|
7994
8087
|
}
|
|
7995
8088
|
function getSandboxPrototype(value, budget) {
|
|
7996
8089
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
8090
|
+
if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
|
|
8091
|
+
return functionPrototypes.get(budget) ?? null;
|
|
7997
8092
|
if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
|
|
7998
8093
|
if (budget !== void 0 && isSandboxDate(value)) return datePrototypes.get(budget) ?? null;
|
|
7999
8094
|
if (budget !== void 0 && isSandboxPromise(value)) return promisePrototypes.get(budget) ?? null;
|
|
@@ -8018,8 +8113,15 @@ function getSandboxPropertyDescriptor(value, key, budget) {
|
|
|
8018
8113
|
return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key);
|
|
8019
8114
|
let current = value;
|
|
8020
8115
|
let depth = 0;
|
|
8021
|
-
while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
|
|
8022
|
-
const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
8116
|
+
while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
|
|
8117
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
8118
|
+
if (properties === void 0 && isGuestClosure(current) && (key === "name" || key === "length"))
|
|
8119
|
+
return {
|
|
8120
|
+
value: key === "name" ? current.name ?? "" : current.length ?? 0,
|
|
8121
|
+
writable: false,
|
|
8122
|
+
enumerable: false,
|
|
8123
|
+
configurable: true
|
|
8124
|
+
};
|
|
8023
8125
|
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
|
|
8024
8126
|
if (descriptor !== void 0) return descriptor;
|
|
8025
8127
|
current = getSandboxPrototype(current, budget);
|
|
@@ -8037,6 +8139,10 @@ function getSandboxDataProperty(value, key, budget) {
|
|
|
8037
8139
|
if (isGuestHostObject(current)) return typeof key === "symbol" ? void 0 : getHostObjectMember(current, String(key));
|
|
8038
8140
|
if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key)?.value;
|
|
8039
8141
|
if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key)?.value;
|
|
8142
|
+
if (isSandboxGenerator(current)) {
|
|
8143
|
+
const descriptor = Object.getOwnPropertyDescriptor(getGeneratorProperties(current), key);
|
|
8144
|
+
if (descriptor !== void 0) return descriptor.value;
|
|
8145
|
+
}
|
|
8040
8146
|
if (isSandboxMap(current) || isSandboxSet(current)) return Object.getOwnPropertyDescriptor(getCollectionProperties(current), key)?.value;
|
|
8041
8147
|
if (isGuestClosure(current)) {
|
|
8042
8148
|
const entry = getGuestFunctionProperty(current, key);
|
|
@@ -8045,9 +8151,9 @@ function getSandboxDataProperty(value, key, budget) {
|
|
|
8045
8151
|
const properties = current.properties;
|
|
8046
8152
|
return properties !== void 0 && Object.hasOwn(properties, key) ? properties[key] : void 0;
|
|
8047
8153
|
}
|
|
8048
|
-
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current)
|
|
8154
|
+
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current))
|
|
8049
8155
|
return void 0;
|
|
8050
|
-
if (!isSandboxClosure(current) && Object.hasOwn(current, key)) return current[key];
|
|
8156
|
+
if (!isSandboxClosure(current) && !isSandboxGenerator(current) && Object.hasOwn(current, key)) return current[key];
|
|
8051
8157
|
current = getSandboxPrototype(current, budget);
|
|
8052
8158
|
if (current !== null) {
|
|
8053
8159
|
budget?.visitNode();
|
|
@@ -8060,7 +8166,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
8060
8166
|
if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
|
|
8061
8167
|
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
8062
8168
|
}
|
|
8063
|
-
if (!Array.isArray(value) && !isSandboxDate(value) && !isSandboxPromise(value) && !isSandboxRegex(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isPrototypeRecord(value) || prototype !== null && !Array.isArray(prototype) && !isSandboxDate(prototype) && !isSandboxPromise(prototype) && !isSandboxRegex(prototype) && !isSandboxMap(prototype) && !isSandboxSet(prototype) && !isPrototypeRecord(prototype)) {
|
|
8169
|
+
if (!Array.isArray(value) && !isSandboxGenerator(value) && !isSandboxDate(value) && !isSandboxPromise(value) && !isSandboxRegex(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isPrototypeRecord(value) || prototype !== null && !Array.isArray(prototype) && !isSandboxGenerator(prototype) && !isSandboxDate(prototype) && !isSandboxPromise(prototype) && !isSandboxRegex(prototype) && !isSandboxMap(prototype) && !isSandboxSet(prototype) && !isPrototypeRecord(prototype)) {
|
|
8064
8170
|
throw new TypeError(
|
|
8065
8171
|
"Prototype links require supported sandbox objects."
|
|
8066
8172
|
);
|
|
@@ -8069,7 +8175,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
8069
8175
|
if (prototype === null) prototypes.set(value, null);
|
|
8070
8176
|
return;
|
|
8071
8177
|
}
|
|
8072
|
-
if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
|
|
8178
|
+
if (!Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
|
|
8073
8179
|
throw new TypeError("Cannot change the prototype of a non-extensible object.");
|
|
8074
8180
|
}
|
|
8075
8181
|
let depth = 0;
|
|
@@ -8126,7 +8232,7 @@ function isRawJson(value) {
|
|
|
8126
8232
|
import { types as nodeTypes } from "node:util";
|
|
8127
8233
|
|
|
8128
8234
|
// packages/safe-js/src/interp/promise-tracker.ts
|
|
8129
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8235
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
8130
8236
|
var SandboxPromiseRejectionTracker = class {
|
|
8131
8237
|
records = /* @__PURE__ */ new Set();
|
|
8132
8238
|
recordsByPromise = /* @__PURE__ */ new WeakMap();
|
|
@@ -8203,8 +8309,8 @@ var SandboxPromiseRejectionTracker = class {
|
|
|
8203
8309
|
return void 0;
|
|
8204
8310
|
}
|
|
8205
8311
|
};
|
|
8206
|
-
var activePromiseTracker = new
|
|
8207
|
-
var fatalRejectionCleanup = new
|
|
8312
|
+
var activePromiseTracker = new AsyncLocalStorage2();
|
|
8313
|
+
var fatalRejectionCleanup = new AsyncLocalStorage2();
|
|
8208
8314
|
function assertPromiseExecutionAllowed() {
|
|
8209
8315
|
const failure = activePromiseTracker.getStore()?.failure;
|
|
8210
8316
|
if (failure !== void 0 && fatalRejectionCleanup.getStore() !== true) throw failure;
|
|
@@ -8766,55 +8872,6 @@ function isLineTerminator(character) {
|
|
|
8766
8872
|
return character === "\n" || character === "\r" || character === "\u2028" || character === "\u2029";
|
|
8767
8873
|
}
|
|
8768
8874
|
|
|
8769
|
-
// packages/safe-js/src/interp/resources.ts
|
|
8770
|
-
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
8771
|
-
var runResources = new AsyncLocalStorage2();
|
|
8772
|
-
function retainValues(budget, values) {
|
|
8773
|
-
const retained = {};
|
|
8774
|
-
budget.setRetainedValues(retained, values);
|
|
8775
|
-
const pending = runResources.getStore()?.referenceReleases;
|
|
8776
|
-
const release = () => {
|
|
8777
|
-
budget.setRetainedValues(retained, void 0);
|
|
8778
|
-
pending?.delete(release);
|
|
8779
|
-
};
|
|
8780
|
-
pending?.add(release);
|
|
8781
|
-
return release;
|
|
8782
|
-
}
|
|
8783
|
-
async function withRunResources(signal, execute) {
|
|
8784
|
-
const controller = new AbortController();
|
|
8785
|
-
const cancel = () => controller.abort(signal?.reason);
|
|
8786
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
8787
|
-
const resources = {
|
|
8788
|
-
signal: controller.signal,
|
|
8789
|
-
referenceReleases: /* @__PURE__ */ new Set(),
|
|
8790
|
-
add(close) {
|
|
8791
|
-
cleanups.add(close);
|
|
8792
|
-
}
|
|
8793
|
-
};
|
|
8794
|
-
signal?.addEventListener("abort", cancel, { once: true });
|
|
8795
|
-
if (signal?.aborted) cancel();
|
|
8796
|
-
let result;
|
|
8797
|
-
let failure;
|
|
8798
|
-
let errors = [];
|
|
8799
|
-
try {
|
|
8800
|
-
result = await runResources.run(resources, execute);
|
|
8801
|
-
} catch (error) {
|
|
8802
|
-
failure = { reason: error };
|
|
8803
|
-
} finally {
|
|
8804
|
-
signal?.removeEventListener("abort", cancel);
|
|
8805
|
-
controller.abort(new Error("SafeJS run finished."));
|
|
8806
|
-
for (const release of resources.referenceReleases) release();
|
|
8807
|
-
resources.referenceReleases.clear();
|
|
8808
|
-
const outcomes = await Promise.allSettled(
|
|
8809
|
-
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
8810
|
-
);
|
|
8811
|
-
errors = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
8812
|
-
}
|
|
8813
|
-
if (failure !== void 0) throw failure.reason;
|
|
8814
|
-
if (errors.length > 0) throw new AggregateError(errors, "SafeJS resource cleanup failed.");
|
|
8815
|
-
return result;
|
|
8816
|
-
}
|
|
8817
|
-
|
|
8818
8875
|
// packages/safe-js/src/interp/bigint-operators.ts
|
|
8819
8876
|
function bigIntOperation(operator, left, right, budget) {
|
|
8820
8877
|
if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
|
|
@@ -9384,7 +9441,10 @@ async function restoreSandboxIterator(snapshot, budget, context, signal) {
|
|
|
9384
9441
|
if (snapshot.kind === "guest") return guestIterator(snapshot.value, snapshot.next, snapshot.async, budget, context, signal);
|
|
9385
9442
|
if (snapshot.kind === "async-from-sync") return asyncFromSyncIterator(await restoreSandboxIterator(snapshot.inner, budget, context, signal), budget, signal, context);
|
|
9386
9443
|
if (Array.isArray(snapshot.value)) return arrayIterator(snapshot.value, context, budget, snapshot.index);
|
|
9387
|
-
const iterator = isSandboxGenerator(snapshot.value)
|
|
9444
|
+
const iterator = isSandboxGenerator(snapshot.value) ? {
|
|
9445
|
+
...generatorObjectIterator(snapshot.value, budget, context),
|
|
9446
|
+
...snapshot.value.async ? { asyncProtocol: true } : {}
|
|
9447
|
+
} : getSandboxIterator(snapshot.value, budget, context);
|
|
9388
9448
|
if (iterator === void 0) throw new TypeError("Invalid builtin iterator snapshot.");
|
|
9389
9449
|
for (let index = 0; index < snapshot.index; index++) await iterator.next();
|
|
9390
9450
|
return iterator;
|
|
@@ -9394,6 +9454,11 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
|
|
|
9394
9454
|
if (context.getProperty === void 0 || isGuestHostObject(value))
|
|
9395
9455
|
return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
|
|
9396
9456
|
if (getSandboxPropertyDescriptor(value, key, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
|
|
9457
|
+
if (isSandboxGenerator(value)) {
|
|
9458
|
+
if (hasExplicitSandboxPrototype(value)) return void 0;
|
|
9459
|
+
if (value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
|
|
9460
|
+
return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
|
|
9461
|
+
}
|
|
9397
9462
|
if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
|
|
9398
9463
|
if (!asyncProtocol) return getSandboxIterator(value, budget, context);
|
|
9399
9464
|
if (isSandboxGenerator(value) && value.async)
|
|
@@ -9458,7 +9523,7 @@ async function readIteratorResult(iterator, result, property) {
|
|
|
9458
9523
|
}
|
|
9459
9524
|
function getSandboxAsyncIterator(value, budget, context, signal) {
|
|
9460
9525
|
if (isSandboxGenerator(value) && value.async) {
|
|
9461
|
-
return { ...
|
|
9526
|
+
return hasExplicitSandboxPrototype(value) ? void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
|
|
9462
9527
|
}
|
|
9463
9528
|
if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
|
|
9464
9529
|
const method = value[Symbol.asyncIterator];
|
|
@@ -9608,7 +9673,7 @@ function getSandboxIterator(value, budget, context) {
|
|
|
9608
9673
|
return syncIterator(Float32Array.prototype.values.call(value));
|
|
9609
9674
|
}
|
|
9610
9675
|
if (isSandboxGenerator(value)) {
|
|
9611
|
-
return value.async ? void 0 :
|
|
9676
|
+
return value.async || hasExplicitSandboxPrototype(value) ? void 0 : generatorObjectIterator(value, budget, context);
|
|
9612
9677
|
}
|
|
9613
9678
|
if (typeof value === "string") {
|
|
9614
9679
|
const iterator2 = value[Symbol.iterator]();
|
|
@@ -9685,6 +9750,26 @@ function collectionIterator(collection, value) {
|
|
|
9685
9750
|
return adapter;
|
|
9686
9751
|
}
|
|
9687
9752
|
var asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
|
|
9753
|
+
function generatorObjectIterator(generator, budget, context) {
|
|
9754
|
+
const iterator = generatorIterator(generator, budget, context);
|
|
9755
|
+
if (context?.getProperty === void 0) return iterator;
|
|
9756
|
+
return {
|
|
9757
|
+
...iterator,
|
|
9758
|
+
getOperation: async (method) => {
|
|
9759
|
+
if (method === "next" || !hasExplicitSandboxPrototype(generator) && getSandboxPropertyDescriptor(generator, method, budget) === void 0) return iterator[method];
|
|
9760
|
+
const operation = await context.getProperty(generator, method);
|
|
9761
|
+
if (operation === void 0 || operation === null) return void 0;
|
|
9762
|
+
if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
|
|
9763
|
+
return async (...args) => {
|
|
9764
|
+
const result = await invokeBuiltinClosure(operation, args, budget ?? new Budget(), context, generator);
|
|
9765
|
+
return generator.async ? await awaitSandboxValue(result, void 0, budget, context) : result;
|
|
9766
|
+
};
|
|
9767
|
+
},
|
|
9768
|
+
readResultProperty: async (result, property) => ({
|
|
9769
|
+
value: await context.getProperty(result, property)
|
|
9770
|
+
})
|
|
9771
|
+
};
|
|
9772
|
+
}
|
|
9688
9773
|
function generatorIterator(generator, budget, context) {
|
|
9689
9774
|
const invoke = async (method, value) => {
|
|
9690
9775
|
const leaveRunning = enterRunningState(generator);
|
|
@@ -13006,14 +13091,14 @@ function createObjectArrayGlobals(options) {
|
|
|
13006
13091
|
call: ([value]) => {
|
|
13007
13092
|
if (isGuestHostObject(value))
|
|
13008
13093
|
throw new TypeError("Live host objects cannot be made non-extensible.");
|
|
13009
|
-
Object.preventExtensions(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
13094
|
+
Object.preventExtensions(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
13010
13095
|
return value;
|
|
13011
13096
|
},
|
|
13012
13097
|
name: "preventExtensions"
|
|
13013
13098
|
}),
|
|
13014
13099
|
isExtensible: createSandboxClosure({
|
|
13015
13100
|
sandbox: true,
|
|
13016
|
-
call: ([value]) => Object.isExtensible(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
13101
|
+
call: ([value]) => Object.isExtensible(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
13017
13102
|
name: "isExtensible"
|
|
13018
13103
|
}),
|
|
13019
13104
|
seal: createSandboxClosure({
|
|
@@ -13021,14 +13106,14 @@ function createObjectArrayGlobals(options) {
|
|
|
13021
13106
|
call: ([value]) => {
|
|
13022
13107
|
if (isGuestHostObject(value))
|
|
13023
13108
|
throw new TypeError("Live host objects cannot be sealed.");
|
|
13024
|
-
Object.seal(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
13109
|
+
Object.seal(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
13025
13110
|
return value;
|
|
13026
13111
|
},
|
|
13027
13112
|
name: "seal"
|
|
13028
13113
|
}),
|
|
13029
13114
|
isSealed: createSandboxClosure({
|
|
13030
13115
|
sandbox: true,
|
|
13031
|
-
call: ([value]) => Object.isSealed(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
13116
|
+
call: ([value]) => Object.isSealed(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
13032
13117
|
name: "isSealed"
|
|
13033
13118
|
}),
|
|
13034
13119
|
freeze: createSandboxClosure({
|
|
@@ -13037,7 +13122,7 @@ function createObjectArrayGlobals(options) {
|
|
|
13037
13122
|
if (isGuestHostObject(value))
|
|
13038
13123
|
throw new TypeError("Live host objects cannot be frozen.");
|
|
13039
13124
|
if (typeof value === "object" && value !== null) {
|
|
13040
|
-
Object.freeze(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
13125
|
+
Object.freeze(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
13041
13126
|
}
|
|
13042
13127
|
return value;
|
|
13043
13128
|
},
|
|
@@ -13045,7 +13130,7 @@ function createObjectArrayGlobals(options) {
|
|
|
13045
13130
|
}),
|
|
13046
13131
|
isFrozen: createSandboxClosure({
|
|
13047
13132
|
sandbox: true,
|
|
13048
|
-
call: ([value]) => Object.isFrozen(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
13133
|
+
call: ([value]) => Object.isFrozen(isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
13049
13134
|
name: "isFrozen"
|
|
13050
13135
|
}),
|
|
13051
13136
|
assign: createSandboxClosure({
|
|
@@ -13388,6 +13473,7 @@ function reflectionProperties(value) {
|
|
|
13388
13473
|
return objectProperties(value);
|
|
13389
13474
|
}
|
|
13390
13475
|
function objectProperties(value, mutable = false) {
|
|
13476
|
+
if (isSandboxGenerator(value)) return getGeneratorProperties(value);
|
|
13391
13477
|
if (isSandboxPromise(value)) return getPromiseProperties(value);
|
|
13392
13478
|
if (isSandboxMap(value) || isSandboxSet(value)) return getCollectionProperties(value);
|
|
13393
13479
|
if (isSandboxRegex(value)) return getRegexProperties(value);
|
|
@@ -13929,7 +14015,7 @@ function getFunctionMember(target, property, options) {
|
|
|
13929
14015
|
} else if (Object.hasOwn(current, String(property))) {
|
|
13930
14016
|
return current[String(property)];
|
|
13931
14017
|
}
|
|
13932
|
-
if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current)) break;
|
|
14018
|
+
if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current) && getSandboxPrototype(current, options.budget) === null) break;
|
|
13933
14019
|
current = getSandboxPrototype(current, options.budget);
|
|
13934
14020
|
if (current !== null) {
|
|
13935
14021
|
options.budget?.visitNode();
|
|
@@ -16192,7 +16278,7 @@ function forInKeys(object, budget) {
|
|
|
16192
16278
|
for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
16193
16279
|
if (depth > 0) budget.visitNode();
|
|
16194
16280
|
assertSandboxDataDepth(depth++);
|
|
16195
|
-
const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
16281
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
16196
16282
|
for (const key of Object.getOwnPropertyNames(properties)) {
|
|
16197
16283
|
if (seen.has(key)) continue;
|
|
16198
16284
|
seen.add(key);
|
|
@@ -16208,7 +16294,7 @@ function hasForInProperty(object, key, budget) {
|
|
|
16208
16294
|
for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
16209
16295
|
if (depth > 0) budget.visitNode();
|
|
16210
16296
|
assertSandboxDataDepth(depth++);
|
|
16211
|
-
const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
16297
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
16212
16298
|
if (Object.hasOwn(properties, key)) return true;
|
|
16213
16299
|
}
|
|
16214
16300
|
return false;
|
|
@@ -16764,7 +16850,7 @@ function getPropertyValue(target, property, context, receiver = target) {
|
|
|
16764
16850
|
if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
|
|
16765
16851
|
if (isSandboxCollectionIterator(target))
|
|
16766
16852
|
return getCollectionIteratorMember(target, property, context.budget);
|
|
16767
|
-
if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
|
|
16853
|
+
if (isSandboxGenerator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getGeneratorMember(target, property, context.budget);
|
|
16768
16854
|
if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
|
|
16769
16855
|
if (isSandboxPromise(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getPromiseMember(property, context.budget);
|
|
16770
16856
|
if (isSandboxRegex(target)) return hasExplicitSandboxPrototype(target) || getSandboxPrototype(target, context.budget) !== null ? void 0 : getRegexMember(target, property, context.budget, createCoercionContext(context));
|
|
@@ -17080,7 +17166,7 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
17080
17166
|
);
|
|
17081
17167
|
}
|
|
17082
17168
|
if (isSandboxGenerator(member.object)) {
|
|
17083
|
-
const memberValue =
|
|
17169
|
+
const memberValue = await getPropertyValue(member.object, member.property, context);
|
|
17084
17170
|
if (memberValue === void 0) {
|
|
17085
17171
|
throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
|
|
17086
17172
|
}
|
|
@@ -17384,7 +17470,7 @@ function hasSandboxProperty(value, key, context) {
|
|
|
17384
17470
|
while (typeof current === "object" && current !== null) {
|
|
17385
17471
|
if (isGuestHostObject(current)) return typeof key === "symbol" ? false : hasHostObjectMember(current, String(key));
|
|
17386
17472
|
if (hasOwnSandboxProperty(current, key, false)) return true;
|
|
17387
|
-
if (!isSandboxDate(current) && !isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
|
|
17473
|
+
if (!isSandboxDate(current) && !isSandboxRegex(current) && !isSandboxMap(current) && !isSandboxSet(current) && !((isGuestClosure(current) || isSandboxGenerator(current) || Array.isArray(current)) && hasExplicitSandboxPrototype(current)) && (Array.isArray(current) || !isPlainSandboxObject(current) || isSandboxDate(current) || isFloat32Array(current) || isSandboxGenerator(current) || isSandboxCollectionIterator(current) || isSandboxRegExpIterator(current))) {
|
|
17388
17474
|
return getPropertyValue(current, key, context) !== void 0;
|
|
17389
17475
|
}
|
|
17390
17476
|
current = getSandboxPrototype(current, context.budget);
|
|
@@ -17630,6 +17716,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
|
|
|
17630
17716
|
}
|
|
17631
17717
|
if (isGuestClosure(target)) target = materializeFunctionProperties(target);
|
|
17632
17718
|
if (isSandboxPromise(target)) target = getPromiseProperties(target);
|
|
17719
|
+
if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
|
|
17633
17720
|
if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
|
|
17634
17721
|
if (isFloat32Array(target)) {
|
|
17635
17722
|
if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
|
|
@@ -17663,7 +17750,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
|
|
|
17663
17750
|
for (let prototype = getSandboxPrototype(prototypeOwner, budget); prototype !== null; prototype = getSandboxPrototype(prototype, budget)) {
|
|
17664
17751
|
budget.visitNode();
|
|
17665
17752
|
assertSandboxDataDepth(depth++);
|
|
17666
|
-
const properties = isSandboxClosure(prototype) ? prototype.properties : prototype;
|
|
17753
|
+
const properties = isSandboxGenerator(prototype) ? getGeneratorProperties(prototype) : isSandboxClosure(prototype) ? prototype.properties : prototype;
|
|
17667
17754
|
const inherited = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
|
|
17668
17755
|
if (inherited === void 0) continue;
|
|
17669
17756
|
if (inherited.writable !== true)
|
|
@@ -17682,7 +17769,7 @@ function setSuperProperty(base, receiver, key, value, context) {
|
|
|
17682
17769
|
for (let current = base; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
17683
17770
|
budget.visitNode();
|
|
17684
17771
|
assertSandboxDataDepth(depth++);
|
|
17685
|
-
const properties = isSandboxClosure(current) ? current.properties : current;
|
|
17772
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxClosure(current) ? current.properties : current;
|
|
17686
17773
|
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key);
|
|
17687
17774
|
if (descriptor === void 0) continue;
|
|
17688
17775
|
if (!("value" in descriptor))
|
|
@@ -17700,6 +17787,7 @@ function deleteSandboxProperty(target, property) {
|
|
|
17700
17787
|
if (isGuestClosure(target)) target = materializeFunctionProperties(target);
|
|
17701
17788
|
if (isSandboxRegex(target)) target = getRegexProperties(target);
|
|
17702
17789
|
if (isSandboxPromise(target)) target = getPromiseProperties(target);
|
|
17790
|
+
if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
|
|
17703
17791
|
if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
|
|
17704
17792
|
if (Array.isArray(target)) {
|
|
17705
17793
|
assertCollectionMutable(target);
|
|
@@ -18266,11 +18354,11 @@ async function objectToPrimitive(value, budget, context, joining, hint, ordinary
|
|
|
18266
18354
|
}
|
|
18267
18355
|
}
|
|
18268
18356
|
function conversionHook(value, name, budget, context) {
|
|
18269
|
-
const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
|
|
18357
|
+
const implicitBuiltin = !hasExplicitSandboxPrototype(value) && (Array.isArray(value) && getSandboxPrototype(value, budget) === null || isFloat32Array(value) || sandboxErrorTypes.has(value) || isSandboxClosure(value) && getSandboxPrototype(value, budget) === null || isSandboxMap(value) || isSandboxSet(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value) || isSandboxPromise(value) || isSandboxRegex(value) && getSandboxPrototype(value, budget) === null || isSandboxGenerator(value) || isGuestHostObject(value));
|
|
18270
18358
|
let current = value;
|
|
18271
18359
|
let depth = 0;
|
|
18272
18360
|
while (current !== null) {
|
|
18273
|
-
const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
18361
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
18274
18362
|
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, name);
|
|
18275
18363
|
if (descriptor !== void 0) {
|
|
18276
18364
|
return readPropertyDescriptor(descriptor, value, context);
|
|
@@ -18483,8 +18571,7 @@ function hasOwnSandboxProperty(value, key, enumerable) {
|
|
|
18483
18571
|
properties = value.properties ?? /* @__PURE__ */ Object.create(null);
|
|
18484
18572
|
} else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
|
|
18485
18573
|
else if (isSandboxPromise(value)) properties = getPromiseProperties(value);
|
|
18486
|
-
else if (isSandboxGenerator(value))
|
|
18487
|
-
return false;
|
|
18574
|
+
else if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
|
|
18488
18575
|
else if (isSandboxRegex(value)) properties = getRegexProperties(value);
|
|
18489
18576
|
else properties = Object(value);
|
|
18490
18577
|
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
@@ -20153,6 +20240,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
20153
20240
|
state: value.state,
|
|
20154
20241
|
astNodeId: origin2.node.nodeId,
|
|
20155
20242
|
async: value.async === true,
|
|
20243
|
+
objectState: captureObjectState(value, encode),
|
|
20156
20244
|
scope: encode(origin2.scope),
|
|
20157
20245
|
closureScope: encode(origin2.closureScope),
|
|
20158
20246
|
...value.state !== "suspended" || origin2.suspendedScope === void 0 ? {} : { suspendedScope: encode(origin2.suspendedScope) },
|
|
@@ -20268,6 +20356,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
20268
20356
|
}
|
|
20269
20357
|
function captureObjectState(value, encode) {
|
|
20270
20358
|
let properties = value;
|
|
20359
|
+
if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
|
|
20271
20360
|
if (isSandboxClosure(value)) {
|
|
20272
20361
|
properties = value.properties;
|
|
20273
20362
|
if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
|
|
@@ -23854,6 +23943,31 @@ function createUriGlobals(budget) {
|
|
|
23854
23943
|
}));
|
|
23855
23944
|
}
|
|
23856
23945
|
|
|
23946
|
+
// packages/safe-js/src/interp/globals/function.ts
|
|
23947
|
+
function createFunctionPrototype(budget) {
|
|
23948
|
+
const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
|
|
23949
|
+
const properties = materializeFunctionProperties(prototype);
|
|
23950
|
+
Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
|
|
23951
|
+
for (const [name, length] of [["call", 1], ["apply", 2], ["bind", 1], ["toString", 0]]) {
|
|
23952
|
+
Object.defineProperty(properties, name, {
|
|
23953
|
+
writable: true,
|
|
23954
|
+
configurable: true,
|
|
23955
|
+
value: createSandboxClosure({
|
|
23956
|
+
guest: true,
|
|
23957
|
+
sandbox: true,
|
|
23958
|
+
name,
|
|
23959
|
+
length,
|
|
23960
|
+
call: (args, context) => callFunctionMethod(context?.thisValue, name, args, {
|
|
23961
|
+
budget,
|
|
23962
|
+
callClosure: (target, values, stack, thisValue, construct, newTarget) => context?.invokeClosure !== void 0 ? context.invokeClosure(target, values, thisValue, construct, newTarget) : invokeBuiltinClosure(target, values, budget, { ...context, stack, thisValue, newTarget }, thisValue, construct)
|
|
23963
|
+
}, context?.stack ?? [], context)
|
|
23964
|
+
})
|
|
23965
|
+
});
|
|
23966
|
+
}
|
|
23967
|
+
setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
23968
|
+
installFunctionPrototype(budget, prototype);
|
|
23969
|
+
}
|
|
23970
|
+
|
|
23857
23971
|
// packages/safe-js/src/interp/globals/symbol.ts
|
|
23858
23972
|
var registries = /* @__PURE__ */ new WeakMap();
|
|
23859
23973
|
function createSymbolGlobal(budget) {
|
|
@@ -24084,6 +24198,7 @@ function createBuiltinBindings(options) {
|
|
|
24084
24198
|
...createPromiseGlobals(options),
|
|
24085
24199
|
...createRegexGlobals(options)
|
|
24086
24200
|
};
|
|
24201
|
+
createFunctionPrototype(options.budget);
|
|
24087
24202
|
registerBuiltinIdentities(options.budget, bindings);
|
|
24088
24203
|
return bindings;
|
|
24089
24204
|
}
|
|
@@ -24254,7 +24369,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
24254
24369
|
}
|
|
24255
24370
|
state(node.state);
|
|
24256
24371
|
} else if (node.kind === "guest-generator") {
|
|
24257
|
-
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates"]);
|
|
24372
|
+
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState"]);
|
|
24373
|
+
if (Object.hasOwn(node, "objectState")) state(node.objectState);
|
|
24258
24374
|
if (!["start", "running", "suspended", "done"].includes(String(node.state)) || typeof node.async !== "boolean" || integer(node.astNodeId) < 1)
|
|
24259
24375
|
throw new TypeError("Invalid generator state.");
|
|
24260
24376
|
reference(node.scope, ["scope-frame"]);
|
|
@@ -25767,6 +25883,7 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
|
|
|
25767
25883
|
if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
|
|
25768
25884
|
else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
|
|
25769
25885
|
else if (isSandboxPromise(value)) entries = Object.entries(getPromiseProperties(value));
|
|
25886
|
+
else if (isSandboxGenerator(value)) entries = Object.entries(getGeneratorProperties(value));
|
|
25770
25887
|
else if (isSandboxMap(value) || isSandboxSet(value)) entries = Object.entries(getCollectionProperties(value));
|
|
25771
25888
|
else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
25772
25889
|
else entries = Object.entries(Object(value));
|
|
@@ -25778,19 +25895,20 @@ function ownSandboxSymbolKeys(value) {
|
|
|
25778
25895
|
if (isSandboxClosure(value)) value = value.properties ?? {};
|
|
25779
25896
|
else if (isSandboxRegex(value)) value = getRegexProperties(value);
|
|
25780
25897
|
else if (isSandboxPromise(value)) value = getPromiseProperties(value);
|
|
25898
|
+
else if (isSandboxGenerator(value)) value = getGeneratorProperties(value);
|
|
25781
25899
|
else if (isSandboxMap(value) || isSandboxSet(value)) value = getCollectionProperties(value);
|
|
25782
|
-
else if (isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
25783
25900
|
return Object.getOwnPropertySymbols(Object(value)).filter((key) => !internalSymbols.has(key));
|
|
25784
25901
|
}
|
|
25785
25902
|
function ownEnumerableSandboxKeys(value, includeSymbols = false) {
|
|
25786
25903
|
if (includeSymbols) {
|
|
25787
|
-
const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
|
|
25904
|
+
const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxGenerator(value) ? getGeneratorProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
|
|
25788
25905
|
return [...ownEnumerableSandboxKeys(value), ...ownSandboxSymbolKeys(value).filter((key) => Object.getOwnPropertyDescriptor(properties, key)?.enumerable === true)];
|
|
25789
25906
|
}
|
|
25790
25907
|
if (isGuestHostObject(value)) return getHostObjectKeys(value);
|
|
25791
25908
|
if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
|
|
25792
25909
|
if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
|
|
25793
25910
|
if (isSandboxPromise(value)) return Object.keys(getPromiseProperties(value));
|
|
25911
|
+
if (isSandboxGenerator(value)) return Object.keys(getGeneratorProperties(value));
|
|
25794
25912
|
if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
|
|
25795
25913
|
if (isSandboxMap(value) || isSandboxSet(value)) return Object.keys(getCollectionProperties(value));
|
|
25796
25914
|
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
@@ -25842,6 +25960,7 @@ function createSandboxGenerator(channel, metadata = void 0) {
|
|
|
25842
25960
|
enumerable: false,
|
|
25843
25961
|
value: true
|
|
25844
25962
|
});
|
|
25963
|
+
getGeneratorProperties(generator);
|
|
25845
25964
|
return generator;
|
|
25846
25965
|
}
|
|
25847
25966
|
function createSandboxMap(entries = []) {
|
|
@@ -26096,6 +26215,14 @@ function measureSandboxData(values, options = {}) {
|
|
|
26096
26215
|
return;
|
|
26097
26216
|
}
|
|
26098
26217
|
if (isSandboxGenerator(value)) {
|
|
26218
|
+
const descriptors3 = Object.getOwnPropertyDescriptors(getGeneratorProperties(value));
|
|
26219
|
+
for (const key of Reflect.ownKeys(descriptors3)) {
|
|
26220
|
+
const descriptor = descriptors3[key];
|
|
26221
|
+
usage += typeof key === "string" ? key.length + 1 : 1;
|
|
26222
|
+
if (typeof key === "symbol") visit(key, depth + 1);
|
|
26223
|
+
if ("value" in descriptor) visit(descriptor.value, depth + 1);
|
|
26224
|
+
else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
|
|
26225
|
+
}
|
|
26099
26226
|
const snapshot = value.channel.snapshot();
|
|
26100
26227
|
usage += snapshot.sent.length;
|
|
26101
26228
|
for (const completion of snapshot.sent) visit(completion.value, depth + 1);
|
|
@@ -40889,12 +41016,12 @@ export {
|
|
|
40889
41016
|
safeAddEvent,
|
|
40890
41017
|
safeRecordException,
|
|
40891
41018
|
safeEndSpan,
|
|
41019
|
+
runResources,
|
|
40892
41020
|
defineExtension,
|
|
40893
41021
|
encodeReplayData,
|
|
40894
41022
|
HostOperationResumePolicyError,
|
|
40895
41023
|
registerPendingHostCallPolicy,
|
|
40896
41024
|
HostCallResumabilityError,
|
|
40897
|
-
runResources,
|
|
40898
41025
|
assertSnapshotInactive,
|
|
40899
41026
|
isSandboxClosure,
|
|
40900
41027
|
deepCopyToSandbox,
|
|
@@ -40922,4 +41049,4 @@ export {
|
|
|
40922
41049
|
FileSnapshotBackend,
|
|
40923
41050
|
run
|
|
40924
41051
|
};
|
|
40925
|
-
//# sourceMappingURL=chunk-
|
|
41052
|
+
//# sourceMappingURL=chunk-M4L3EZHL.js.map
|