poe-code 14.0.79 → 14.0.81
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 +772 -341
- 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-2LNBLFJ3.js} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-BGSPSHLP.js → chunk-ZSYBRZU6.js} +644 -292
- package/packages/safe-js/dist/chunks/chunk-ZSYBRZU6.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/async.d.ts +1 -1
- package/packages/safe-js/dist/interp/async.js +65 -43
- package/packages/safe-js/dist/interp/bound-function-state.d.ts +7 -0
- package/packages/safe-js/dist/interp/bound-function-state.js +1 -0
- package/packages/safe-js/dist/interp/bound-function.d.ts +4 -0
- package/packages/safe-js/dist/interp/bound-function.js +18 -0
- 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/generator-prototypes.d.ts +6 -0
- package/packages/safe-js/dist/interp/generator-prototypes.js +1 -0
- package/packages/safe-js/dist/interp/globals/function.d.ts +2 -0
- package/packages/safe-js/dist/interp/globals/function.js +32 -0
- package/packages/safe-js/dist/interp/globals/generator.d.ts +2 -0
- package/packages/safe-js/dist/interp/globals/generator.js +51 -0
- package/packages/safe-js/dist/interp/globals/object-array.js +28 -7
- package/packages/safe-js/dist/interp/globals/object.js +2 -1
- package/packages/safe-js/dist/interp/globals.d.ts +1 -0
- package/packages/safe-js/dist/interp/globals.js +4 -0
- package/packages/safe-js/dist/interp/instanceof.d.ts +4 -0
- package/packages/safe-js/dist/interp/instanceof.js +58 -0
- package/packages/safe-js/dist/interp/interpreter.js +16 -47
- package/packages/safe-js/dist/interp/iteration.js +76 -5
- package/packages/safe-js/dist/interp/methods/function.d.ts +5 -2
- package/packages/safe-js/dist/interp/methods/function.js +55 -42
- package/packages/safe-js/dist/interp/methods/generator.d.ts +4 -1
- package/packages/safe-js/dist/interp/methods/generator.js +12 -6
- package/packages/safe-js/dist/interp/object-model.d.ts +1 -0
- package/packages/safe-js/dist/interp/object-model.js +69 -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 +27 -3
- package/packages/safe-js/dist/snapshot/guest-heap.d.ts +9 -0
- package/packages/safe-js/dist/snapshot/guest-heap.js +11 -0
- package/packages/safe-js/dist/snapshot/restore.js +61 -7
- package/packages/safe-js/dist/chunks/chunk-BGSPSHLP.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-B3AL4KJ3.js.map → chunk-2LNBLFJ3.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -126512,6 +126512,23 @@ var init_internal_symbols = __esm({
|
|
|
126512
126512
|
}
|
|
126513
126513
|
});
|
|
126514
126514
|
|
|
126515
|
+
// packages/safe-js/src/interp/generator-properties.ts
|
|
126516
|
+
function getGeneratorProperties(value) {
|
|
126517
|
+
let properties = generatorGuestProperties.get(value);
|
|
126518
|
+
if (properties === void 0) {
|
|
126519
|
+
properties = /* @__PURE__ */ Object.create(null);
|
|
126520
|
+
generatorGuestProperties.set(value, properties);
|
|
126521
|
+
}
|
|
126522
|
+
return properties;
|
|
126523
|
+
}
|
|
126524
|
+
var generatorGuestProperties;
|
|
126525
|
+
var init_generator_properties = __esm({
|
|
126526
|
+
"packages/safe-js/src/interp/generator-properties.ts"() {
|
|
126527
|
+
"use strict";
|
|
126528
|
+
generatorGuestProperties = /* @__PURE__ */ new WeakMap();
|
|
126529
|
+
}
|
|
126530
|
+
});
|
|
126531
|
+
|
|
126515
126532
|
// packages/safe-js/src/interp/regexp-properties.ts
|
|
126516
126533
|
function getRegexProperties(value) {
|
|
126517
126534
|
const properties = regexGuestProperties.get(value);
|
|
@@ -127035,7 +127052,7 @@ function walkGraphDepth(root, rootPath, assertDepth) {
|
|
|
127035
127052
|
}
|
|
127036
127053
|
}
|
|
127037
127054
|
function graphEntries(value) {
|
|
127038
|
-
const properties = regexGuestProperties.get(value);
|
|
127055
|
+
const properties = regexGuestProperties.get(value) ?? generatorGuestProperties.get(value);
|
|
127039
127056
|
if (properties !== void 0) return Reflect.ownKeys(properties).flatMap((key3) => {
|
|
127040
127057
|
const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
|
|
127041
127058
|
return "value" in descriptor ? [[`.${String(key3)}`, descriptor.value]] : [];
|
|
@@ -127079,6 +127096,7 @@ var init_graph_depth = __esm({
|
|
|
127079
127096
|
init_collection_brands();
|
|
127080
127097
|
init_boxed();
|
|
127081
127098
|
init_regexp_properties();
|
|
127099
|
+
init_generator_properties();
|
|
127082
127100
|
MAX_DATA_DEPTH = 1024;
|
|
127083
127101
|
SnapshotBudgetError = class extends Error {
|
|
127084
127102
|
code = "budgetExceeded";
|
|
@@ -127098,6 +127116,70 @@ var init_graph_depth = __esm({
|
|
|
127098
127116
|
}
|
|
127099
127117
|
});
|
|
127100
127118
|
|
|
127119
|
+
// packages/safe-js/src/interp/generator-prototypes.ts
|
|
127120
|
+
var generatorPrototypes;
|
|
127121
|
+
var init_generator_prototypes = __esm({
|
|
127122
|
+
"packages/safe-js/src/interp/generator-prototypes.ts"() {
|
|
127123
|
+
"use strict";
|
|
127124
|
+
generatorPrototypes = /* @__PURE__ */ new WeakMap();
|
|
127125
|
+
}
|
|
127126
|
+
});
|
|
127127
|
+
|
|
127128
|
+
// packages/safe-js/src/interp/resources.ts
|
|
127129
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
127130
|
+
function retainValues(budget, values) {
|
|
127131
|
+
const retained = {};
|
|
127132
|
+
budget.setRetainedValues(retained, values);
|
|
127133
|
+
const pending = runResources.getStore()?.referenceReleases;
|
|
127134
|
+
const release2 = () => {
|
|
127135
|
+
budget.setRetainedValues(retained, void 0);
|
|
127136
|
+
pending?.delete(release2);
|
|
127137
|
+
};
|
|
127138
|
+
pending?.add(release2);
|
|
127139
|
+
return release2;
|
|
127140
|
+
}
|
|
127141
|
+
async function withRunResources(signal, execute2) {
|
|
127142
|
+
const controller = new AbortController();
|
|
127143
|
+
const cancel2 = () => controller.abort(signal?.reason);
|
|
127144
|
+
const cleanups = /* @__PURE__ */ new Set();
|
|
127145
|
+
const resources = {
|
|
127146
|
+
signal: controller.signal,
|
|
127147
|
+
referenceReleases: /* @__PURE__ */ new Set(),
|
|
127148
|
+
add(close) {
|
|
127149
|
+
cleanups.add(close);
|
|
127150
|
+
}
|
|
127151
|
+
};
|
|
127152
|
+
signal?.addEventListener("abort", cancel2, { once: true });
|
|
127153
|
+
if (signal?.aborted) cancel2();
|
|
127154
|
+
let result;
|
|
127155
|
+
let failure;
|
|
127156
|
+
let errors2 = [];
|
|
127157
|
+
try {
|
|
127158
|
+
result = await runResources.run(resources, execute2);
|
|
127159
|
+
} catch (error3) {
|
|
127160
|
+
failure = { reason: error3 };
|
|
127161
|
+
} finally {
|
|
127162
|
+
signal?.removeEventListener("abort", cancel2);
|
|
127163
|
+
controller.abort(new Error("SafeJS run finished."));
|
|
127164
|
+
for (const release2 of resources.referenceReleases) release2();
|
|
127165
|
+
resources.referenceReleases.clear();
|
|
127166
|
+
const outcomes = await Promise.allSettled(
|
|
127167
|
+
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
127168
|
+
);
|
|
127169
|
+
errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
127170
|
+
}
|
|
127171
|
+
if (failure !== void 0) throw failure.reason;
|
|
127172
|
+
if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
|
|
127173
|
+
return result;
|
|
127174
|
+
}
|
|
127175
|
+
var runResources;
|
|
127176
|
+
var init_resources = __esm({
|
|
127177
|
+
"packages/safe-js/src/interp/resources.ts"() {
|
|
127178
|
+
"use strict";
|
|
127179
|
+
runResources = new AsyncLocalStorage4();
|
|
127180
|
+
}
|
|
127181
|
+
});
|
|
127182
|
+
|
|
127101
127183
|
// packages/safe-js/src/interp/symbols.ts
|
|
127102
127184
|
var wellKnownSymbols;
|
|
127103
127185
|
var init_symbols2 = __esm({
|
|
@@ -127615,9 +127697,23 @@ function materializeFunctionProperties(closure) {
|
|
|
127615
127697
|
descriptorObjects.add(prototype);
|
|
127616
127698
|
Object.defineProperty(properties, "prototype", { value: prototype, writable: true });
|
|
127617
127699
|
}
|
|
127618
|
-
|
|
127619
|
-
|
|
127620
|
-
|
|
127700
|
+
const state = { revision: 0 };
|
|
127701
|
+
const tracked = new Proxy(properties, {
|
|
127702
|
+
defineProperty(target, key3, descriptor) {
|
|
127703
|
+
const changed = Reflect.defineProperty(target, key3, descriptor);
|
|
127704
|
+
if (changed) state.revision++;
|
|
127705
|
+
return changed;
|
|
127706
|
+
},
|
|
127707
|
+
deleteProperty(target, key3) {
|
|
127708
|
+
const changed = Reflect.deleteProperty(target, key3);
|
|
127709
|
+
if (changed) state.revision++;
|
|
127710
|
+
return changed;
|
|
127711
|
+
}
|
|
127712
|
+
});
|
|
127713
|
+
functionPropertyRevisions.set(tracked, state);
|
|
127714
|
+
descriptorObjects.add(tracked);
|
|
127715
|
+
functionProperties.set(closure, tracked);
|
|
127716
|
+
return tracked;
|
|
127621
127717
|
}
|
|
127622
127718
|
function getGuestFunctionProperty(closure, key3) {
|
|
127623
127719
|
let properties = functionProperties.get(closure);
|
|
@@ -127635,6 +127731,12 @@ function installObjectPrototype(budget, prototype, constructor) {
|
|
|
127635
127731
|
intrinsicPrototypes.set(budget, prototype);
|
|
127636
127732
|
registerIntrinsicPrototype(budget, prototype, constructor);
|
|
127637
127733
|
}
|
|
127734
|
+
function installFunctionPrototype(budget, prototype) {
|
|
127735
|
+
functionPrototypes.set(budget, prototype);
|
|
127736
|
+
registerBuiltinIdentities(budget, { "%FunctionPrototype%": prototype });
|
|
127737
|
+
registerIntrinsicFunction(budget, prototype);
|
|
127738
|
+
registerIntrinsicObject(budget, materializeFunctionProperties(prototype));
|
|
127739
|
+
}
|
|
127638
127740
|
function installBoxedPrototype(budget, prototype, constructor, kind = typeof boxedValue(prototype)) {
|
|
127639
127741
|
let state = boxedPrototypes.get(budget);
|
|
127640
127742
|
if (state === void 0) boxedPrototypes.set(budget, state = /* @__PURE__ */ new Map());
|
|
@@ -127721,6 +127823,9 @@ function trackIntrinsicState(budget, root, owner, targets) {
|
|
|
127721
127823
|
explicit: hasExplicitSandboxPrototype(target)
|
|
127722
127824
|
})).map((record4) => ({
|
|
127723
127825
|
...record4,
|
|
127826
|
+
revision: functionPropertyRevisions.get(record4.value),
|
|
127827
|
+
capturedRevision: -1,
|
|
127828
|
+
captured: [],
|
|
127724
127829
|
extensible: Object.isExtensible(record4.value),
|
|
127725
127830
|
descriptors: new Map(Reflect.ownKeys(record4.value).map((key3) => [key3, Object.getOwnPropertyDescriptor(record4.value, key3)]))
|
|
127726
127831
|
}));
|
|
@@ -127736,14 +127841,21 @@ function trackIntrinsicState(budget, root, owner, targets) {
|
|
|
127736
127841
|
);
|
|
127737
127842
|
budget.setRetainedValues(root, () => {
|
|
127738
127843
|
const retained = [];
|
|
127739
|
-
for (const
|
|
127844
|
+
for (const record4 of records) {
|
|
127845
|
+
const { target, value, descriptors: descriptors2, prototype: parent, revision: revision2 } = record4;
|
|
127740
127846
|
const currentPrototype = getSandboxPrototype(target);
|
|
127741
127847
|
if (currentPrototype !== parent) retained.push(currentPrototype);
|
|
127742
|
-
|
|
127743
|
-
const
|
|
127744
|
-
|
|
127745
|
-
|
|
127848
|
+
if (revision2 === void 0 || revision2.revision !== record4.capturedRevision) {
|
|
127849
|
+
const captured = [];
|
|
127850
|
+
for (const key3 of Reflect.ownKeys(value)) {
|
|
127851
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key3);
|
|
127852
|
+
if (unchanged(descriptors2.get(key3), descriptor)) continue;
|
|
127853
|
+
captured.push(key3, descriptor.value, ...retainedAccessorClosures(descriptor));
|
|
127854
|
+
}
|
|
127855
|
+
record4.captured = captured;
|
|
127856
|
+
record4.capturedRevision = revision2?.revision ?? -1;
|
|
127746
127857
|
}
|
|
127858
|
+
for (const item of record4.captured) retained.push(item);
|
|
127747
127859
|
}
|
|
127748
127860
|
return retained;
|
|
127749
127861
|
});
|
|
@@ -127759,11 +127871,15 @@ function releaseObjectPrototype(budget) {
|
|
|
127759
127871
|
promisePrototypes.delete(budget);
|
|
127760
127872
|
datePrototypes.delete(budget);
|
|
127761
127873
|
arrayPrototypes.delete(budget);
|
|
127874
|
+
functionPrototypes.delete(budget);
|
|
127875
|
+
generatorPrototypes.delete(budget);
|
|
127762
127876
|
initialRegexDescriptors.delete(budget);
|
|
127763
127877
|
intrinsicPrototypes.delete(budget);
|
|
127764
127878
|
}
|
|
127765
127879
|
function getSandboxPrototype(value, budget) {
|
|
127766
127880
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
127881
|
+
if (budget !== void 0 && isGuestClosure(value) && runResources.getStore()?.functionSourceText !== false)
|
|
127882
|
+
return functionPrototypes.get(budget) ?? null;
|
|
127767
127883
|
if (budget !== void 0 && Array.isArray(value)) return arrayPrototypes.get(budget) ?? null;
|
|
127768
127884
|
if (budget !== void 0 && isSandboxDate(value)) return datePrototypes.get(budget) ?? null;
|
|
127769
127885
|
if (budget !== void 0 && isSandboxPromise(value)) return promisePrototypes.get(budget) ?? null;
|
|
@@ -127788,8 +127904,15 @@ function getSandboxPropertyDescriptor(value, key3, budget) {
|
|
|
127788
127904
|
return hostProperties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(hostProperties, key3);
|
|
127789
127905
|
let current = value;
|
|
127790
127906
|
let depth = 0;
|
|
127791
|
-
while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
|
|
127792
|
-
const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
127907
|
+
while (typeof current === "object" && current !== null && (Array.isArray(current) || isSandboxGenerator(current) || isSandboxDate(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxMap(current) || isSandboxSet(current) || isPrototypeRecord(current))) {
|
|
127908
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? key3 === "prototype" && current.construct !== void 0 && current.boundTarget === void 0 ? materializeFunctionProperties(current) : getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
127909
|
+
if (properties === void 0 && isGuestClosure(current) && (key3 === "name" || key3 === "length"))
|
|
127910
|
+
return {
|
|
127911
|
+
value: key3 === "name" ? current.name ?? "" : current.length ?? 0,
|
|
127912
|
+
writable: false,
|
|
127913
|
+
enumerable: false,
|
|
127914
|
+
configurable: true
|
|
127915
|
+
};
|
|
127793
127916
|
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
|
|
127794
127917
|
if (descriptor !== void 0) return descriptor;
|
|
127795
127918
|
current = getSandboxPrototype(current, budget);
|
|
@@ -127807,6 +127930,10 @@ function getSandboxDataProperty(value, key3, budget) {
|
|
|
127807
127930
|
if (isGuestHostObject(current)) return typeof key3 === "symbol" ? void 0 : getHostObjectMember(current, String(key3));
|
|
127808
127931
|
if (isSandboxRegex(current)) return Object.getOwnPropertyDescriptor(getRegexProperties(current), key3)?.value;
|
|
127809
127932
|
if (isSandboxPromise(current)) return Object.getOwnPropertyDescriptor(getPromiseProperties(current), key3)?.value;
|
|
127933
|
+
if (isSandboxGenerator(current)) {
|
|
127934
|
+
const descriptor = Object.getOwnPropertyDescriptor(getGeneratorProperties(current), key3);
|
|
127935
|
+
if (descriptor !== void 0) return descriptor.value;
|
|
127936
|
+
}
|
|
127810
127937
|
if (isSandboxMap(current) || isSandboxSet(current)) return Object.getOwnPropertyDescriptor(getCollectionProperties(current), key3)?.value;
|
|
127811
127938
|
if (isGuestClosure(current)) {
|
|
127812
127939
|
const entry = getGuestFunctionProperty(current, key3);
|
|
@@ -127815,9 +127942,9 @@ function getSandboxDataProperty(value, key3, budget) {
|
|
|
127815
127942
|
const properties = current.properties;
|
|
127816
127943
|
return properties !== void 0 && Object.hasOwn(properties, key3) ? properties[key3] : void 0;
|
|
127817
127944
|
}
|
|
127818
|
-
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current)
|
|
127945
|
+
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current))
|
|
127819
127946
|
return void 0;
|
|
127820
|
-
if (!isSandboxClosure(current) && Object.hasOwn(current, key3)) return current[key3];
|
|
127947
|
+
if (!isSandboxClosure(current) && !isSandboxGenerator(current) && Object.hasOwn(current, key3)) return current[key3];
|
|
127821
127948
|
current = getSandboxPrototype(current, budget);
|
|
127822
127949
|
if (current !== null) {
|
|
127823
127950
|
budget?.visitNode();
|
|
@@ -127830,7 +127957,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
127830
127957
|
if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
|
|
127831
127958
|
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
127832
127959
|
}
|
|
127833
|
-
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)) {
|
|
127960
|
+
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)) {
|
|
127834
127961
|
throw new TypeError(
|
|
127835
127962
|
"Prototype links require supported sandbox objects."
|
|
127836
127963
|
);
|
|
@@ -127839,7 +127966,7 @@ function setSandboxPrototype(value, prototype, budget) {
|
|
|
127839
127966
|
if (prototype === null) prototypes.set(value, null);
|
|
127840
127967
|
return;
|
|
127841
127968
|
}
|
|
127842
|
-
if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value)) {
|
|
127969
|
+
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)) {
|
|
127843
127970
|
throw new TypeError("Cannot change the prototype of a non-extensible object.");
|
|
127844
127971
|
}
|
|
127845
127972
|
let depth = 0;
|
|
@@ -127874,11 +128001,14 @@ function hasGuestObjectState(value) {
|
|
|
127874
128001
|
(descriptor) => !descriptor.enumerable || !descriptor.configurable || !descriptor.writable
|
|
127875
128002
|
);
|
|
127876
128003
|
}
|
|
127877
|
-
var guestClosures, functionProperties, prototypes, intrinsicPrototypes, boxedPrototypes, regexPrototypes, collectionPrototypes, promisePrototypes, datePrototypes, arrayPrototypes, initialArrayMethods, initialRegexDescriptors, intrinsicPrototypeRoots, intrinsicConstructors, intrinsicFunctions, initialBoxedMethods, descriptorObjects;
|
|
128004
|
+
var guestClosures, functionProperties, functionPropertyRevisions, prototypes, intrinsicPrototypes, boxedPrototypes, regexPrototypes, collectionPrototypes, promisePrototypes, datePrototypes, arrayPrototypes, functionPrototypes, initialArrayMethods, initialRegexDescriptors, intrinsicPrototypeRoots, intrinsicConstructors, intrinsicFunctions, initialBoxedMethods, descriptorObjects;
|
|
127878
128005
|
var init_object_model = __esm({
|
|
127879
128006
|
"packages/safe-js/src/interp/object-model.ts"() {
|
|
127880
128007
|
"use strict";
|
|
127881
128008
|
init_graph_depth();
|
|
128009
|
+
init_generator_properties();
|
|
128010
|
+
init_generator_prototypes();
|
|
128011
|
+
init_resources();
|
|
127882
128012
|
init_intrinsics();
|
|
127883
128013
|
init_template_objects();
|
|
127884
128014
|
init_date();
|
|
@@ -127888,6 +128018,7 @@ var init_object_model = __esm({
|
|
|
127888
128018
|
init_values();
|
|
127889
128019
|
guestClosures = /* @__PURE__ */ new WeakSet();
|
|
127890
128020
|
functionProperties = /* @__PURE__ */ new WeakMap();
|
|
128021
|
+
functionPropertyRevisions = /* @__PURE__ */ new WeakMap();
|
|
127891
128022
|
prototypes = /* @__PURE__ */ new WeakMap();
|
|
127892
128023
|
intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
|
|
127893
128024
|
boxedPrototypes = /* @__PURE__ */ new WeakMap();
|
|
@@ -127896,6 +128027,7 @@ var init_object_model = __esm({
|
|
|
127896
128027
|
promisePrototypes = /* @__PURE__ */ new WeakMap();
|
|
127897
128028
|
datePrototypes = /* @__PURE__ */ new WeakMap();
|
|
127898
128029
|
arrayPrototypes = /* @__PURE__ */ new WeakMap();
|
|
128030
|
+
functionPrototypes = /* @__PURE__ */ new WeakMap();
|
|
127899
128031
|
initialArrayMethods = /* @__PURE__ */ new WeakMap();
|
|
127900
128032
|
initialRegexDescriptors = /* @__PURE__ */ new WeakMap();
|
|
127901
128033
|
intrinsicPrototypeRoots = /* @__PURE__ */ new WeakMap();
|
|
@@ -128000,7 +128132,7 @@ var init_float32 = __esm({
|
|
|
128000
128132
|
});
|
|
128001
128133
|
|
|
128002
128134
|
// packages/safe-js/src/interp/promise-tracker.ts
|
|
128003
|
-
import { AsyncLocalStorage as
|
|
128135
|
+
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
128004
128136
|
function assertPromiseExecutionAllowed() {
|
|
128005
128137
|
const failure = activePromiseTracker.getStore()?.failure;
|
|
128006
128138
|
if (failure !== void 0 && fatalRejectionCleanup.getStore() !== true) throw failure;
|
|
@@ -128114,13 +128246,13 @@ var init_promise_tracker = __esm({
|
|
|
128114
128246
|
return void 0;
|
|
128115
128247
|
}
|
|
128116
128248
|
};
|
|
128117
|
-
activePromiseTracker = new
|
|
128118
|
-
fatalRejectionCleanup = new
|
|
128249
|
+
activePromiseTracker = new AsyncLocalStorage5();
|
|
128250
|
+
fatalRejectionCleanup = new AsyncLocalStorage5();
|
|
128119
128251
|
}
|
|
128120
128252
|
});
|
|
128121
128253
|
|
|
128122
128254
|
// packages/safe-js/src/interp/promise-replay.ts
|
|
128123
|
-
import { AsyncLocalStorage as
|
|
128255
|
+
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
128124
128256
|
function validateReplay(value) {
|
|
128125
128257
|
validateSnapshotData(value);
|
|
128126
128258
|
if (value === null || typeof value !== "object" || !("version" in value) || value.version !== 1 || !("steps" in value) || !isCounter(value.steps) || !("promises" in value) || !isCounter(value.promises) || !("settlements" in value) || !Array.isArray(value.settlements)) {
|
|
@@ -128469,7 +128601,7 @@ var init_promise_replay = __esm({
|
|
|
128469
128601
|
this.liveWaiters.clear();
|
|
128470
128602
|
}
|
|
128471
128603
|
};
|
|
128472
|
-
promiseReplayContext = new
|
|
128604
|
+
promiseReplayContext = new AsyncLocalStorage6();
|
|
128473
128605
|
}
|
|
128474
128606
|
});
|
|
128475
128607
|
|
|
@@ -130389,61 +130521,6 @@ var init_engine2 = __esm({
|
|
|
130389
130521
|
}
|
|
130390
130522
|
});
|
|
130391
130523
|
|
|
130392
|
-
// packages/safe-js/src/interp/resources.ts
|
|
130393
|
-
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
130394
|
-
function retainValues(budget, values) {
|
|
130395
|
-
const retained = {};
|
|
130396
|
-
budget.setRetainedValues(retained, values);
|
|
130397
|
-
const pending = runResources.getStore()?.referenceReleases;
|
|
130398
|
-
const release2 = () => {
|
|
130399
|
-
budget.setRetainedValues(retained, void 0);
|
|
130400
|
-
pending?.delete(release2);
|
|
130401
|
-
};
|
|
130402
|
-
pending?.add(release2);
|
|
130403
|
-
return release2;
|
|
130404
|
-
}
|
|
130405
|
-
async function withRunResources(signal, execute2) {
|
|
130406
|
-
const controller = new AbortController();
|
|
130407
|
-
const cancel2 = () => controller.abort(signal?.reason);
|
|
130408
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
130409
|
-
const resources = {
|
|
130410
|
-
signal: controller.signal,
|
|
130411
|
-
referenceReleases: /* @__PURE__ */ new Set(),
|
|
130412
|
-
add(close) {
|
|
130413
|
-
cleanups.add(close);
|
|
130414
|
-
}
|
|
130415
|
-
};
|
|
130416
|
-
signal?.addEventListener("abort", cancel2, { once: true });
|
|
130417
|
-
if (signal?.aborted) cancel2();
|
|
130418
|
-
let result;
|
|
130419
|
-
let failure;
|
|
130420
|
-
let errors2 = [];
|
|
130421
|
-
try {
|
|
130422
|
-
result = await runResources.run(resources, execute2);
|
|
130423
|
-
} catch (error3) {
|
|
130424
|
-
failure = { reason: error3 };
|
|
130425
|
-
} finally {
|
|
130426
|
-
signal?.removeEventListener("abort", cancel2);
|
|
130427
|
-
controller.abort(new Error("SafeJS run finished."));
|
|
130428
|
-
for (const release2 of resources.referenceReleases) release2();
|
|
130429
|
-
resources.referenceReleases.clear();
|
|
130430
|
-
const outcomes = await Promise.allSettled(
|
|
130431
|
-
[...cleanups].map((close) => Promise.resolve().then(close))
|
|
130432
|
-
);
|
|
130433
|
-
errors2 = outcomes.flatMap((outcome) => outcome.status === "rejected" ? [outcome.reason] : []);
|
|
130434
|
-
}
|
|
130435
|
-
if (failure !== void 0) throw failure.reason;
|
|
130436
|
-
if (errors2.length > 0) throw new AggregateError(errors2, "SafeJS resource cleanup failed.");
|
|
130437
|
-
return result;
|
|
130438
|
-
}
|
|
130439
|
-
var runResources;
|
|
130440
|
-
var init_resources = __esm({
|
|
130441
|
-
"packages/safe-js/src/interp/resources.ts"() {
|
|
130442
|
-
"use strict";
|
|
130443
|
-
runResources = new AsyncLocalStorage6();
|
|
130444
|
-
}
|
|
130445
|
-
});
|
|
130446
|
-
|
|
130447
130524
|
// packages/safe-js/src/interp/bigint-operators.ts
|
|
130448
130525
|
function bigIntOperation(operator, left, right, budget) {
|
|
130449
130526
|
if (operator === ">>>") throw new TypeError("BigInts have no unsigned right shift.");
|
|
@@ -130865,7 +130942,10 @@ async function restoreSandboxIterator(snapshot2, budget, context, signal) {
|
|
|
130865
130942
|
if (snapshot2.kind === "guest") return guestIterator(snapshot2.value, snapshot2.next, snapshot2.async, budget, context, signal);
|
|
130866
130943
|
if (snapshot2.kind === "async-from-sync") return asyncFromSyncIterator(await restoreSandboxIterator(snapshot2.inner, budget, context, signal), budget, signal, context);
|
|
130867
130944
|
if (Array.isArray(snapshot2.value)) return arrayIterator(snapshot2.value, context, budget, snapshot2.index);
|
|
130868
|
-
const iterator = isSandboxGenerator(snapshot2.value)
|
|
130945
|
+
const iterator = isSandboxGenerator(snapshot2.value) ? {
|
|
130946
|
+
...generatorObjectIterator(snapshot2.value, budget, context),
|
|
130947
|
+
...snapshot2.value.async ? { asyncProtocol: true } : {}
|
|
130948
|
+
} : getSandboxIterator(snapshot2.value, budget, context);
|
|
130869
130949
|
if (iterator === void 0) throw new TypeError("Invalid builtin iterator snapshot.");
|
|
130870
130950
|
for (let index = 0; index < snapshot2.index; index++) await iterator.next();
|
|
130871
130951
|
return iterator;
|
|
@@ -130875,9 +130955,13 @@ async function acquireSandboxIterator(value, budget, context, asyncProtocol = fa
|
|
|
130875
130955
|
if (context.getProperty === void 0 || isGuestHostObject(value))
|
|
130876
130956
|
return asyncProtocol ? getSandboxAsyncIterator(value, budget, context, signal) : getSandboxIterator(value, budget, context);
|
|
130877
130957
|
if (getSandboxPropertyDescriptor(value, key3, budget) === void 0 && !(isSandboxRegExpIterator(value) && !asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)) {
|
|
130958
|
+
if (isSandboxGenerator(value)) {
|
|
130959
|
+
if (!hasExplicitSandboxPrototype(value) && value.async === true === asyncProtocol && getSandboxPropertyDescriptor(value, "next", budget) !== void 0)
|
|
130960
|
+
return guestIterator(value, await context.getProperty(value, "next"), asyncProtocol, budget, context, signal);
|
|
130961
|
+
}
|
|
130878
130962
|
if (!asyncProtocol && Array.isArray(value) && getSandboxPrototype(value, budget) !== null) return void 0;
|
|
130879
130963
|
if (!asyncProtocol) return getSandboxIterator(value, budget, context);
|
|
130880
|
-
if (isSandboxGenerator(value) && value.async)
|
|
130964
|
+
if (isSandboxGenerator(value) && value.async && !hasExplicitSandboxPrototype(value))
|
|
130881
130965
|
return getSandboxAsyncIterator(value, budget, context, signal);
|
|
130882
130966
|
const iterator2 = await acquireSandboxIterator(value, budget, context);
|
|
130883
130967
|
return iterator2 === void 0 ? void 0 : asyncFromSyncIterator(iterator2, budget, signal, context);
|
|
@@ -130939,7 +131023,7 @@ async function readIteratorResult(iterator, result, property) {
|
|
|
130939
131023
|
}
|
|
130940
131024
|
function getSandboxAsyncIterator(value, budget, context, signal) {
|
|
130941
131025
|
if (isSandboxGenerator(value) && value.async) {
|
|
130942
|
-
return { ...
|
|
131026
|
+
return hasExplicitSandboxPrototype(value) ? context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget, context, true, signal) : void 0 : { ...generatorObjectIterator(value, budget, context), asyncProtocol: true };
|
|
130943
131027
|
}
|
|
130944
131028
|
if (value !== null && (typeof value === "object" || typeof value === "function") && !isGuestHostObject(value)) {
|
|
130945
131029
|
const method = value[Symbol.asyncIterator];
|
|
@@ -131089,7 +131173,9 @@ function getSandboxIterator(value, budget, context) {
|
|
|
131089
131173
|
return syncIterator(Float32Array.prototype.values.call(value));
|
|
131090
131174
|
}
|
|
131091
131175
|
if (isSandboxGenerator(value)) {
|
|
131092
|
-
|
|
131176
|
+
if (value.async) return void 0;
|
|
131177
|
+
if (hasExplicitSandboxPrototype(value)) return context?.getProperty === void 0 ? generatorProtocolAdapter(value, budget ?? new Budget(), context, false) : void 0;
|
|
131178
|
+
return generatorObjectIterator(value, budget, context);
|
|
131093
131179
|
}
|
|
131094
131180
|
if (typeof value === "string") {
|
|
131095
131181
|
const iterator2 = value[Symbol.iterator]();
|
|
@@ -131165,6 +131251,58 @@ function collectionIterator(collection, value) {
|
|
|
131165
131251
|
adapter.snapshot = () => ({ kind: "builtin", value, index: adapter.snapshotIndex() });
|
|
131166
131252
|
return adapter;
|
|
131167
131253
|
}
|
|
131254
|
+
function generatorProtocolAdapter(value, budget, context, asyncProtocol, signal) {
|
|
131255
|
+
const bridge = {
|
|
131256
|
+
...context,
|
|
131257
|
+
stack: context?.stack ?? [],
|
|
131258
|
+
thisValue: value,
|
|
131259
|
+
invokeClosure: (closure, args, receiver, construct) => invokeBuiltinClosure(closure, args, budget, context, receiver, construct),
|
|
131260
|
+
getProperty: (target, key3) => {
|
|
131261
|
+
const descriptor = getSandboxPropertyDescriptor(target, key3, budget);
|
|
131262
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, target, bridge, true);
|
|
131263
|
+
}
|
|
131264
|
+
};
|
|
131265
|
+
let resolved;
|
|
131266
|
+
let pending;
|
|
131267
|
+
const initialize = () => pending ??= acquireSandboxIterator(value, budget, bridge, asyncProtocol, signal).then((iterator) => {
|
|
131268
|
+
if (iterator === void 0) throw new TypeError("Generator does not provide an iterator protocol.");
|
|
131269
|
+
return resolved = iterator;
|
|
131270
|
+
});
|
|
131271
|
+
return {
|
|
131272
|
+
asynchronous: true,
|
|
131273
|
+
...asyncProtocol ? { asyncProtocol: true } : {},
|
|
131274
|
+
get retainedValue() {
|
|
131275
|
+
return [value, resolved?.retainedValue];
|
|
131276
|
+
},
|
|
131277
|
+
snapshot: () => resolved?.snapshot?.() ?? { kind: "unsupported" },
|
|
131278
|
+
next: async (...args) => (await initialize()).next(...args),
|
|
131279
|
+
getOperation: async (method) => {
|
|
131280
|
+
const iterator = await initialize();
|
|
131281
|
+
return iterator.getOperation === void 0 ? iterator[method] : iterator.getOperation(method);
|
|
131282
|
+
},
|
|
131283
|
+
readResultProperty: async (result, property) => readIteratorResult(await initialize(), result, property)
|
|
131284
|
+
};
|
|
131285
|
+
}
|
|
131286
|
+
function generatorObjectIterator(generator, budget, context) {
|
|
131287
|
+
const iterator = generatorIterator(generator, budget, context);
|
|
131288
|
+
if (context?.getProperty === void 0) return iterator;
|
|
131289
|
+
return {
|
|
131290
|
+
...iterator,
|
|
131291
|
+
getOperation: async (method) => {
|
|
131292
|
+
if (method === "next" || !hasExplicitSandboxPrototype(generator) && getSandboxPropertyDescriptor(generator, method, budget) === void 0) return iterator[method];
|
|
131293
|
+
const operation = await context.getProperty(generator, method);
|
|
131294
|
+
if (operation === void 0 || operation === null) return void 0;
|
|
131295
|
+
if (!isSandboxClosure(operation)) throw new TypeError("Iterator operation must be callable.");
|
|
131296
|
+
return async (...args) => {
|
|
131297
|
+
const result = await invokeBuiltinClosure(operation, args, budget ?? new Budget(), context, generator);
|
|
131298
|
+
return generator.async ? await awaitSandboxValue(result, void 0, budget, context) : result;
|
|
131299
|
+
};
|
|
131300
|
+
},
|
|
131301
|
+
readResultProperty: async (result, property) => ({
|
|
131302
|
+
value: await context.getProperty(result, property)
|
|
131303
|
+
})
|
|
131304
|
+
};
|
|
131305
|
+
}
|
|
131168
131306
|
function generatorIterator(generator, budget, context) {
|
|
131169
131307
|
const invoke2 = async (method, value) => {
|
|
131170
131308
|
const leaveRunning = enterRunningState(generator);
|
|
@@ -131249,6 +131387,7 @@ var init_iteration = __esm({
|
|
|
131249
131387
|
init_builtin_call();
|
|
131250
131388
|
init_object_model();
|
|
131251
131389
|
init_intrinsics();
|
|
131390
|
+
init_accessors();
|
|
131252
131391
|
asyncGeneratorRequests = /* @__PURE__ */ new WeakMap();
|
|
131253
131392
|
}
|
|
131254
131393
|
});
|
|
@@ -131665,12 +131804,12 @@ async function evaluateFunctionExpression(node, context, evaluateNode3) {
|
|
|
131665
131804
|
value: closure
|
|
131666
131805
|
};
|
|
131667
131806
|
}
|
|
131668
|
-
function createInterpretedClosure(node, context, evaluateNode3, homeObject) {
|
|
131807
|
+
function createInterpretedClosure(node, context, evaluateNode3, homeObject, initializeGeneratorPrototype = true) {
|
|
131669
131808
|
if (node.type !== "ArrowFunctionExpression") {
|
|
131670
131809
|
context = { ...context, functionEnvironment: { homeObject } };
|
|
131671
131810
|
}
|
|
131672
131811
|
if (node.type !== "ArrowFunctionExpression" && node.generator) {
|
|
131673
|
-
return createGeneratorClosure(node, context, evaluateNode3);
|
|
131812
|
+
return createGeneratorClosure(node, context, evaluateNode3, initializeGeneratorPrototype);
|
|
131674
131813
|
}
|
|
131675
131814
|
const construct = node.type !== "ArrowFunctionExpression" && !(node.type === "FunctionExpression" && node.method === true) && !node.async ? async (args, callContext) => {
|
|
131676
131815
|
const thisValue = {};
|
|
@@ -131757,7 +131896,8 @@ function executeAsyncFunction(execute2, budget, signal, callContext) {
|
|
|
131757
131896
|
});
|
|
131758
131897
|
return createSandboxPromise(promise, { synchronousPrefix });
|
|
131759
131898
|
}
|
|
131760
|
-
function createGeneratorClosure(node, context, evaluateNode3) {
|
|
131899
|
+
function createGeneratorClosure(node, context, evaluateNode3, initializePrototype) {
|
|
131900
|
+
const prototypes2 = !initializePrototype || runResources.getStore()?.functionSourceText === false ? void 0 : generatorPrototypes.get(context.budget)?.get(node.async === true);
|
|
131761
131901
|
const closure = createSandboxClosure({
|
|
131762
131902
|
sourceRange: functionSources.get(node),
|
|
131763
131903
|
guest: true,
|
|
@@ -131767,54 +131907,69 @@ function createGeneratorClosure(node, context, evaluateNode3) {
|
|
|
131767
131907
|
...node.id === void 0 ? { name: context.inferredName } : { name: node.id.name },
|
|
131768
131908
|
retainedValues: () => [...context.scope.retainedValues(), context.functionEnvironment?.homeObject, context.functionEnvironment?.newTarget],
|
|
131769
131909
|
call: async (args, callContext) => {
|
|
131770
|
-
const
|
|
131771
|
-
|
|
131772
|
-
|
|
131773
|
-
|
|
131774
|
-
|
|
131775
|
-
|
|
131776
|
-
|
|
131777
|
-
|
|
131778
|
-
callContext?.thisValue,
|
|
131779
|
-
closureContext,
|
|
131780
|
-
evaluateNode3
|
|
131781
|
-
);
|
|
131782
|
-
const channel = createGeneratorChannel((generatorYield) => {
|
|
131783
|
-
const execute2 = async () => {
|
|
131784
|
-
const result = await evaluateNode3(node.body, {
|
|
131785
|
-
...closureContext,
|
|
131786
|
-
functionBody: node.body,
|
|
131787
|
-
asyncGenerator: node.async,
|
|
131788
|
-
generatorBlockScopes: /* @__PURE__ */ new Map(),
|
|
131789
|
-
generatorExpressionStates: /* @__PURE__ */ new Map(),
|
|
131790
|
-
captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
|
|
131791
|
-
origin.suspendedScope = suspendedScope;
|
|
131792
|
-
origin.blockScopes = blocks;
|
|
131793
|
-
origin.finallyCompletions = completions;
|
|
131794
|
-
origin.expressionStates = expressions;
|
|
131795
|
-
},
|
|
131796
|
-
generatorYield: (value2, yieldNodeId) => {
|
|
131797
|
-
generator.state = "suspended";
|
|
131798
|
-
return generatorYield(value2, yieldNodeId);
|
|
131799
|
-
},
|
|
131800
|
-
scope
|
|
131801
|
-
});
|
|
131802
|
-
if (result.kind === "error") {
|
|
131803
|
-
throw result.error;
|
|
131804
|
-
}
|
|
131805
|
-
if (result.kind === "throw") {
|
|
131806
|
-
throw result.value;
|
|
131807
|
-
}
|
|
131808
|
-
const value = result.hasValue ? result.value : void 0;
|
|
131809
|
-
return node.async ? awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)) : value;
|
|
131910
|
+
const candidate = prototypes2 === void 0 ? void 0 : getGuestFunctionProperty(closure, "prototype");
|
|
131911
|
+
const prototype = typeof candidate === "object" && candidate !== null ? candidate : prototypes2?.instancePrototype;
|
|
131912
|
+
const releasePrototype = prototype === void 0 ? void 0 : retainValues(context.budget, () => [prototype]);
|
|
131913
|
+
try {
|
|
131914
|
+
const closureContext = {
|
|
131915
|
+
...context,
|
|
131916
|
+
compilation: callContext?.compilation ?? context.compilation,
|
|
131917
|
+
callStack: [...callContext?.stack ?? context.callStack]
|
|
131810
131918
|
};
|
|
131811
|
-
|
|
131812
|
-
|
|
131813
|
-
|
|
131814
|
-
|
|
131815
|
-
|
|
131919
|
+
const scope = await createClosureScope(
|
|
131920
|
+
node,
|
|
131921
|
+
args,
|
|
131922
|
+
callContext?.thisValue,
|
|
131923
|
+
closureContext,
|
|
131924
|
+
evaluateNode3
|
|
131925
|
+
);
|
|
131926
|
+
const channel = createGeneratorChannel((generatorYield) => {
|
|
131927
|
+
const execute2 = async () => {
|
|
131928
|
+
const result = await evaluateNode3(node.body, {
|
|
131929
|
+
...closureContext,
|
|
131930
|
+
functionBody: node.body,
|
|
131931
|
+
asyncGenerator: node.async,
|
|
131932
|
+
generatorBlockScopes: /* @__PURE__ */ new Map(),
|
|
131933
|
+
generatorExpressionStates: /* @__PURE__ */ new Map(),
|
|
131934
|
+
captureGeneratorScope: (suspendedScope, blocks, completions, expressions) => {
|
|
131935
|
+
origin.suspendedScope = suspendedScope;
|
|
131936
|
+
origin.blockScopes = blocks;
|
|
131937
|
+
origin.finallyCompletions = completions;
|
|
131938
|
+
origin.expressionStates = expressions;
|
|
131939
|
+
},
|
|
131940
|
+
generatorYield: (value2, yieldNodeId) => {
|
|
131941
|
+
generator.state = "suspended";
|
|
131942
|
+
return generatorYield(value2, yieldNodeId);
|
|
131943
|
+
},
|
|
131944
|
+
scope
|
|
131945
|
+
});
|
|
131946
|
+
if (result.kind === "error") {
|
|
131947
|
+
throw result.error;
|
|
131948
|
+
}
|
|
131949
|
+
if (result.kind === "throw") {
|
|
131950
|
+
throw result.value;
|
|
131951
|
+
}
|
|
131952
|
+
const value = result.hasValue ? result.value : void 0;
|
|
131953
|
+
return node.async ? awaitSandboxValue(value, context.signal, context.budget, createCoercionContext(context)) : value;
|
|
131954
|
+
};
|
|
131955
|
+
return node.async ? runAsyncPrefix(execute2) : execute2();
|
|
131956
|
+
});
|
|
131957
|
+
const generator = createSandboxGenerator(channel, { async: node.async });
|
|
131958
|
+
if (prototype !== void 0) setSandboxPrototype(generator, prototype, context.budget);
|
|
131959
|
+
const origin = registerGeneratorOrigin(generator, node, scope, closureContext);
|
|
131960
|
+
return generator;
|
|
131961
|
+
} finally {
|
|
131962
|
+
releasePrototype?.();
|
|
131963
|
+
}
|
|
131816
131964
|
}
|
|
131817
131965
|
});
|
|
131966
|
+
if (prototypes2 !== void 0) {
|
|
131967
|
+
const prototype = /* @__PURE__ */ Object.create(null);
|
|
131968
|
+
markDescriptorObject(prototype);
|
|
131969
|
+
setSandboxPrototype(prototype, prototypes2.instancePrototype);
|
|
131970
|
+
Object.defineProperty(materializeFunctionProperties(closure), "prototype", { value: prototype, writable: true });
|
|
131971
|
+
setSandboxPrototype(closure, prototypes2.functionPrototype);
|
|
131972
|
+
}
|
|
131818
131973
|
registerClosureOrigin(closure, node, context);
|
|
131819
131974
|
return closure;
|
|
131820
131975
|
}
|
|
@@ -131971,6 +132126,8 @@ var init_async = __esm({
|
|
|
131971
132126
|
init_var_hoist();
|
|
131972
132127
|
init_interpreter();
|
|
131973
132128
|
init_object_model();
|
|
132129
|
+
init_generator_prototypes();
|
|
132130
|
+
init_resources();
|
|
131974
132131
|
init_function_source();
|
|
131975
132132
|
init_closure_origin();
|
|
131976
132133
|
init_bindings();
|
|
@@ -134660,14 +134817,14 @@ function createObjectArrayGlobals(options) {
|
|
|
134660
134817
|
call: ([value]) => {
|
|
134661
134818
|
if (isGuestHostObject(value))
|
|
134662
134819
|
throw new TypeError("Live host objects cannot be made non-extensible.");
|
|
134663
|
-
Object.preventExtensions(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
134820
|
+
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);
|
|
134664
134821
|
return value;
|
|
134665
134822
|
},
|
|
134666
134823
|
name: "preventExtensions"
|
|
134667
134824
|
}),
|
|
134668
134825
|
isExtensible: createSandboxClosure({
|
|
134669
134826
|
sandbox: true,
|
|
134670
|
-
call: ([value]) => Object.isExtensible(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
134827
|
+
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),
|
|
134671
134828
|
name: "isExtensible"
|
|
134672
134829
|
}),
|
|
134673
134830
|
seal: createSandboxClosure({
|
|
@@ -134675,14 +134832,14 @@ function createObjectArrayGlobals(options) {
|
|
|
134675
134832
|
call: ([value]) => {
|
|
134676
134833
|
if (isGuestHostObject(value))
|
|
134677
134834
|
throw new TypeError("Live host objects cannot be sealed.");
|
|
134678
|
-
Object.seal(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
134835
|
+
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);
|
|
134679
134836
|
return value;
|
|
134680
134837
|
},
|
|
134681
134838
|
name: "seal"
|
|
134682
134839
|
}),
|
|
134683
134840
|
isSealed: createSandboxClosure({
|
|
134684
134841
|
sandbox: true,
|
|
134685
|
-
call: ([value]) => Object.isSealed(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
134842
|
+
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),
|
|
134686
134843
|
name: "isSealed"
|
|
134687
134844
|
}),
|
|
134688
134845
|
freeze: createSandboxClosure({
|
|
@@ -134691,7 +134848,7 @@ function createObjectArrayGlobals(options) {
|
|
|
134691
134848
|
if (isGuestHostObject(value))
|
|
134692
134849
|
throw new TypeError("Live host objects cannot be frozen.");
|
|
134693
134850
|
if (typeof value === "object" && value !== null) {
|
|
134694
|
-
Object.freeze(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value);
|
|
134851
|
+
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);
|
|
134695
134852
|
}
|
|
134696
134853
|
return value;
|
|
134697
134854
|
},
|
|
@@ -134699,7 +134856,7 @@ function createObjectArrayGlobals(options) {
|
|
|
134699
134856
|
}),
|
|
134700
134857
|
isFrozen: createSandboxClosure({
|
|
134701
134858
|
sandbox: true,
|
|
134702
|
-
call: ([value]) => Object.isFrozen(isSandboxPromise(value) ? getPromiseProperties(value) : isGuestClosure(value) ? materializeFunctionProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : value),
|
|
134859
|
+
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),
|
|
134703
134860
|
name: "isFrozen"
|
|
134704
134861
|
}),
|
|
134705
134862
|
assign: createSandboxClosure({
|
|
@@ -134830,6 +134987,32 @@ function createArrayGlobal(budget) {
|
|
|
134830
134987
|
length: 0,
|
|
134831
134988
|
call: (_args, context) => context?.thisValue
|
|
134832
134989
|
}), writable: true, configurable: true });
|
|
134990
|
+
const iteratorTagGetter = createSandboxClosure({
|
|
134991
|
+
guest: true,
|
|
134992
|
+
sandbox: true,
|
|
134993
|
+
name: "get [Symbol.toStringTag]",
|
|
134994
|
+
length: 0,
|
|
134995
|
+
call: () => "Iterator"
|
|
134996
|
+
});
|
|
134997
|
+
const iteratorTagSetter = createSandboxClosure({
|
|
134998
|
+
guest: true,
|
|
134999
|
+
sandbox: true,
|
|
135000
|
+
name: "set [Symbol.toStringTag]",
|
|
135001
|
+
length: 1,
|
|
135002
|
+
call: ([value], context) => {
|
|
135003
|
+
const receiver = context?.thisValue;
|
|
135004
|
+
if (receiver === iterablePrototype || receiver === null || typeof receiver !== "object")
|
|
135005
|
+
throw new TypeError("Iterator tag setter requires a distinct object receiver.");
|
|
135006
|
+
defineOwnDataProperty(objectProperties(receiver, true), Symbol.toStringTag, value);
|
|
135007
|
+
createDataCheckpoint(budget, context)(receiver, 0, true);
|
|
135008
|
+
return void 0;
|
|
135009
|
+
}
|
|
135010
|
+
});
|
|
135011
|
+
Object.defineProperty(iterablePrototype, Symbol.toStringTag, {
|
|
135012
|
+
get: accessorAdapter(iteratorTagGetter, "get"),
|
|
135013
|
+
set: accessorAdapter(iteratorTagSetter, "set"),
|
|
135014
|
+
configurable: true
|
|
135015
|
+
});
|
|
134833
135016
|
setSandboxPrototype(iterablePrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
134834
135017
|
setSandboxPrototype(iteratorPrototype, iterablePrototype);
|
|
134835
135018
|
Object.defineProperties(iteratorPrototype, {
|
|
@@ -134843,6 +135026,9 @@ function createArrayGlobal(budget) {
|
|
|
134843
135026
|
[Symbol.toStringTag]: { value: "Array Iterator", configurable: true }
|
|
134844
135027
|
});
|
|
134845
135028
|
registerBuiltinIdentities(budget, { "%ArrayIteratorPrototype%": iteratorPrototype, "%IteratorPrototype%": iterablePrototype });
|
|
135029
|
+
registerIntrinsicFunction(budget, iterablePrototype[Symbol.iterator]);
|
|
135030
|
+
registerIntrinsicFunction(budget, iteratorTagGetter);
|
|
135031
|
+
registerIntrinsicFunction(budget, iteratorTagSetter);
|
|
134846
135032
|
registerIntrinsicObject(budget, iterablePrototype);
|
|
134847
135033
|
registerIntrinsicObject(budget, iteratorPrototype);
|
|
134848
135034
|
for (const method of ["keys", "values", "entries"]) {
|
|
@@ -135042,6 +135228,7 @@ function reflectionProperties(value) {
|
|
|
135042
135228
|
return objectProperties(value);
|
|
135043
135229
|
}
|
|
135044
135230
|
function objectProperties(value, mutable = false) {
|
|
135231
|
+
if (isSandboxGenerator(value)) return getGeneratorProperties(value);
|
|
135045
135232
|
if (isSandboxPromise(value)) return getPromiseProperties(value);
|
|
135046
135233
|
if (isSandboxMap(value) || isSandboxSet(value)) return getCollectionProperties(value);
|
|
135047
135234
|
if (isSandboxRegex(value)) return getRegexProperties(value);
|
|
@@ -135360,6 +135547,7 @@ var init_object_array = __esm({
|
|
|
135360
135547
|
"packages/safe-js/src/interp/globals/object-array.ts"() {
|
|
135361
135548
|
"use strict";
|
|
135362
135549
|
init_budget2();
|
|
135550
|
+
init_generator_properties();
|
|
135363
135551
|
init_accessors();
|
|
135364
135552
|
init_builtin_call();
|
|
135365
135553
|
init_data_checkpoint();
|
|
@@ -135622,6 +135810,47 @@ var init_function_string = __esm({
|
|
|
135622
135810
|
}
|
|
135623
135811
|
});
|
|
135624
135812
|
|
|
135813
|
+
// packages/safe-js/src/interp/bound-function-state.ts
|
|
135814
|
+
var boundFunctionStates;
|
|
135815
|
+
var init_bound_function_state = __esm({
|
|
135816
|
+
"packages/safe-js/src/interp/bound-function-state.ts"() {
|
|
135817
|
+
"use strict";
|
|
135818
|
+
boundFunctionStates = /* @__PURE__ */ new WeakMap();
|
|
135819
|
+
}
|
|
135820
|
+
});
|
|
135821
|
+
|
|
135822
|
+
// packages/safe-js/src/interp/bound-function.ts
|
|
135823
|
+
function createBoundFunction(state, name, length, callClosure) {
|
|
135824
|
+
const bound = createSandboxClosure({
|
|
135825
|
+
guest: true,
|
|
135826
|
+
sandbox: true,
|
|
135827
|
+
name,
|
|
135828
|
+
length,
|
|
135829
|
+
boundTarget: state.target,
|
|
135830
|
+
retainedValues: () => [state.target, state.thisValue, ...state.args, bound.name],
|
|
135831
|
+
call: (args, context) => callClosure(state.target, [...state.args, ...args], context?.stack ?? [], state.thisValue),
|
|
135832
|
+
...state.target.construct === void 0 ? {} : {
|
|
135833
|
+
construct: (args, context) => callClosure(
|
|
135834
|
+
state.target,
|
|
135835
|
+
[...state.args, ...args],
|
|
135836
|
+
context?.stack ?? [],
|
|
135837
|
+
void 0,
|
|
135838
|
+
true,
|
|
135839
|
+
context?.newTarget === bound ? state.target : context?.newTarget
|
|
135840
|
+
)
|
|
135841
|
+
}
|
|
135842
|
+
});
|
|
135843
|
+
boundFunctionStates.set(bound, state);
|
|
135844
|
+
return bound;
|
|
135845
|
+
}
|
|
135846
|
+
var init_bound_function = __esm({
|
|
135847
|
+
"packages/safe-js/src/interp/bound-function.ts"() {
|
|
135848
|
+
"use strict";
|
|
135849
|
+
init_values();
|
|
135850
|
+
init_bound_function_state();
|
|
135851
|
+
}
|
|
135852
|
+
});
|
|
135853
|
+
|
|
135625
135854
|
// packages/safe-js/src/interp/methods/function.ts
|
|
135626
135855
|
function getFunctionMember(target, property, options) {
|
|
135627
135856
|
let current = target;
|
|
@@ -135638,7 +135867,7 @@ function getFunctionMember(target, property, options) {
|
|
|
135638
135867
|
} else if (Object.hasOwn(current, String(property))) {
|
|
135639
135868
|
return current[String(property)];
|
|
135640
135869
|
}
|
|
135641
|
-
if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current)) break;
|
|
135870
|
+
if (isSandboxClosure(current) && !hasExplicitSandboxPrototype(current) && getSandboxPrototype(current, options.budget) === null) break;
|
|
135642
135871
|
current = getSandboxPrototype(current, options.budget);
|
|
135643
135872
|
if (current !== null) {
|
|
135644
135873
|
options.budget?.visitNode();
|
|
@@ -135672,28 +135901,11 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
|
|
|
135672
135901
|
const thisValue = args[0];
|
|
135673
135902
|
if (methodName === "bind") {
|
|
135674
135903
|
const boundArgs = args.slice(1);
|
|
135904
|
+
const explicitPrototype = hasExplicitSandboxPrototype(target);
|
|
135905
|
+
const prototype = getSandboxPrototype(target, options.budget);
|
|
135675
135906
|
const bind2 = (length, name) => {
|
|
135676
|
-
const bound =
|
|
135677
|
-
|
|
135678
|
-
sandbox: true,
|
|
135679
|
-
name: `bound ${name}`,
|
|
135680
|
-
length,
|
|
135681
|
-
boundTarget: target,
|
|
135682
|
-
retainedValues: () => [target, thisValue, ...boundArgs, bound.name],
|
|
135683
|
-
call: (callArgs, context2) => options.callClosure(target, [...boundArgs, ...callArgs], context2?.stack ?? [], thisValue),
|
|
135684
|
-
...target.construct === void 0 ? {} : {
|
|
135685
|
-
construct: (callArgs, context2) => options.callClosure(
|
|
135686
|
-
target,
|
|
135687
|
-
[...boundArgs, ...callArgs],
|
|
135688
|
-
context2?.stack ?? [],
|
|
135689
|
-
void 0,
|
|
135690
|
-
true,
|
|
135691
|
-
context2?.newTarget === bound ? target : context2?.newTarget
|
|
135692
|
-
)
|
|
135693
|
-
}
|
|
135694
|
-
});
|
|
135695
|
-
if (hasExplicitSandboxPrototype(target))
|
|
135696
|
-
setSandboxPrototype(bound, getSandboxPrototype(target, options.budget), options.budget);
|
|
135907
|
+
const bound = createBoundFunction({ target, thisValue, args: boundArgs }, `bound ${name}`, length, options.callClosure);
|
|
135908
|
+
if (explicitPrototype) setSandboxPrototype(bound, prototype, options.budget);
|
|
135697
135909
|
return bound;
|
|
135698
135910
|
};
|
|
135699
135911
|
if (context?.getProperty === void 0)
|
|
@@ -135702,15 +135914,20 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
|
|
|
135702
135914
|
target.name ?? ""
|
|
135703
135915
|
);
|
|
135704
135916
|
return (async () => {
|
|
135705
|
-
const
|
|
135706
|
-
|
|
135707
|
-
|
|
135708
|
-
|
|
135709
|
-
|
|
135710
|
-
|
|
135711
|
-
|
|
135712
|
-
|
|
135713
|
-
|
|
135917
|
+
const release2 = options.budget !== void 0 && explicitPrototype && prototype !== null ? retainValues(options.budget, () => [prototype]) : void 0;
|
|
135918
|
+
try {
|
|
135919
|
+
const properties = target.properties;
|
|
135920
|
+
const defaultName = target.name;
|
|
135921
|
+
const hasLength = !isGuestClosure(target) || target.properties === void 0 || Object.hasOwn(target.properties, "length");
|
|
135922
|
+
const length = hasLength ? await context.getProperty(target, "length") : void 0;
|
|
135923
|
+
const name = !isGuestClosure(target) && !Object.hasOwn(properties ?? {}, "name") ? defaultName : await context.getProperty(target, "name");
|
|
135924
|
+
return bind2(
|
|
135925
|
+
typeof length === "number" && !Number.isNaN(length) ? Math.max(0, Math.trunc(length) - boundArgs.length) : 0,
|
|
135926
|
+
typeof name === "string" ? name : ""
|
|
135927
|
+
);
|
|
135928
|
+
} finally {
|
|
135929
|
+
release2?.();
|
|
135930
|
+
}
|
|
135714
135931
|
})();
|
|
135715
135932
|
}
|
|
135716
135933
|
if (methodName === "call") {
|
|
@@ -135720,25 +135937,37 @@ function callFunctionMethod(target, methodName, args, options, stack, context) {
|
|
|
135720
135937
|
if (applyArgs === null || applyArgs === void 0) {
|
|
135721
135938
|
return options.callClosure(target, [], stack, thisValue);
|
|
135722
135939
|
}
|
|
135723
|
-
if (
|
|
135724
|
-
throw new TypeError("Function#apply requires an
|
|
135940
|
+
if (typeof applyArgs !== "object") {
|
|
135941
|
+
throw new TypeError("Function#apply requires an object or nullish arguments value.");
|
|
135725
135942
|
}
|
|
135726
|
-
if (context?.getProperty === void 0)
|
|
135943
|
+
if (context?.getProperty === void 0 && Array.isArray(applyArgs))
|
|
135727
135944
|
return options.callClosure(target, applyArgs, stack, thisValue);
|
|
135728
135945
|
return (async () => {
|
|
135946
|
+
const budget = options.budget ?? new Budget();
|
|
135947
|
+
const invocationContext = {
|
|
135948
|
+
...context,
|
|
135949
|
+
stack,
|
|
135950
|
+
thisValue: context?.thisValue,
|
|
135951
|
+
invokeClosure: context?.invokeClosure ?? ((callee, values2, receiver) => Promise.resolve(options.callClosure(callee, values2, stack, receiver)))
|
|
135952
|
+
};
|
|
135953
|
+
const read = (value, key3) => {
|
|
135954
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key3);
|
|
135955
|
+
const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
|
|
135956
|
+
return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, value, invocationContext);
|
|
135957
|
+
};
|
|
135729
135958
|
const values = [];
|
|
135730
|
-
const
|
|
135731
|
-
options.budget?.allocateArrayLength(length);
|
|
135732
|
-
const retained = {};
|
|
135733
|
-
options.budget?.setRetainedValues(retained, () => values);
|
|
135959
|
+
const release2 = retainValues(budget, () => [applyArgs, ...values]);
|
|
135734
135960
|
try {
|
|
135961
|
+
const number = await sandboxNumber(await read(applyArgs, "length"), budget, invocationContext);
|
|
135962
|
+
const length = Number.isNaN(number) || number <= 0 ? 0 : Math.min(Math.trunc(number), Number.MAX_SAFE_INTEGER);
|
|
135963
|
+
budget.allocateArrayLength(length);
|
|
135735
135964
|
for (let index = 0; index < length; index++) {
|
|
135736
|
-
|
|
135737
|
-
values.push(await
|
|
135965
|
+
budget.visitNode();
|
|
135966
|
+
values.push(await read(applyArgs, String(index)));
|
|
135738
135967
|
}
|
|
135739
135968
|
return await options.callClosure(target, values, stack, thisValue);
|
|
135740
135969
|
} finally {
|
|
135741
|
-
|
|
135970
|
+
release2();
|
|
135742
135971
|
}
|
|
135743
135972
|
})();
|
|
135744
135973
|
}
|
|
@@ -135749,8 +135978,12 @@ var init_function = __esm({
|
|
|
135749
135978
|
init_values();
|
|
135750
135979
|
init_object_model();
|
|
135751
135980
|
init_graph_depth();
|
|
135981
|
+
init_budget2();
|
|
135752
135982
|
init_function_string();
|
|
135753
135983
|
init_resources();
|
|
135984
|
+
init_bound_function();
|
|
135985
|
+
init_string_coercion();
|
|
135986
|
+
init_accessors();
|
|
135754
135987
|
functionMethodNames = /* @__PURE__ */ new Set(["apply", "bind", "call", "toString"]);
|
|
135755
135988
|
}
|
|
135756
135989
|
});
|
|
@@ -135923,16 +136156,19 @@ function getGeneratorMember(target, property, budget) {
|
|
|
135923
136156
|
return createSandboxClosure({
|
|
135924
136157
|
sandbox: true,
|
|
135925
136158
|
name: property,
|
|
135926
|
-
call: ([value], context) =>
|
|
135927
|
-
const iterator = generatorIterator(target, budget, context);
|
|
135928
|
-
const result = Promise.resolve(iterator[property](value)).then((result2) => allocateProducedSandboxValue(
|
|
135929
|
-
{ value: result2.value, done: result2.done === true },
|
|
135930
|
-
budget
|
|
135931
|
-
));
|
|
135932
|
-
return target.async ? createSandboxPromise(result) : result;
|
|
135933
|
-
}
|
|
136159
|
+
call: ([value], context) => callGeneratorMethod(target, property, value, budget, context, target.async === true)
|
|
135934
136160
|
});
|
|
135935
136161
|
}
|
|
136162
|
+
function callGeneratorMethod(target, method, value, budget, context, async) {
|
|
136163
|
+
const result = (async () => {
|
|
136164
|
+
if (!isSandboxGenerator(target) || target.async === true !== async)
|
|
136165
|
+
throw new TypeError(`${async ? "AsyncGenerator" : "Generator"}.${method} requires a matching generator receiver.`);
|
|
136166
|
+
const iterator = generatorIterator(target, budget, context);
|
|
136167
|
+
const result2 = await iterator[method](value);
|
|
136168
|
+
return allocateProducedSandboxValue({ value: result2.value, done: result2.done === true }, budget);
|
|
136169
|
+
})();
|
|
136170
|
+
return async ? createSandboxPromise(result) : result;
|
|
136171
|
+
}
|
|
135936
136172
|
var generatorMethodNames;
|
|
135937
136173
|
var init_generator2 = __esm({
|
|
135938
136174
|
"packages/safe-js/src/interp/methods/generator.ts"() {
|
|
@@ -135997,120 +136233,37 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
|
|
|
135997
136233
|
try {
|
|
135998
136234
|
for (let entry = cursor2.next(); !entry.done; entry = cursor2.next()) {
|
|
135999
136235
|
const value = entry.value;
|
|
136000
|
-
await options.callClosure(callback, [value, value, target], stack, args[1]);
|
|
136001
|
-
}
|
|
136002
|
-
} finally {
|
|
136003
|
-
cursor2.leave();
|
|
136004
|
-
}
|
|
136005
|
-
return void 0;
|
|
136006
|
-
}
|
|
136007
|
-
case "keys":
|
|
136008
|
-
case "values":
|
|
136009
|
-
case "entries":
|
|
136010
|
-
return createSandboxCollectionIterator(target, methodName);
|
|
136011
|
-
}
|
|
136012
|
-
}
|
|
136013
|
-
var setMethodNames;
|
|
136014
|
-
var init_set = __esm({
|
|
136015
|
-
"packages/safe-js/src/interp/methods/set.ts"() {
|
|
136016
|
-
"use strict";
|
|
136017
|
-
init_values();
|
|
136018
|
-
init_running_state();
|
|
136019
|
-
init_collection_callback();
|
|
136020
|
-
init_collection_iterator();
|
|
136021
|
-
setMethodNames = /* @__PURE__ */ new Set([
|
|
136022
|
-
"add",
|
|
136023
|
-
"has",
|
|
136024
|
-
"delete",
|
|
136025
|
-
"clear",
|
|
136026
|
-
"forEach",
|
|
136027
|
-
"keys",
|
|
136028
|
-
"values",
|
|
136029
|
-
"entries"
|
|
136030
|
-
]);
|
|
136031
|
-
}
|
|
136032
|
-
});
|
|
136033
|
-
|
|
136034
|
-
// packages/safe-js/src/interp/globals/error.ts
|
|
136035
|
-
function createErrorGlobals(options) {
|
|
136036
|
-
return Object.fromEntries(
|
|
136037
|
-
errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
|
|
136038
|
-
);
|
|
136039
|
-
}
|
|
136040
|
-
function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
136041
|
-
if (!isSandboxClosure(constructor)) {
|
|
136042
|
-
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
136043
|
-
}
|
|
136044
|
-
const name = errorConstructorNames.get(constructor);
|
|
136045
|
-
if (name === void 0) {
|
|
136046
|
-
return false;
|
|
136047
|
-
}
|
|
136048
|
-
return isSandboxErrorConstructorInstance(value, name);
|
|
136049
|
-
}
|
|
136050
|
-
function createErrorConstructor(name, budget) {
|
|
136051
|
-
const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
|
|
136052
|
-
const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
|
|
136053
|
-
errorConstructorNames.set(closure, name);
|
|
136054
|
-
return closure;
|
|
136055
|
-
}
|
|
136056
|
-
function createSubsetError(name, args, stackFrames, budget) {
|
|
136057
|
-
const message2 = name === "AggregateError" ? args[1] : args[0];
|
|
136058
|
-
const options = name === "AggregateError" ? args[2] : args[1];
|
|
136059
|
-
const error3 = createSubsetErrorValue(name, message2, stackFrames, budget);
|
|
136060
|
-
if (name === "AggregateError") {
|
|
136061
|
-
const errors2 = Array.isArray(args[0]) ? [...args[0]] : [];
|
|
136062
|
-
budget.allocateArrayLength(errors2.length);
|
|
136063
|
-
error3.errors = errors2;
|
|
136064
|
-
}
|
|
136065
|
-
if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
|
|
136066
|
-
error3.cause = options.cause;
|
|
136236
|
+
await options.callClosure(callback, [value, value, target], stack, args[1]);
|
|
136237
|
+
}
|
|
136238
|
+
} finally {
|
|
136239
|
+
cursor2.leave();
|
|
136240
|
+
}
|
|
136241
|
+
return void 0;
|
|
136242
|
+
}
|
|
136243
|
+
case "keys":
|
|
136244
|
+
case "values":
|
|
136245
|
+
case "entries":
|
|
136246
|
+
return createSandboxCollectionIterator(target, methodName);
|
|
136067
136247
|
}
|
|
136068
|
-
return error3;
|
|
136069
136248
|
}
|
|
136070
|
-
|
|
136071
|
-
|
|
136072
|
-
|
|
136073
|
-
var errorConstructorNames, errorNames;
|
|
136074
|
-
var init_error = __esm({
|
|
136075
|
-
"packages/safe-js/src/interp/globals/error.ts"() {
|
|
136249
|
+
var setMethodNames;
|
|
136250
|
+
var init_set = __esm({
|
|
136251
|
+
"packages/safe-js/src/interp/methods/set.ts"() {
|
|
136076
136252
|
"use strict";
|
|
136077
|
-
init_exceptions();
|
|
136078
136253
|
init_values();
|
|
136079
|
-
|
|
136080
|
-
|
|
136081
|
-
"Error",
|
|
136082
|
-
"TypeError",
|
|
136083
|
-
"RangeError",
|
|
136084
|
-
"ReferenceError",
|
|
136085
|
-
"SyntaxError",
|
|
136086
|
-
"URIError",
|
|
136087
|
-
"EvalError",
|
|
136088
|
-
"AggregateError"
|
|
136089
|
-
];
|
|
136090
|
-
}
|
|
136091
|
-
});
|
|
136092
|
-
|
|
136093
|
-
// packages/safe-js/src/interp/methods/collection-iterator.ts
|
|
136094
|
-
function getCollectionIteratorMember(target, property, budget) {
|
|
136095
|
-
if (Object.hasOwn(target, property)) return target[property];
|
|
136096
|
-
if (property !== "next") return void 0;
|
|
136097
|
-
const { collectionKind } = collectionIteratorState(target);
|
|
136098
|
-
return createSandboxClosure({
|
|
136099
|
-
sandbox: true,
|
|
136100
|
-
name: "next",
|
|
136101
|
-
call: (_args, context) => {
|
|
136102
|
-
const receiver = context?.thisValue;
|
|
136103
|
-
if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
|
|
136104
|
-
throw new TypeError("Iterator next requires a matching collection iterator receiver.");
|
|
136105
|
-
return nextCollectionIterator(receiver, budget);
|
|
136106
|
-
}
|
|
136107
|
-
});
|
|
136108
|
-
}
|
|
136109
|
-
var init_collection_iterator2 = __esm({
|
|
136110
|
-
"packages/safe-js/src/interp/methods/collection-iterator.ts"() {
|
|
136111
|
-
"use strict";
|
|
136254
|
+
init_running_state();
|
|
136255
|
+
init_collection_callback();
|
|
136112
136256
|
init_collection_iterator();
|
|
136113
|
-
|
|
136257
|
+
setMethodNames = /* @__PURE__ */ new Set([
|
|
136258
|
+
"add",
|
|
136259
|
+
"has",
|
|
136260
|
+
"delete",
|
|
136261
|
+
"clear",
|
|
136262
|
+
"forEach",
|
|
136263
|
+
"keys",
|
|
136264
|
+
"values",
|
|
136265
|
+
"entries"
|
|
136266
|
+
]);
|
|
136114
136267
|
}
|
|
136115
136268
|
});
|
|
136116
136269
|
|
|
@@ -136247,6 +136400,147 @@ var init_float32array2 = __esm({
|
|
|
136247
136400
|
}
|
|
136248
136401
|
});
|
|
136249
136402
|
|
|
136403
|
+
// packages/safe-js/src/interp/globals/error.ts
|
|
136404
|
+
function createErrorGlobals(options) {
|
|
136405
|
+
return Object.fromEntries(
|
|
136406
|
+
errorNames.map((name) => [name, createErrorConstructor(name, options.budget)])
|
|
136407
|
+
);
|
|
136408
|
+
}
|
|
136409
|
+
function isSandboxErrorConstructorInstance2(value, constructor) {
|
|
136410
|
+
if (!isSandboxClosure(constructor)) {
|
|
136411
|
+
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
136412
|
+
}
|
|
136413
|
+
const name = errorConstructorNames.get(constructor);
|
|
136414
|
+
if (name === void 0) {
|
|
136415
|
+
return false;
|
|
136416
|
+
}
|
|
136417
|
+
return isSandboxErrorConstructorInstance(value, name);
|
|
136418
|
+
}
|
|
136419
|
+
function createErrorConstructor(name, budget) {
|
|
136420
|
+
const call = (args, context) => createSubsetError(name, args, context?.stack ?? [], budget);
|
|
136421
|
+
const closure = createSandboxClosure({ sandbox: true, call, construct: call, name });
|
|
136422
|
+
errorConstructorNames.set(closure, name);
|
|
136423
|
+
return closure;
|
|
136424
|
+
}
|
|
136425
|
+
function createSubsetError(name, args, stackFrames, budget) {
|
|
136426
|
+
const message2 = name === "AggregateError" ? args[1] : args[0];
|
|
136427
|
+
const options = name === "AggregateError" ? args[2] : args[1];
|
|
136428
|
+
const error3 = createSubsetErrorValue(name, message2, stackFrames, budget);
|
|
136429
|
+
if (name === "AggregateError") {
|
|
136430
|
+
const errors2 = Array.isArray(args[0]) ? [...args[0]] : [];
|
|
136431
|
+
budget.allocateArrayLength(errors2.length);
|
|
136432
|
+
error3.errors = errors2;
|
|
136433
|
+
}
|
|
136434
|
+
if (isObjectLike(options) && Object.prototype.hasOwnProperty.call(options, "cause")) {
|
|
136435
|
+
error3.cause = options.cause;
|
|
136436
|
+
}
|
|
136437
|
+
return error3;
|
|
136438
|
+
}
|
|
136439
|
+
function isObjectLike(value) {
|
|
136440
|
+
return typeof value === "object" && value !== null;
|
|
136441
|
+
}
|
|
136442
|
+
var errorConstructorNames, errorNames;
|
|
136443
|
+
var init_error = __esm({
|
|
136444
|
+
"packages/safe-js/src/interp/globals/error.ts"() {
|
|
136445
|
+
"use strict";
|
|
136446
|
+
init_exceptions();
|
|
136447
|
+
init_values();
|
|
136448
|
+
errorConstructorNames = /* @__PURE__ */ new WeakMap();
|
|
136449
|
+
errorNames = [
|
|
136450
|
+
"Error",
|
|
136451
|
+
"TypeError",
|
|
136452
|
+
"RangeError",
|
|
136453
|
+
"ReferenceError",
|
|
136454
|
+
"SyntaxError",
|
|
136455
|
+
"URIError",
|
|
136456
|
+
"EvalError",
|
|
136457
|
+
"AggregateError"
|
|
136458
|
+
];
|
|
136459
|
+
}
|
|
136460
|
+
});
|
|
136461
|
+
|
|
136462
|
+
// packages/safe-js/src/interp/instanceof.ts
|
|
136463
|
+
async function evaluateInstanceof(value, constructor, budget, context) {
|
|
136464
|
+
if (constructor === null || typeof constructor !== "object")
|
|
136465
|
+
throw new TypeError("Right-hand side of 'instanceof' must be an object.");
|
|
136466
|
+
const method = await readInstanceProperty(constructor, Symbol.hasInstance, budget, context);
|
|
136467
|
+
if (method !== void 0 && method !== null) {
|
|
136468
|
+
if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
|
|
136469
|
+
return Boolean(await invokeBuiltinClosure(method, [value], budget, context, constructor));
|
|
136470
|
+
}
|
|
136471
|
+
if (!isSandboxClosure(constructor))
|
|
136472
|
+
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
136473
|
+
return ordinaryHasInstance(value, constructor, budget, context);
|
|
136474
|
+
}
|
|
136475
|
+
async function ordinaryHasInstance(value, constructor, budget, context) {
|
|
136476
|
+
if (!isSandboxClosure(constructor)) return false;
|
|
136477
|
+
if (constructor.boundTarget !== void 0) {
|
|
136478
|
+
budget.visitNode();
|
|
136479
|
+
return evaluateInstanceof(value, constructor.boundTarget, budget, context);
|
|
136480
|
+
}
|
|
136481
|
+
if (isFloat32ArrayConstructor(constructor)) return isFloat32Array(value);
|
|
136482
|
+
if (isSandboxErrorConstructorInstance2(value, constructor)) return true;
|
|
136483
|
+
if (!isGuestClosure(constructor) || typeof value !== "object" || value === null) return false;
|
|
136484
|
+
const prototype = await readInstanceProperty(constructor, "prototype", budget, context);
|
|
136485
|
+
if (typeof prototype !== "object" || prototype === null)
|
|
136486
|
+
throw new TypeError("Function has a non-object prototype in instanceof check.");
|
|
136487
|
+
let depth = 0;
|
|
136488
|
+
for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
|
|
136489
|
+
budget.visitNode();
|
|
136490
|
+
assertSandboxDataDepth(depth++);
|
|
136491
|
+
if (current === prototype) return true;
|
|
136492
|
+
}
|
|
136493
|
+
return false;
|
|
136494
|
+
}
|
|
136495
|
+
async function readInstanceProperty(value, key3, budget, context) {
|
|
136496
|
+
if (context?.getProperty !== void 0) return context.getProperty(value, key3);
|
|
136497
|
+
const descriptor = getSandboxPropertyDescriptor(value, key3, budget);
|
|
136498
|
+
if (descriptor === void 0) return void 0;
|
|
136499
|
+
return readPropertyDescriptor(descriptor, value, {
|
|
136500
|
+
...context,
|
|
136501
|
+
stack: context?.stack ?? [],
|
|
136502
|
+
thisValue: value,
|
|
136503
|
+
invokeClosure: context?.invokeClosure ?? ((closure, args, receiver) => invokeBuiltinClosure(closure, args, budget, context, receiver))
|
|
136504
|
+
});
|
|
136505
|
+
}
|
|
136506
|
+
var init_instanceof = __esm({
|
|
136507
|
+
"packages/safe-js/src/interp/instanceof.ts"() {
|
|
136508
|
+
"use strict";
|
|
136509
|
+
init_graph_depth();
|
|
136510
|
+
init_accessors();
|
|
136511
|
+
init_builtin_call();
|
|
136512
|
+
init_float32();
|
|
136513
|
+
init_float32array2();
|
|
136514
|
+
init_error();
|
|
136515
|
+
init_object_model();
|
|
136516
|
+
init_values();
|
|
136517
|
+
}
|
|
136518
|
+
});
|
|
136519
|
+
|
|
136520
|
+
// packages/safe-js/src/interp/methods/collection-iterator.ts
|
|
136521
|
+
function getCollectionIteratorMember(target, property, budget) {
|
|
136522
|
+
if (Object.hasOwn(target, property)) return target[property];
|
|
136523
|
+
if (property !== "next") return void 0;
|
|
136524
|
+
const { collectionKind } = collectionIteratorState(target);
|
|
136525
|
+
return createSandboxClosure({
|
|
136526
|
+
sandbox: true,
|
|
136527
|
+
name: "next",
|
|
136528
|
+
call: (_args, context) => {
|
|
136529
|
+
const receiver = context?.thisValue;
|
|
136530
|
+
if (!isSandboxCollectionIterator(receiver) || collectionIteratorState(receiver).collectionKind !== collectionKind)
|
|
136531
|
+
throw new TypeError("Iterator next requires a matching collection iterator receiver.");
|
|
136532
|
+
return nextCollectionIterator(receiver, budget);
|
|
136533
|
+
}
|
|
136534
|
+
});
|
|
136535
|
+
}
|
|
136536
|
+
var init_collection_iterator2 = __esm({
|
|
136537
|
+
"packages/safe-js/src/interp/methods/collection-iterator.ts"() {
|
|
136538
|
+
"use strict";
|
|
136539
|
+
init_collection_iterator();
|
|
136540
|
+
init_values();
|
|
136541
|
+
}
|
|
136542
|
+
});
|
|
136543
|
+
|
|
136250
136544
|
// packages/safe-js/src/interp/scope.ts
|
|
136251
136545
|
function defineSnapshotBinding(target, name, value) {
|
|
136252
136546
|
Object.defineProperty(target, name, {
|
|
@@ -137911,7 +138205,7 @@ function forInKeys(object, budget) {
|
|
|
137911
138205
|
for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
137912
138206
|
if (depth > 0) budget.visitNode();
|
|
137913
138207
|
assertSandboxDataDepth(depth++);
|
|
137914
|
-
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;
|
|
138208
|
+
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;
|
|
137915
138209
|
for (const key3 of Object.getOwnPropertyNames(properties)) {
|
|
137916
138210
|
if (seen.has(key3)) continue;
|
|
137917
138211
|
seen.add(key3);
|
|
@@ -137927,7 +138221,7 @@ function hasForInProperty(object, key3, budget) {
|
|
|
137927
138221
|
for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
137928
138222
|
if (depth > 0) budget.visitNode();
|
|
137929
138223
|
assertSandboxDataDepth(depth++);
|
|
137930
|
-
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;
|
|
138224
|
+
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;
|
|
137931
138225
|
if (Object.hasOwn(properties, key3)) return true;
|
|
137932
138226
|
}
|
|
137933
138227
|
return false;
|
|
@@ -138483,7 +138777,7 @@ function getPropertyValue(target, property, context, receiver = target) {
|
|
|
138483
138777
|
if (isSandboxSet(target)) return getSandboxPrototype(target, context.budget) === null ? getSetMember(target, property, createSetMethodOptions(context)) : void 0;
|
|
138484
138778
|
if (isSandboxCollectionIterator(target))
|
|
138485
138779
|
return getCollectionIteratorMember(target, property, context.budget);
|
|
138486
|
-
if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
|
|
138780
|
+
if (isSandboxGenerator(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getGeneratorMember(target, property, context.budget);
|
|
138487
138781
|
if (isSandboxClosure(target)) return getClosureMemberValue(target, property, context);
|
|
138488
138782
|
if (isSandboxPromise(target)) return hasExplicitSandboxPrototype(target) ? void 0 : getPromiseMember(property, context.budget);
|
|
138489
138783
|
if (isSandboxRegex(target)) return hasExplicitSandboxPrototype(target) || getSandboxPrototype(target, context.budget) !== null ? void 0 : getRegexMember(target, property, context.budget, createCoercionContext(context));
|
|
@@ -138799,7 +139093,7 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
138799
139093
|
);
|
|
138800
139094
|
}
|
|
138801
139095
|
if (isSandboxGenerator(member.object)) {
|
|
138802
|
-
const memberValue =
|
|
139096
|
+
const memberValue = await getPropertyValue(member.object, member.property, context);
|
|
138803
139097
|
if (memberValue === void 0) {
|
|
138804
139098
|
throw new TypeError(`Generator#${String(member.property)} is not a supported method.`);
|
|
138805
139099
|
}
|
|
@@ -139051,42 +139345,11 @@ function applyBinaryOperator(node, left, right, context) {
|
|
|
139051
139345
|
case ">>>":
|
|
139052
139346
|
return toNumber(left) >>> toNumber(right);
|
|
139053
139347
|
case "instanceof":
|
|
139054
|
-
return evaluateInstanceof(left, right, context);
|
|
139348
|
+
return evaluateInstanceof(left, right, context.budget, createCoercionContext(context));
|
|
139055
139349
|
case "in":
|
|
139056
139350
|
return hasSandboxProperty(right, left, context);
|
|
139057
139351
|
}
|
|
139058
139352
|
}
|
|
139059
|
-
async function evaluateInstanceof(left, right, context) {
|
|
139060
|
-
while (true) {
|
|
139061
|
-
if (right === null || typeof right !== "object" && typeof right !== "function")
|
|
139062
|
-
throw new TypeError("Right-hand side of 'instanceof' must be an object.");
|
|
139063
|
-
const method = await getPropertyValue(right, Symbol.hasInstance, context);
|
|
139064
|
-
if (method !== void 0 && method !== null) {
|
|
139065
|
-
if (!isSandboxClosure(method)) throw new TypeError("Symbol.hasInstance must be callable.");
|
|
139066
|
-
return Boolean(await invokeSandboxClosure(method, [left], context, context.callStack, void 0, right));
|
|
139067
|
-
}
|
|
139068
|
-
if (!isSandboxClosure(right))
|
|
139069
|
-
throw new TypeError("Right-hand side of 'instanceof' is not a function.");
|
|
139070
|
-
if (right.boundTarget === void 0) break;
|
|
139071
|
-
context.budget.visitNode();
|
|
139072
|
-
right = right.boundTarget;
|
|
139073
|
-
}
|
|
139074
|
-
if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
|
|
139075
|
-
if (isSandboxErrorConstructorInstance2(left, right)) return true;
|
|
139076
|
-
if (isGuestClosure(right)) {
|
|
139077
|
-
if (typeof left !== "object" || left === null) return false;
|
|
139078
|
-
const prototype = await getPropertyValue(right, "prototype", context);
|
|
139079
|
-
if (typeof prototype !== "object" || prototype === null)
|
|
139080
|
-
throw new TypeError("Function has a non-object prototype in instanceof check.");
|
|
139081
|
-
let depth = 0;
|
|
139082
|
-
for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
|
|
139083
|
-
context.budget.visitNode();
|
|
139084
|
-
assertSandboxDataDepth(depth++);
|
|
139085
|
-
if (current === prototype) return true;
|
|
139086
|
-
}
|
|
139087
|
-
}
|
|
139088
|
-
return false;
|
|
139089
|
-
}
|
|
139090
139353
|
function createCoercionContext(context) {
|
|
139091
139354
|
return {
|
|
139092
139355
|
stack: context.callStack,
|
|
@@ -139103,7 +139366,7 @@ function hasSandboxProperty(value, key3, context) {
|
|
|
139103
139366
|
while (typeof current === "object" && current !== null) {
|
|
139104
139367
|
if (isGuestHostObject(current)) return typeof key3 === "symbol" ? false : hasHostObjectMember(current, String(key3));
|
|
139105
139368
|
if (hasOwnSandboxProperty(current, key3, false)) return true;
|
|
139106
|
-
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))) {
|
|
139369
|
+
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))) {
|
|
139107
139370
|
return getPropertyValue(current, key3, context) !== void 0;
|
|
139108
139371
|
}
|
|
139109
139372
|
current = getSandboxPrototype(current, context.budget);
|
|
@@ -139349,6 +139612,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
|
|
|
139349
139612
|
}
|
|
139350
139613
|
if (isGuestClosure(target)) target = materializeFunctionProperties(target);
|
|
139351
139614
|
if (isSandboxPromise(target)) target = getPromiseProperties(target);
|
|
139615
|
+
if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
|
|
139352
139616
|
if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
|
|
139353
139617
|
if (isFloat32Array(target)) {
|
|
139354
139618
|
if (typeof property === "symbol") throw new TypeError("Typed array symbol properties are not yet supported.");
|
|
@@ -139382,7 +139646,7 @@ function setSandboxProperty(target, property, value, budget, checkInherited = tr
|
|
|
139382
139646
|
for (let prototype = getSandboxPrototype(prototypeOwner, budget); prototype !== null; prototype = getSandboxPrototype(prototype, budget)) {
|
|
139383
139647
|
budget.visitNode();
|
|
139384
139648
|
assertSandboxDataDepth(depth++);
|
|
139385
|
-
const properties = isSandboxClosure(prototype) ? prototype.properties : prototype;
|
|
139649
|
+
const properties = isSandboxGenerator(prototype) ? getGeneratorProperties(prototype) : isSandboxClosure(prototype) ? prototype.properties : prototype;
|
|
139386
139650
|
const inherited = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
|
|
139387
139651
|
if (inherited === void 0) continue;
|
|
139388
139652
|
if (inherited.writable !== true)
|
|
@@ -139401,7 +139665,7 @@ function setSuperProperty(base, receiver, key3, value, context) {
|
|
|
139401
139665
|
for (let current = base; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
139402
139666
|
budget.visitNode();
|
|
139403
139667
|
assertSandboxDataDepth(depth++);
|
|
139404
|
-
const properties = isSandboxClosure(current) ? current.properties : current;
|
|
139668
|
+
const properties = isSandboxGenerator(current) ? getGeneratorProperties(current) : isSandboxClosure(current) ? current.properties : current;
|
|
139405
139669
|
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key3);
|
|
139406
139670
|
if (descriptor === void 0) continue;
|
|
139407
139671
|
if (!("value" in descriptor))
|
|
@@ -139419,6 +139683,7 @@ function deleteSandboxProperty(target, property) {
|
|
|
139419
139683
|
if (isGuestClosure(target)) target = materializeFunctionProperties(target);
|
|
139420
139684
|
if (isSandboxRegex(target)) target = getRegexProperties(target);
|
|
139421
139685
|
if (isSandboxPromise(target)) target = getPromiseProperties(target);
|
|
139686
|
+
if (isSandboxGenerator(target)) target = getGeneratorProperties(target);
|
|
139422
139687
|
if (isSandboxMap(target) || isSandboxSet(target)) target = getCollectionProperties(target);
|
|
139423
139688
|
if (Array.isArray(target)) {
|
|
139424
139689
|
assertCollectionMutable(target);
|
|
@@ -139741,11 +140006,12 @@ var init_interpreter = __esm({
|
|
|
139741
140006
|
init_iteration();
|
|
139742
140007
|
init_running_state();
|
|
139743
140008
|
init_generator2();
|
|
140009
|
+
init_generator_properties();
|
|
139744
140010
|
init_regex();
|
|
139745
140011
|
init_patterns();
|
|
139746
140012
|
init_string();
|
|
139747
140013
|
init_set();
|
|
139748
|
-
|
|
140014
|
+
init_instanceof();
|
|
139749
140015
|
init_object2();
|
|
139750
140016
|
init_collection_iterator();
|
|
139751
140017
|
init_collection_iterator2();
|
|
@@ -140116,11 +140382,11 @@ async function objectToPrimitive(value, budget, context, joining, hint, ordinary
|
|
|
140116
140382
|
}
|
|
140117
140383
|
}
|
|
140118
140384
|
function conversionHook(value, name, budget, context) {
|
|
140119
|
-
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));
|
|
140385
|
+
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));
|
|
140120
140386
|
let current = value;
|
|
140121
140387
|
let depth = 0;
|
|
140122
140388
|
while (current !== null) {
|
|
140123
|
-
const properties = isSandboxPromise(current) ? getPromiseProperties(current) : isGuestClosure(current) ? getGuestFunctionProperties(current) : isSandboxRegex(current) ? getRegexProperties(current) : isSandboxMap(current) || isSandboxSet(current) ? getCollectionProperties(current) : current;
|
|
140389
|
+
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;
|
|
140124
140390
|
const descriptor = properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, name);
|
|
140125
140391
|
if (descriptor !== void 0) {
|
|
140126
140392
|
return readPropertyDescriptor(descriptor, value, context);
|
|
@@ -140183,6 +140449,7 @@ var init_string_coercion = __esm({
|
|
|
140183
140449
|
"packages/safe-js/src/interp/string-coercion.ts"() {
|
|
140184
140450
|
"use strict";
|
|
140185
140451
|
init_shape();
|
|
140452
|
+
init_generator_properties();
|
|
140186
140453
|
init_accessors();
|
|
140187
140454
|
init_date();
|
|
140188
140455
|
init_builtin_call();
|
|
@@ -140363,8 +140630,7 @@ function hasOwnSandboxProperty(value, key3, enumerable) {
|
|
|
140363
140630
|
properties = value.properties ?? /* @__PURE__ */ Object.create(null);
|
|
140364
140631
|
} else if (isSandboxMap(value) || isSandboxSet(value)) properties = getCollectionProperties(value);
|
|
140365
140632
|
else if (isSandboxPromise(value)) properties = getPromiseProperties(value);
|
|
140366
|
-
else if (isSandboxGenerator(value))
|
|
140367
|
-
return false;
|
|
140633
|
+
else if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
|
|
140368
140634
|
else if (isSandboxRegex(value)) properties = getRegexProperties(value);
|
|
140369
140635
|
else properties = Object(value);
|
|
140370
140636
|
const descriptor = Object.getOwnPropertyDescriptor(properties, key3);
|
|
@@ -140401,6 +140667,7 @@ var init_object2 = __esm({
|
|
|
140401
140667
|
"packages/safe-js/src/interp/globals/object.ts"() {
|
|
140402
140668
|
"use strict";
|
|
140403
140669
|
init_graph_depth();
|
|
140670
|
+
init_generator_properties();
|
|
140404
140671
|
init_accessors();
|
|
140405
140672
|
init_arguments();
|
|
140406
140673
|
init_date();
|
|
@@ -142206,6 +142473,7 @@ function ownEnumerableSandboxEntries(value, excludedKeys) {
|
|
|
142206
142473
|
if (isGuestClosure(value)) entries = Object.entries(value.properties ?? {});
|
|
142207
142474
|
else if (isSandboxRegex(value)) entries = Object.entries(getRegexProperties(value));
|
|
142208
142475
|
else if (isSandboxPromise(value)) entries = Object.entries(getPromiseProperties(value));
|
|
142476
|
+
else if (isSandboxGenerator(value)) entries = Object.entries(getGeneratorProperties(value));
|
|
142209
142477
|
else if (isSandboxMap(value) || isSandboxSet(value)) entries = Object.entries(getCollectionProperties(value));
|
|
142210
142478
|
else if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
142211
142479
|
else entries = Object.entries(Object(value));
|
|
@@ -142217,19 +142485,20 @@ function ownSandboxSymbolKeys(value) {
|
|
|
142217
142485
|
if (isSandboxClosure(value)) value = value.properties ?? {};
|
|
142218
142486
|
else if (isSandboxRegex(value)) value = getRegexProperties(value);
|
|
142219
142487
|
else if (isSandboxPromise(value)) value = getPromiseProperties(value);
|
|
142488
|
+
else if (isSandboxGenerator(value)) value = getGeneratorProperties(value);
|
|
142220
142489
|
else if (isSandboxMap(value) || isSandboxSet(value)) value = getCollectionProperties(value);
|
|
142221
|
-
else if (isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
142222
142490
|
return Object.getOwnPropertySymbols(Object(value)).filter((key3) => !internalSymbols.has(key3));
|
|
142223
142491
|
}
|
|
142224
142492
|
function ownEnumerableSandboxKeys(value, includeSymbols = false) {
|
|
142225
142493
|
if (includeSymbols) {
|
|
142226
|
-
const properties = isSandboxClosure(value) ? value.properties ?? {} : isSandboxPromise(value) ? getPromiseProperties(value) : isSandboxRegex(value) ? getRegexProperties(value) : isSandboxMap(value) || isSandboxSet(value) ? getCollectionProperties(value) : Object(value);
|
|
142494
|
+
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);
|
|
142227
142495
|
return [...ownEnumerableSandboxKeys(value), ...ownSandboxSymbolKeys(value).filter((key3) => Object.getOwnPropertyDescriptor(properties, key3)?.enumerable === true)];
|
|
142228
142496
|
}
|
|
142229
142497
|
if (isGuestHostObject(value)) return getHostObjectKeys(value);
|
|
142230
142498
|
if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
|
|
142231
142499
|
if (isGuestClosure(value)) return Object.keys(value.properties ?? {});
|
|
142232
142500
|
if (isSandboxPromise(value)) return Object.keys(getPromiseProperties(value));
|
|
142501
|
+
if (isSandboxGenerator(value)) return Object.keys(getGeneratorProperties(value));
|
|
142233
142502
|
if (isSandboxRegex(value)) return Object.keys(getRegexProperties(value));
|
|
142234
142503
|
if (isSandboxMap(value) || isSandboxSet(value)) return Object.keys(getCollectionProperties(value));
|
|
142235
142504
|
if (isSandboxClosure(value) || isSandboxGenerator(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxRegex(value)) return [];
|
|
@@ -142281,6 +142550,7 @@ function createSandboxGenerator(channel, metadata = void 0) {
|
|
|
142281
142550
|
enumerable: false,
|
|
142282
142551
|
value: true
|
|
142283
142552
|
});
|
|
142553
|
+
getGeneratorProperties(generator);
|
|
142284
142554
|
return generator;
|
|
142285
142555
|
}
|
|
142286
142556
|
function createSandboxMap(entries = []) {
|
|
@@ -142535,6 +142805,14 @@ function measureSandboxData(values, options = {}) {
|
|
|
142535
142805
|
return;
|
|
142536
142806
|
}
|
|
142537
142807
|
if (isSandboxGenerator(value)) {
|
|
142808
|
+
const descriptors3 = Object.getOwnPropertyDescriptors(getGeneratorProperties(value));
|
|
142809
|
+
for (const key3 of Reflect.ownKeys(descriptors3)) {
|
|
142810
|
+
const descriptor = descriptors3[key3];
|
|
142811
|
+
usage += typeof key3 === "string" ? key3.length + 1 : 1;
|
|
142812
|
+
if (typeof key3 === "symbol") visit(key3, depth + 1);
|
|
142813
|
+
if ("value" in descriptor) visit(descriptor.value, depth + 1);
|
|
142814
|
+
else for (const closure of retainedAccessorClosures(descriptor)) visit(closure, depth + 1);
|
|
142815
|
+
}
|
|
142538
142816
|
const snapshot2 = value.channel.snapshot();
|
|
142539
142817
|
usage += snapshot2.sent.length;
|
|
142540
142818
|
for (const completion of snapshot2.sent) visit(completion.value, depth + 1);
|
|
@@ -143299,6 +143577,7 @@ var init_values = __esm({
|
|
|
143299
143577
|
"use strict";
|
|
143300
143578
|
init_otel2();
|
|
143301
143579
|
init_internal_symbols();
|
|
143580
|
+
init_generator_properties();
|
|
143302
143581
|
init_regexp_properties();
|
|
143303
143582
|
init_collection_properties();
|
|
143304
143583
|
init_collection_properties();
|
|
@@ -143406,6 +143685,18 @@ function captureGuestHeapNode(value, encode) {
|
|
|
143406
143685
|
const state2 = captureObjectState(value, encode);
|
|
143407
143686
|
return { kind: "intrinsic", id: intrinsic, ...state2 === void 0 ? {} : { state: state2 } };
|
|
143408
143687
|
}
|
|
143688
|
+
const bound = boundFunctionStates.get(value);
|
|
143689
|
+
if (bound !== void 0 && isSandboxClosure(value)) {
|
|
143690
|
+
return {
|
|
143691
|
+
kind: "bound-function",
|
|
143692
|
+
target: encode(bound.target),
|
|
143693
|
+
thisValue: encode(bound.thisValue),
|
|
143694
|
+
args: bound.args.map(encode),
|
|
143695
|
+
length: encode(value.length),
|
|
143696
|
+
...value.name === void 0 ? {} : { name: value.name },
|
|
143697
|
+
state: captureObjectState(value, encode)
|
|
143698
|
+
};
|
|
143699
|
+
}
|
|
143409
143700
|
if (isSandboxMap(value)) return { kind: "map", entries: [...value.entries].map(([key3, entry]) => [encode(key3), encode(entry)]), ...serializeCollectionProperties(value, encode) };
|
|
143410
143701
|
if (isSandboxSet(value)) return { kind: "set", values: [...value.values].map(encode), ...serializeCollectionProperties(value, encode) };
|
|
143411
143702
|
if (isSandboxArrayIterator(value)) {
|
|
@@ -143456,6 +143747,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
143456
143747
|
state: value.state,
|
|
143457
143748
|
astNodeId: origin2.node.nodeId,
|
|
143458
143749
|
async: value.async === true,
|
|
143750
|
+
objectState: captureObjectState(value, encode),
|
|
143459
143751
|
scope: encode(origin2.scope),
|
|
143460
143752
|
closureScope: encode(origin2.closureScope),
|
|
143461
143753
|
...value.state !== "suspended" || origin2.suspendedScope === void 0 ? {} : { suspendedScope: encode(origin2.suspendedScope) },
|
|
@@ -143571,6 +143863,7 @@ function captureGuestHeapNode(value, encode) {
|
|
|
143571
143863
|
}
|
|
143572
143864
|
function captureObjectState(value, encode) {
|
|
143573
143865
|
let properties = value;
|
|
143866
|
+
if (isSandboxGenerator(value)) properties = getGeneratorProperties(value);
|
|
143574
143867
|
if (isSandboxClosure(value)) {
|
|
143575
143868
|
properties = value.properties;
|
|
143576
143869
|
if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
|
|
@@ -143585,6 +143878,8 @@ var init_guest_heap = __esm({
|
|
|
143585
143878
|
"packages/safe-js/src/snapshot/guest-heap.ts"() {
|
|
143586
143879
|
"use strict";
|
|
143587
143880
|
init_closure_origin();
|
|
143881
|
+
init_bound_function_state();
|
|
143882
|
+
init_generator_properties();
|
|
143588
143883
|
init_intrinsics();
|
|
143589
143884
|
init_object_model();
|
|
143590
143885
|
init_host_capabilities();
|
|
@@ -146799,6 +147094,120 @@ var init_uri = __esm({
|
|
|
146799
147094
|
}
|
|
146800
147095
|
});
|
|
146801
147096
|
|
|
147097
|
+
// packages/safe-js/src/interp/globals/function.ts
|
|
147098
|
+
function createFunctionPrototype(budget, installHasInstance = true) {
|
|
147099
|
+
const prototype = createSandboxClosure({ guest: true, sandbox: true, name: "", length: 0, call: () => void 0 });
|
|
147100
|
+
const properties = materializeFunctionProperties(prototype);
|
|
147101
|
+
Object.defineProperty(properties, "constructor", { value: void 0, writable: true, configurable: true });
|
|
147102
|
+
for (const [name, length] of [["call", 1], ["apply", 2], ["bind", 1], ["toString", 0]]) {
|
|
147103
|
+
Object.defineProperty(properties, name, {
|
|
147104
|
+
writable: true,
|
|
147105
|
+
configurable: true,
|
|
147106
|
+
value: createSandboxClosure({
|
|
147107
|
+
guest: true,
|
|
147108
|
+
sandbox: true,
|
|
147109
|
+
name,
|
|
147110
|
+
length,
|
|
147111
|
+
call: (args, context) => callFunctionMethod(context?.thisValue, name, args, {
|
|
147112
|
+
budget,
|
|
147113
|
+
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)
|
|
147114
|
+
}, context?.stack ?? [], context)
|
|
147115
|
+
})
|
|
147116
|
+
});
|
|
147117
|
+
}
|
|
147118
|
+
const hasInstance = installHasInstance ? createSandboxClosure({
|
|
147119
|
+
guest: true,
|
|
147120
|
+
sandbox: true,
|
|
147121
|
+
name: "[Symbol.hasInstance]",
|
|
147122
|
+
length: 1,
|
|
147123
|
+
call: ([value], context) => ordinaryHasInstance(value, context?.thisValue, budget, context)
|
|
147124
|
+
}) : void 0;
|
|
147125
|
+
if (hasInstance !== void 0) Object.defineProperty(properties, Symbol.hasInstance, { value: hasInstance });
|
|
147126
|
+
setSandboxPrototype(prototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
147127
|
+
installFunctionPrototype(budget, prototype);
|
|
147128
|
+
if (hasInstance !== void 0) registerIntrinsicFunction(budget, hasInstance);
|
|
147129
|
+
}
|
|
147130
|
+
var init_function2 = __esm({
|
|
147131
|
+
"packages/safe-js/src/interp/globals/function.ts"() {
|
|
147132
|
+
"use strict";
|
|
147133
|
+
init_builtin_call();
|
|
147134
|
+
init_function();
|
|
147135
|
+
init_object_model();
|
|
147136
|
+
init_values();
|
|
147137
|
+
init_instanceof();
|
|
147138
|
+
}
|
|
147139
|
+
});
|
|
147140
|
+
|
|
147141
|
+
// packages/safe-js/src/interp/globals/generator.ts
|
|
147142
|
+
function createGeneratorPrototypes(budget) {
|
|
147143
|
+
const asyncIteratorPrototype = /* @__PURE__ */ Object.create(null);
|
|
147144
|
+
const asyncIterator = createSandboxClosure({
|
|
147145
|
+
guest: true,
|
|
147146
|
+
sandbox: true,
|
|
147147
|
+
name: "[Symbol.asyncIterator]",
|
|
147148
|
+
length: 0,
|
|
147149
|
+
call: (_args, context) => context?.thisValue
|
|
147150
|
+
});
|
|
147151
|
+
Object.defineProperty(asyncIteratorPrototype, Symbol.asyncIterator, {
|
|
147152
|
+
value: asyncIterator,
|
|
147153
|
+
writable: true,
|
|
147154
|
+
configurable: true
|
|
147155
|
+
});
|
|
147156
|
+
setSandboxPrototype(asyncIteratorPrototype, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
|
|
147157
|
+
registerBuiltinIdentities(budget, { "%AsyncIteratorPrototype%": asyncIteratorPrototype });
|
|
147158
|
+
registerIntrinsicObject(budget, asyncIteratorPrototype);
|
|
147159
|
+
registerIntrinsicFunction(budget, asyncIterator);
|
|
147160
|
+
const state = /* @__PURE__ */ new Map();
|
|
147161
|
+
for (const async of [false, true]) {
|
|
147162
|
+
const tag = async ? "AsyncGenerator" : "Generator";
|
|
147163
|
+
const functionPrototype = /* @__PURE__ */ Object.create(null);
|
|
147164
|
+
const instancePrototype = /* @__PURE__ */ Object.create(null);
|
|
147165
|
+
setSandboxPrototype(functionPrototype, resolveIntrinsicIdentity(budget, JSON.stringify(["%FunctionPrototype%"])));
|
|
147166
|
+
setSandboxPrototype(instancePrototype, async ? asyncIteratorPrototype : resolveIntrinsicIdentity(budget, JSON.stringify(["%IteratorPrototype%"])));
|
|
147167
|
+
Object.defineProperties(functionPrototype, {
|
|
147168
|
+
prototype: { value: instancePrototype, configurable: true },
|
|
147169
|
+
// Do not expose native dynamic-source constructors through this graph.
|
|
147170
|
+
constructor: { value: void 0, configurable: true },
|
|
147171
|
+
[Symbol.toStringTag]: { value: `${tag}Function`, configurable: true }
|
|
147172
|
+
});
|
|
147173
|
+
Object.defineProperties(instancePrototype, {
|
|
147174
|
+
constructor: { value: functionPrototype, configurable: true },
|
|
147175
|
+
[Symbol.toStringTag]: { value: tag, configurable: true }
|
|
147176
|
+
});
|
|
147177
|
+
for (const method of ["next", "return", "throw"]) {
|
|
147178
|
+
Object.defineProperty(instancePrototype, method, {
|
|
147179
|
+
writable: true,
|
|
147180
|
+
configurable: true,
|
|
147181
|
+
value: createSandboxClosure({
|
|
147182
|
+
guest: true,
|
|
147183
|
+
sandbox: true,
|
|
147184
|
+
name: method,
|
|
147185
|
+
length: 1,
|
|
147186
|
+
call: ([value], context) => callGeneratorMethod(context?.thisValue, method, value, budget, context, async)
|
|
147187
|
+
})
|
|
147188
|
+
});
|
|
147189
|
+
}
|
|
147190
|
+
registerBuiltinIdentities(budget, {
|
|
147191
|
+
[`%${tag}Prototype%`]: instancePrototype,
|
|
147192
|
+
[`%${tag}FunctionPrototype%`]: functionPrototype
|
|
147193
|
+
});
|
|
147194
|
+
registerIntrinsicObject(budget, functionPrototype);
|
|
147195
|
+
registerIntrinsicObject(budget, instancePrototype);
|
|
147196
|
+
state.set(async, { functionPrototype, instancePrototype });
|
|
147197
|
+
}
|
|
147198
|
+
generatorPrototypes.set(budget, state);
|
|
147199
|
+
}
|
|
147200
|
+
var init_generator3 = __esm({
|
|
147201
|
+
"packages/safe-js/src/interp/globals/generator.ts"() {
|
|
147202
|
+
"use strict";
|
|
147203
|
+
init_generator_prototypes();
|
|
147204
|
+
init_intrinsics();
|
|
147205
|
+
init_generator2();
|
|
147206
|
+
init_object_model();
|
|
147207
|
+
init_values();
|
|
147208
|
+
}
|
|
147209
|
+
});
|
|
147210
|
+
|
|
146802
147211
|
// packages/safe-js/src/interp/globals/symbol.ts
|
|
146803
147212
|
function createSymbolGlobal(budget) {
|
|
146804
147213
|
let registry = registries.get(budget);
|
|
@@ -147051,6 +147460,8 @@ function createBuiltinBindings(options) {
|
|
|
147051
147460
|
...createPromiseGlobals(options),
|
|
147052
147461
|
...createRegexGlobals(options)
|
|
147053
147462
|
};
|
|
147463
|
+
createFunctionPrototype(options.budget, options.functionHasInstance);
|
|
147464
|
+
createGeneratorPrototypes(options.budget);
|
|
147054
147465
|
registerBuiltinIdentities(options.budget, bindings);
|
|
147055
147466
|
return bindings;
|
|
147056
147467
|
}
|
|
@@ -147066,6 +147477,8 @@ var init_globals = __esm({
|
|
|
147066
147477
|
init_misc();
|
|
147067
147478
|
init_uri();
|
|
147068
147479
|
init_object_array();
|
|
147480
|
+
init_function2();
|
|
147481
|
+
init_generator3();
|
|
147069
147482
|
init_promise();
|
|
147070
147483
|
init_date2();
|
|
147071
147484
|
init_symbol();
|
|
@@ -147119,7 +147532,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
147119
147532
|
createRawJson(node.text);
|
|
147120
147533
|
return true;
|
|
147121
147534
|
}
|
|
147122
|
-
if (!["intrinsic", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
147535
|
+
if (!["intrinsic", "bound-function", "guest-function", "guest-class", "guest-generator", "scope-frame", "guest-object", "guest-array", "array-iterator", "map", "set"].includes(String(node.kind))) return false;
|
|
147123
147536
|
const reference = (value, kinds) => {
|
|
147124
147537
|
const ref = record3(value);
|
|
147125
147538
|
fields(ref, ["kind", "id"]);
|
|
@@ -147130,7 +147543,7 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
147130
147543
|
};
|
|
147131
147544
|
const callable = (value) => {
|
|
147132
147545
|
if (absent(value)) return;
|
|
147133
|
-
const target = reference(value, ["intrinsic", "guest-function", "guest-class"]);
|
|
147546
|
+
const target = reference(value, ["intrinsic", "bound-function", "guest-function", "guest-class"]);
|
|
147134
147547
|
if (target.kind === "intrinsic" && intrinsicCatalogue().get(String(target.id)) !== true)
|
|
147135
147548
|
throw new TypeError("Guest accessor reference is not callable.");
|
|
147136
147549
|
};
|
|
@@ -147226,6 +147639,22 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
147226
147639
|
if (descriptor.kind !== "data" || descriptor.writable !== false || descriptor.enumerable !== false || descriptor.configurable !== false)
|
|
147227
147640
|
throw new TypeError("Invalid class prototype descriptor.");
|
|
147228
147641
|
reference(descriptor.value, ["object", "guest-object"]);
|
|
147642
|
+
} else if (node.kind === "bound-function") {
|
|
147643
|
+
fields(node, ["kind", "target", "thisValue", "args", "length", "state"], ["name"]);
|
|
147644
|
+
if (Object.hasOwn(node, "name") && typeof node.name !== "string") throw new TypeError("Invalid bound function name.");
|
|
147645
|
+
if (array(node.args).length > maxArrayLength) throw new TypeError("Bound arguments exceed allocation limit.");
|
|
147646
|
+
if (!absent(node.length) && !(typeof node.length === "number" && node.length >= 0) && !(record3(node.length).kind === "number" && record3(node.length).value === "Infinity"))
|
|
147647
|
+
throw new TypeError("Invalid bound function length.");
|
|
147648
|
+
const visited = /* @__PURE__ */ new Set([raw]);
|
|
147649
|
+
let current = node;
|
|
147650
|
+
while (current.kind === "bound-function") {
|
|
147651
|
+
assertSnapshotDataDepth(visited.size, "<bound-target>");
|
|
147652
|
+
callable(current.target);
|
|
147653
|
+
current = reference(current.target);
|
|
147654
|
+
if (visited.has(current)) throw new TypeError("Cyclic bound function target.");
|
|
147655
|
+
visited.add(current);
|
|
147656
|
+
}
|
|
147657
|
+
state(node.state);
|
|
147229
147658
|
} else if (node.kind === "guest-function") {
|
|
147230
147659
|
fields(node, ["kind", "astNodeId", "scope", "state"], ["name", "environment"]);
|
|
147231
147660
|
if (integer2(node.astNodeId) < 1) throw new TypeError("Invalid guest AST identity.");
|
|
@@ -147239,7 +147668,8 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
147239
147668
|
}
|
|
147240
147669
|
state(node.state);
|
|
147241
147670
|
} else if (node.kind === "guest-generator") {
|
|
147242
|
-
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates"]);
|
|
147671
|
+
fields(node, ["kind", "state", "astNodeId", "async", "scope", "closureScope", "sent"], ["suspendedScope", "yieldNodeId", "environment", "blockScopes", "finallyCompletions", "expressionStates", "objectState"]);
|
|
147672
|
+
if (Object.hasOwn(node, "objectState")) state(node.objectState);
|
|
147243
147673
|
if (!["start", "running", "suspended", "done"].includes(String(node.state)) || typeof node.async !== "boolean" || integer2(node.astNodeId) < 1)
|
|
147244
147674
|
throw new TypeError("Invalid generator state.");
|
|
147245
147675
|
reference(node.scope, ["scope-frame"]);
|
|
@@ -147460,6 +147890,7 @@ var init_guest_heap_validation = __esm({
|
|
|
147460
147890
|
init_intrinsics();
|
|
147461
147891
|
init_object_model();
|
|
147462
147892
|
init_values();
|
|
147893
|
+
init_graph_depth();
|
|
147463
147894
|
}
|
|
147464
147895
|
});
|
|
147465
147896
|
|