@poe-platform/safe-js 0.1.222 → 0.1.223
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/safe-js/chunks/{chunk-BWMXJOKV.js → chunk-JJKJAB53.js} +2 -2
- package/dist/safe-js/chunks/{chunk-M7KI5UI3.js → chunk-PEHO3DVD.js} +168 -73
- package/dist/safe-js/chunks/chunk-PEHO3DVD.js.map +7 -0
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-M7KI5UI3.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-BWMXJOKV.js.map → chunk-JJKJAB53.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-PEHO3DVD.js";
|
|
31
31
|
|
|
32
32
|
// packages/safe-js/src/migrate.ts
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
@@ -8249,4 +8249,4 @@ export {
|
|
|
8249
8249
|
parseMcpConfig,
|
|
8250
8250
|
makeMcpModule
|
|
8251
8251
|
};
|
|
8252
|
-
//# sourceMappingURL=chunk-
|
|
8252
|
+
//# sourceMappingURL=chunk-JJKJAB53.js.map
|
|
@@ -138,6 +138,47 @@ function findSourceOffset(source, line, column) {
|
|
|
138
138
|
return source.length;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
// packages/safe-js/src/interp/template-objects.ts
|
|
142
|
+
var realms = /* @__PURE__ */ new WeakMap();
|
|
143
|
+
var templateOrigins = /* @__PURE__ */ new WeakMap();
|
|
144
|
+
var templateRawArrays = /* @__PURE__ */ new WeakMap();
|
|
145
|
+
var templateCookedArrays = /* @__PURE__ */ new WeakMap();
|
|
146
|
+
function templateObject(node, budget) {
|
|
147
|
+
const cached = realms.get(budget)?.get(node);
|
|
148
|
+
if (cached !== void 0) return cached;
|
|
149
|
+
budget.allocateArrayLength(node.quasis.length);
|
|
150
|
+
const strings = node.quasis.map((quasi) => quasi.value.cooked === void 0 ? void 0 : budget.allocateString(quasi.value.cooked));
|
|
151
|
+
const raw = node.quasis.map((quasi) => budget.allocateString(quasi.value.raw));
|
|
152
|
+
Object.freeze(raw);
|
|
153
|
+
Object.defineProperty(strings, "raw", { value: raw });
|
|
154
|
+
Object.freeze(strings);
|
|
155
|
+
registerTemplateObject(node, strings, budget);
|
|
156
|
+
return strings;
|
|
157
|
+
}
|
|
158
|
+
function registerTemplateObject(node, value, budget) {
|
|
159
|
+
const raw = Object.getOwnPropertyDescriptor(value, "raw")?.value;
|
|
160
|
+
if (!Object.isFrozen(value) || !Array.isArray(raw) || !Object.isFrozen(raw) || value.length !== node.quasis.length || raw.length !== node.quasis.length || node.quasis.some((quasi, index) => Object.getOwnPropertyDescriptor(value, String(index))?.value !== quasi.value.cooked || Object.getOwnPropertyDescriptor(raw, String(index))?.value !== quasi.value.raw))
|
|
161
|
+
throw new TypeError("Invalid template object contents.");
|
|
162
|
+
let realm = realms.get(budget);
|
|
163
|
+
const existing = realm?.get(node);
|
|
164
|
+
if (existing !== void 0 && existing !== value) throw new TypeError("Conflicting template object identity.");
|
|
165
|
+
if (realm === void 0) {
|
|
166
|
+
realm = /* @__PURE__ */ new Map();
|
|
167
|
+
realms.set(budget, realm);
|
|
168
|
+
const retained = realm;
|
|
169
|
+
budget.setRetainedValues(realm, () => retained.values());
|
|
170
|
+
}
|
|
171
|
+
realm.set(node, value);
|
|
172
|
+
templateOrigins.set(value, node);
|
|
173
|
+
templateRawArrays.set(value, raw);
|
|
174
|
+
templateCookedArrays.set(raw, value);
|
|
175
|
+
}
|
|
176
|
+
function releaseTemplateObjects(budget) {
|
|
177
|
+
const realm = realms.get(budget);
|
|
178
|
+
if (realm !== void 0) budget.setRetainedValues(realm, void 0);
|
|
179
|
+
realms.delete(budget);
|
|
180
|
+
}
|
|
181
|
+
|
|
141
182
|
// packages/safe-js/src/interp/budget.ts
|
|
142
183
|
var REGEX_STEP_LIMIT = 2e3;
|
|
143
184
|
var REGEX_COMPILE_LIMITS = Object.freeze({
|
|
@@ -391,6 +432,7 @@ var Budget = class {
|
|
|
391
432
|
}
|
|
392
433
|
reset() {
|
|
393
434
|
if (this.compileUses !== 0) throw new SandboxError("reentry");
|
|
435
|
+
releaseTemplateObjects(this);
|
|
394
436
|
this.compileGeneration += 1;
|
|
395
437
|
this.defaultCompileOwner = void 0;
|
|
396
438
|
this.provisionalScopes = 0;
|
|
@@ -6860,9 +6902,9 @@ function exportDate(value) {
|
|
|
6860
6902
|
return new NativeDate(dateTime(value));
|
|
6861
6903
|
}
|
|
6862
6904
|
function dateDataProperties(value) {
|
|
6863
|
-
const
|
|
6864
|
-
return Reflect.ownKeys(
|
|
6865
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
6905
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(value);
|
|
6906
|
+
return Reflect.ownKeys(descriptors2).map((key) => {
|
|
6907
|
+
const descriptor = Object.getOwnPropertyDescriptor(descriptors2, key).value;
|
|
6866
6908
|
if (!("value" in descriptor)) throw new TypeError("Date accessor properties cannot be copied as data.");
|
|
6867
6909
|
return [key, descriptor];
|
|
6868
6910
|
});
|
|
@@ -7159,9 +7201,9 @@ function primitiveReceiver(value, kind) {
|
|
|
7159
7201
|
}
|
|
7160
7202
|
function boxedDataProperties(value, includeSymbols = false) {
|
|
7161
7203
|
const primitive = nativeBoxedValue(value);
|
|
7162
|
-
const
|
|
7163
|
-
const keys = includeSymbols ? Reflect.ownKeys(
|
|
7164
|
-
return keys.map((key) => [key, Object.getOwnPropertyDescriptor(
|
|
7204
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(value);
|
|
7205
|
+
const keys = includeSymbols ? Reflect.ownKeys(descriptors2) : Object.keys(descriptors2);
|
|
7206
|
+
return keys.map((key) => [key, Object.getOwnPropertyDescriptor(descriptors2, key).value]).filter(([key]) => {
|
|
7165
7207
|
if (typeof key === "symbol") return true;
|
|
7166
7208
|
if (typeof primitive !== "string") return true;
|
|
7167
7209
|
if (key === "length") return false;
|
|
@@ -7910,10 +7952,10 @@ function getGeneratorOrigin(value) {
|
|
|
7910
7952
|
|
|
7911
7953
|
// packages/safe-js/src/interp/intrinsics.ts
|
|
7912
7954
|
var identities = /* @__PURE__ */ new WeakMap();
|
|
7913
|
-
var
|
|
7955
|
+
var realms2 = /* @__PURE__ */ new WeakMap();
|
|
7914
7956
|
function registerBuiltinIdentities(budget, bindings) {
|
|
7915
|
-
let realm =
|
|
7916
|
-
if (realm === void 0)
|
|
7957
|
+
let realm = realms2.get(budget);
|
|
7958
|
+
if (realm === void 0) realms2.set(budget, realm = /* @__PURE__ */ new Map());
|
|
7917
7959
|
const pending = Object.entries(bindings).map(([name, value]) => [[name], value]);
|
|
7918
7960
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
7919
7961
|
for (let index = 0; index < pending.length; index++) {
|
|
@@ -7948,15 +7990,15 @@ function getIntrinsicIdentity(value) {
|
|
|
7948
7990
|
return identities.get(value);
|
|
7949
7991
|
}
|
|
7950
7992
|
function resolveIntrinsicIdentity(budget, id) {
|
|
7951
|
-
const value =
|
|
7993
|
+
const value = realms2.get(budget)?.get(id);
|
|
7952
7994
|
if (value === void 0) throw new TypeError(`Unknown intrinsic identity: ${id}`);
|
|
7953
7995
|
return value;
|
|
7954
7996
|
}
|
|
7955
7997
|
function listIntrinsicIdentities(budget) {
|
|
7956
|
-
return [...
|
|
7998
|
+
return [...realms2.get(budget)?.keys() ?? []];
|
|
7957
7999
|
}
|
|
7958
8000
|
function releaseIntrinsicIdentities(budget) {
|
|
7959
|
-
|
|
8001
|
+
realms2.delete(budget);
|
|
7960
8002
|
}
|
|
7961
8003
|
|
|
7962
8004
|
// packages/safe-js/src/interp/object-model.ts
|
|
@@ -8074,23 +8116,24 @@ function registerIntrinsicPrototype(budget, prototype, constructor) {
|
|
|
8074
8116
|
const unchanged = (before, after) => before !== void 0 && after !== void 0 && Object.is(before.value, after.value) && before.get === after.get && before.set === after.set && before.writable === after.writable && before.configurable === after.configurable && before.enumerable === after.enumerable;
|
|
8075
8117
|
intrinsicConstructors.set(
|
|
8076
8118
|
constructor,
|
|
8077
|
-
() => records.every(({ target, value, descriptors, prototype: parent, explicit, extensible }) => {
|
|
8119
|
+
() => records.every(({ target, value, descriptors: descriptors2, prototype: parent, explicit, extensible }) => {
|
|
8078
8120
|
const current = Object.getOwnPropertyDescriptors(value);
|
|
8079
|
-
return getSandboxPrototype(target) === parent && Object.isExtensible(value) === extensible && hasExplicitSandboxPrototype(target) === explicit && Reflect.ownKeys(current).length ===
|
|
8121
|
+
return getSandboxPrototype(target) === parent && Object.isExtensible(value) === extensible && hasExplicitSandboxPrototype(target) === explicit && Reflect.ownKeys(current).length === descriptors2.size && Reflect.ownKeys(value).every((key) => unchanged(descriptors2.get(key), Object.getOwnPropertyDescriptor(value, key)));
|
|
8080
8122
|
})
|
|
8081
8123
|
);
|
|
8082
8124
|
budget.setRetainedValues(
|
|
8083
8125
|
prototype,
|
|
8084
|
-
() => records.flatMap(({ target, value, descriptors, prototype: parent }) => [
|
|
8126
|
+
() => records.flatMap(({ target, value, descriptors: descriptors2, prototype: parent }) => [
|
|
8085
8127
|
...getSandboxPrototype(target) === parent ? [] : [getSandboxPrototype(target)],
|
|
8086
8128
|
...Reflect.ownKeys(value).flatMap((key) => {
|
|
8087
8129
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
8088
|
-
return unchanged(
|
|
8130
|
+
return unchanged(descriptors2.get(key), descriptor) ? [] : [key, descriptor.value, ...retainedAccessorClosures(descriptor)];
|
|
8089
8131
|
})
|
|
8090
8132
|
])
|
|
8091
8133
|
);
|
|
8092
8134
|
}
|
|
8093
8135
|
function releaseObjectPrototype(budget) {
|
|
8136
|
+
releaseTemplateObjects(budget);
|
|
8094
8137
|
releaseIntrinsicIdentities(budget);
|
|
8095
8138
|
for (const prototype of intrinsicPrototypeRoots.get(budget) ?? []) budget.setRetainedValues(prototype, void 0);
|
|
8096
8139
|
intrinsicPrototypeRoots.delete(budget);
|
|
@@ -8559,7 +8602,16 @@ function captureGuestHeapNode(value, encode) {
|
|
|
8559
8602
|
if (Array.isArray(value) && (!Object.isExtensible(value) || hasExplicitSandboxPrototype(value) || Reflect.ownKeys(value).some((key) => {
|
|
8560
8603
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
8561
8604
|
return key === "length" ? descriptor.writable !== true : !("value" in descriptor) || !descriptor.enumerable || !descriptor.configurable || !descriptor.writable;
|
|
8562
|
-
})))
|
|
8605
|
+
}))) {
|
|
8606
|
+
const templateNodeId = templateOrigins.get(value)?.nodeId;
|
|
8607
|
+
const templateOwner = templateCookedArrays.get(value);
|
|
8608
|
+
return {
|
|
8609
|
+
kind: "guest-array",
|
|
8610
|
+
state: captureObjectState(value, encode),
|
|
8611
|
+
...templateNodeId === void 0 ? {} : { templateNodeId },
|
|
8612
|
+
...templateOwner === void 0 ? {} : { templateOwner: encode(templateOwner) }
|
|
8613
|
+
};
|
|
8614
|
+
}
|
|
8563
8615
|
if (isLiveCapability(value) || isSandboxClosure(value) || isSandboxBox(value) || isSandboxDate(value) || isSandboxRegex(value) || isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value) || isSandboxArguments(value) || isSandboxCollectionIterator(value) || isSandboxRegExpIterator(value)) return void 0;
|
|
8564
8616
|
const prototype = Object.getPrototypeOf(value);
|
|
8565
8617
|
if ((prototype === null || prototype === Object.prototype) && hasGuestObjectState(value))
|
|
@@ -13517,11 +13569,11 @@ function createObjectArrayGlobals(options) {
|
|
|
13517
13569
|
getOwnPropertyDescriptors: createSandboxClosure({
|
|
13518
13570
|
sandbox: true,
|
|
13519
13571
|
call: ([value]) => {
|
|
13520
|
-
const
|
|
13572
|
+
const descriptors2 = /* @__PURE__ */ Object.create(null);
|
|
13521
13573
|
const properties = objectProperties(value);
|
|
13522
13574
|
for (const key of [...Object.getOwnPropertyNames(properties), ...ownSandboxSymbolKeys(value)])
|
|
13523
|
-
defineOwnDataProperty(
|
|
13524
|
-
return allocateProducedSandboxValue(
|
|
13575
|
+
defineOwnDataProperty(descriptors2, key, exposePropertyDescriptor(Object.getOwnPropertyDescriptor(properties, key)));
|
|
13576
|
+
return allocateProducedSandboxValue(descriptors2, options.budget);
|
|
13525
13577
|
},
|
|
13526
13578
|
name: "getOwnPropertyDescriptors"
|
|
13527
13579
|
}),
|
|
@@ -13552,8 +13604,8 @@ function createObjectArrayGlobals(options) {
|
|
|
13552
13604
|
}),
|
|
13553
13605
|
defineProperties: createSandboxClosure({
|
|
13554
13606
|
sandbox: true,
|
|
13555
|
-
call: async ([value,
|
|
13556
|
-
await definePropertiesFromObject(value,
|
|
13607
|
+
call: async ([value, descriptors2], context) => {
|
|
13608
|
+
await definePropertiesFromObject(value, descriptors2, options.budget, context);
|
|
13557
13609
|
return value;
|
|
13558
13610
|
},
|
|
13559
13611
|
name: "defineProperties"
|
|
@@ -13582,12 +13634,12 @@ function createObjectArrayGlobals(options) {
|
|
|
13582
13634
|
}),
|
|
13583
13635
|
create: createSandboxClosure({
|
|
13584
13636
|
sandbox: true,
|
|
13585
|
-
call: async ([prototype,
|
|
13637
|
+
call: async ([prototype, descriptors2], context) => {
|
|
13586
13638
|
if (prototype !== null) objectProperties(prototype);
|
|
13587
13639
|
const value = /* @__PURE__ */ Object.create(null);
|
|
13588
13640
|
setSandboxPrototype(value, prototype, options.budget);
|
|
13589
|
-
if (
|
|
13590
|
-
await definePropertiesFromObject(value,
|
|
13641
|
+
if (descriptors2 !== void 0) {
|
|
13642
|
+
await definePropertiesFromObject(value, descriptors2, options.budget, context);
|
|
13591
13643
|
}
|
|
13592
13644
|
return allocateProducedSandboxValue(value, options.budget);
|
|
13593
13645
|
},
|
|
@@ -13936,19 +13988,19 @@ async function propertyDescriptor(input, budget, context) {
|
|
|
13936
13988
|
release();
|
|
13937
13989
|
}
|
|
13938
13990
|
}
|
|
13939
|
-
async function definePropertiesFromObject(target,
|
|
13991
|
+
async function definePropertiesFromObject(target, descriptors2, budget, context) {
|
|
13940
13992
|
objectProperties(target, true);
|
|
13941
13993
|
const properties = [];
|
|
13942
13994
|
const release = retainValues(budget, () => [
|
|
13943
13995
|
target,
|
|
13944
|
-
|
|
13996
|
+
descriptors2,
|
|
13945
13997
|
properties,
|
|
13946
13998
|
...properties.flatMap(([, descriptor]) => retainedAccessorClosures(descriptor))
|
|
13947
13999
|
]);
|
|
13948
14000
|
try {
|
|
13949
|
-
for (const key of ownEnumerableSandboxKeys(
|
|
13950
|
-
if (!hasOwnSandboxProperty(
|
|
13951
|
-
const descriptor = await (context?.getProperty !== void 0 ? context.getProperty(
|
|
14001
|
+
for (const key of ownEnumerableSandboxKeys(descriptors2, true)) {
|
|
14002
|
+
if (!hasOwnSandboxProperty(descriptors2, key, true)) continue;
|
|
14003
|
+
const descriptor = await (context?.getProperty !== void 0 ? context.getProperty(descriptors2, key) : getSandboxDataProperty(descriptors2, key, budget));
|
|
13952
14004
|
properties.push([key, await propertyDescriptor(descriptor, budget, context)]);
|
|
13953
14005
|
}
|
|
13954
14006
|
for (const [key, descriptor] of properties) defineDataProperty(target, key, descriptor, budget);
|
|
@@ -16179,7 +16231,6 @@ function relativeIndex(value, length, fallback) {
|
|
|
16179
16231
|
}
|
|
16180
16232
|
|
|
16181
16233
|
// packages/safe-js/src/interp/interpreter.ts
|
|
16182
|
-
var taggedTemplateRawArrays = /* @__PURE__ */ new WeakMap();
|
|
16183
16234
|
var dispatchTable = {
|
|
16184
16235
|
ArrayExpression: evaluateArrayExpression,
|
|
16185
16236
|
AssignmentExpression: evaluateAssignmentExpression,
|
|
@@ -16654,7 +16705,7 @@ async function evaluateTaggedTemplateExpression(node, context) {
|
|
|
16654
16705
|
hasValue: true,
|
|
16655
16706
|
value: await invokeSandboxClosure(
|
|
16656
16707
|
tag2,
|
|
16657
|
-
[
|
|
16708
|
+
[templateObject(node.quasi, context.budget), ...values.value],
|
|
16658
16709
|
context,
|
|
16659
16710
|
[...context.callStack, formatStackFrame(node, tag2.name)],
|
|
16660
16711
|
node.span,
|
|
@@ -16679,26 +16730,6 @@ async function evaluateTaggedTemplateExpression(node, context) {
|
|
|
16679
16730
|
const tag = await evaluateNode(node.tag, context);
|
|
16680
16731
|
return tag.kind === "normal" ? invokeTag(tag.value, void 0) : tag;
|
|
16681
16732
|
}
|
|
16682
|
-
function createTaggedTemplateStrings(node, context) {
|
|
16683
|
-
context.budget.allocateArrayLength(node.quasis.length);
|
|
16684
|
-
const strings = node.quasis.map(
|
|
16685
|
-
(quasi) => quasi.value.cooked === void 0 ? void 0 : context.budget.allocateString(quasi.value.cooked)
|
|
16686
|
-
);
|
|
16687
|
-
context.budget.allocateArrayLength(node.quasis.length);
|
|
16688
|
-
const raw = node.quasis.map(
|
|
16689
|
-
(quasi) => context.budget.allocateString(quasi.value.raw)
|
|
16690
|
-
);
|
|
16691
|
-
Object.defineProperty(strings, "raw", {
|
|
16692
|
-
configurable: false,
|
|
16693
|
-
enumerable: false,
|
|
16694
|
-
value: raw,
|
|
16695
|
-
writable: false
|
|
16696
|
-
});
|
|
16697
|
-
taggedTemplateRawArrays.set(strings, raw);
|
|
16698
|
-
Object.freeze(raw);
|
|
16699
|
-
Object.freeze(strings);
|
|
16700
|
-
return strings;
|
|
16701
|
-
}
|
|
16702
16733
|
async function evaluateArrowFunction(node, context) {
|
|
16703
16734
|
return evaluateArrowFunctionExpression(node, context, evaluateNode);
|
|
16704
16735
|
}
|
|
@@ -18898,8 +18929,8 @@ function getMemberValue(target, property, context) {
|
|
|
18898
18929
|
}
|
|
18899
18930
|
function getArrayMemberValue(target, property, context) {
|
|
18900
18931
|
if (hasExplicitSandboxPrototype(target)) return void 0;
|
|
18901
|
-
if (property === "raw" &&
|
|
18902
|
-
return
|
|
18932
|
+
if (property === "raw" && templateRawArrays.has(target)) {
|
|
18933
|
+
return templateRawArrays.get(target);
|
|
18903
18934
|
}
|
|
18904
18935
|
return getArrayMember(target, property, createArrayMethodOptions(context));
|
|
18905
18936
|
}
|
|
@@ -22350,7 +22381,10 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
|
|
|
22350
22381
|
if (typeof node.id !== "string" || !intrinsicCatalogue().has(node.id)) throw new TypeError("Unknown intrinsic identity.");
|
|
22351
22382
|
if (Object.hasOwn(node, "state")) state(node.state);
|
|
22352
22383
|
} else if (node.kind === "guest-object" || node.kind === "guest-array") {
|
|
22353
|
-
fields(node, ["kind", "state"]);
|
|
22384
|
+
fields(node, ["kind", "state"], node.kind === "guest-array" ? ["templateNodeId", "templateOwner"] : []);
|
|
22385
|
+
if (Object.hasOwn(node, "templateOwner")) reference(node.templateOwner, ["guest-array"]);
|
|
22386
|
+
if (Object.hasOwn(node, "templateNodeId") && integer(node.templateNodeId) < 1)
|
|
22387
|
+
throw new TypeError("Invalid template source identity.");
|
|
22354
22388
|
state(node.state);
|
|
22355
22389
|
if (node.kind === "guest-array") {
|
|
22356
22390
|
const properties = array(record2(record2(node.state).properties).properties).map((entry) => array(entry));
|
|
@@ -22602,6 +22636,61 @@ function validateGuestFunctionAst(record3, origin) {
|
|
|
22602
22636
|
}
|
|
22603
22637
|
}
|
|
22604
22638
|
|
|
22639
|
+
// packages/safe-js/src/snapshot/template-validation.ts
|
|
22640
|
+
function validateTemplateObjects(heap, nodes) {
|
|
22641
|
+
const sites = /* @__PURE__ */ new Map();
|
|
22642
|
+
for (const node of nodes) {
|
|
22643
|
+
if (node.type === "TaggedTemplateExpression" && node.quasi.nodeId !== void 0)
|
|
22644
|
+
sites.set(node.quasi.nodeId, node.quasi);
|
|
22645
|
+
}
|
|
22646
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22647
|
+
const rawOwners = /* @__PURE__ */ new Map();
|
|
22648
|
+
for (const raw of Object.values(heap)) {
|
|
22649
|
+
const entry = raw;
|
|
22650
|
+
if (entry.kind !== "guest-array" || entry.templateNodeId === void 0) continue;
|
|
22651
|
+
const node = sites.get(entry.templateNodeId);
|
|
22652
|
+
if (node === void 0 || seen.has(entry.templateNodeId)) throw new TypeError("Invalid or duplicate template source identity.");
|
|
22653
|
+
seen.add(entry.templateNodeId);
|
|
22654
|
+
const cooked = descriptors(entry.state);
|
|
22655
|
+
const rawReference = cooked.get("raw")?.value;
|
|
22656
|
+
const rawArray = rawReference?.kind === "ref" ? heap[String(rawReference.id)] : void 0;
|
|
22657
|
+
if (rawArray?.kind !== "guest-array") throw new TypeError("Invalid template raw array.");
|
|
22658
|
+
if (rawOwners.has(rawArray) && rawOwners.get(rawArray) !== raw) throw new TypeError("Conflicting template raw identity.");
|
|
22659
|
+
rawOwners.set(rawArray, raw);
|
|
22660
|
+
checkArray(cooked, node.quasis.map((quasi) => quasi.value.cooked), true);
|
|
22661
|
+
checkArray(descriptors(rawArray.state), node.quasis.map((quasi) => quasi.value.raw), false);
|
|
22662
|
+
}
|
|
22663
|
+
for (const [raw, owner] of rawOwners) {
|
|
22664
|
+
const reference = raw.templateOwner;
|
|
22665
|
+
if (reference === void 0 || heap[String(reference.id)] !== owner)
|
|
22666
|
+
throw new TypeError("Missing or invalid template owner identity.");
|
|
22667
|
+
}
|
|
22668
|
+
for (const raw of Object.values(heap)) {
|
|
22669
|
+
const entry = raw;
|
|
22670
|
+
if (entry.templateOwner !== void 0 && rawOwners.get(raw) !== heap[String(entry.templateOwner.id)])
|
|
22671
|
+
throw new TypeError("Invalid template owner identity.");
|
|
22672
|
+
}
|
|
22673
|
+
}
|
|
22674
|
+
function descriptors(raw) {
|
|
22675
|
+
const state = raw;
|
|
22676
|
+
if (Object.hasOwn(state, "prototype") || state.properties.extensible !== false)
|
|
22677
|
+
throw new TypeError("Invalid template object state.");
|
|
22678
|
+
return new Map(state.properties.properties);
|
|
22679
|
+
}
|
|
22680
|
+
function checkArray(properties, values, cooked) {
|
|
22681
|
+
if (properties.size !== values.length + (cooked ? 2 : 1)) throw new TypeError("Invalid template property count.");
|
|
22682
|
+
const expected = new Map(values.map((value, index) => [String(index), value]));
|
|
22683
|
+
expected.set("length", values.length);
|
|
22684
|
+
if (cooked) expected.set("raw", properties.get("raw")?.value);
|
|
22685
|
+
for (const [key, value] of expected) {
|
|
22686
|
+
const descriptor = properties.get(key);
|
|
22687
|
+
const actual = descriptor?.value;
|
|
22688
|
+
const equal = value === void 0 ? actual !== null && typeof actual === "object" && actual.kind === "undefined" : actual === value;
|
|
22689
|
+
if (descriptor?.kind !== "data" || descriptor.configurable !== false || descriptor.writable !== false || descriptor.enumerable !== (key !== "length" && key !== "raw") || !equal)
|
|
22690
|
+
throw new TypeError("Invalid template property descriptor or contents.");
|
|
22691
|
+
}
|
|
22692
|
+
}
|
|
22693
|
+
|
|
22605
22694
|
// packages/safe-js/src/snapshot/validation.ts
|
|
22606
22695
|
var DEFAULT_MAX_DEPTH = MAX_DATA_DEPTH;
|
|
22607
22696
|
var DEFAULT_MAX_ENTRIES = 1e5;
|
|
@@ -23873,8 +23962,8 @@ function measureSandboxData(values, options = {}) {
|
|
|
23873
23962
|
seen.add(value);
|
|
23874
23963
|
usage += 1;
|
|
23875
23964
|
if (!isGuestHostObject(value)) {
|
|
23876
|
-
const
|
|
23877
|
-
for (const [key, descriptor] of
|
|
23965
|
+
const descriptors3 = Object.getOwnPropertySymbols(value).filter((key) => !internalSymbols.has(key)).map((key) => [key, Object.getOwnPropertyDescriptor(value, key)]);
|
|
23966
|
+
for (const [key, descriptor] of descriptors3) {
|
|
23878
23967
|
usage += 1;
|
|
23879
23968
|
visit(key, depth + 1);
|
|
23880
23969
|
if ("value" in descriptor) visit(descriptor.value, depth + 1);
|
|
@@ -24010,16 +24099,16 @@ function measureSandboxData(values, options = {}) {
|
|
|
24010
24099
|
}
|
|
24011
24100
|
return;
|
|
24012
24101
|
}
|
|
24013
|
-
const
|
|
24014
|
-
const keys = Object.keys(
|
|
24102
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(value);
|
|
24103
|
+
const keys = Object.keys(descriptors2);
|
|
24015
24104
|
const includeNonEnumerable = isSandboxDate(value) || hasManagedDescriptors(value);
|
|
24016
24105
|
let entryCount = 0;
|
|
24017
24106
|
for (const key of keys) {
|
|
24018
|
-
if (
|
|
24107
|
+
if (descriptors2[key].enumerable || includeNonEnumerable) entryCount += 1;
|
|
24019
24108
|
}
|
|
24020
24109
|
usage += entryCount;
|
|
24021
24110
|
for (const key of keys) {
|
|
24022
|
-
const descriptor =
|
|
24111
|
+
const descriptor = descriptors2[key];
|
|
24023
24112
|
if (!descriptor.enumerable && !includeNonEnumerable) continue;
|
|
24024
24113
|
usage += key.length;
|
|
24025
24114
|
if ("value" in descriptor) visit(descriptor.value, depth + 1);
|
|
@@ -24627,11 +24716,11 @@ function defineOwnDataProperty(target, key, value) {
|
|
|
24627
24716
|
});
|
|
24628
24717
|
}
|
|
24629
24718
|
function getEnumerableObjectEntries(value, path) {
|
|
24630
|
-
const
|
|
24719
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(value);
|
|
24631
24720
|
const entries = [];
|
|
24632
|
-
for (const key of Reflect.ownKeys(
|
|
24721
|
+
for (const key of Reflect.ownKeys(descriptors2)) {
|
|
24633
24722
|
if (typeof key === "symbol" && internalSymbols.has(key)) continue;
|
|
24634
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
24723
|
+
const descriptor = Object.getOwnPropertyDescriptor(descriptors2, key).value;
|
|
24635
24724
|
if (!descriptor.enumerable) {
|
|
24636
24725
|
continue;
|
|
24637
24726
|
}
|
|
@@ -24646,11 +24735,11 @@ function getEnumerableObjectEntries(value, path) {
|
|
|
24646
24735
|
return entries;
|
|
24647
24736
|
}
|
|
24648
24737
|
function getEnumerableArrayEntries(value, path) {
|
|
24649
|
-
const
|
|
24738
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(value);
|
|
24650
24739
|
const entries = [];
|
|
24651
|
-
for (const key of Reflect.ownKeys(
|
|
24740
|
+
for (const key of Reflect.ownKeys(descriptors2)) {
|
|
24652
24741
|
if (typeof key === "symbol" && internalSymbols.has(key)) continue;
|
|
24653
|
-
const descriptor = Object.getOwnPropertyDescriptor(
|
|
24742
|
+
const descriptor = Object.getOwnPropertyDescriptor(descriptors2, key).value;
|
|
24654
24743
|
if (key === "length" || !descriptor.enumerable) {
|
|
24655
24744
|
continue;
|
|
24656
24745
|
}
|
|
@@ -25312,9 +25401,9 @@ function normalize(value, seen) {
|
|
|
25312
25401
|
return normalized2;
|
|
25313
25402
|
}
|
|
25314
25403
|
const normalized = /* @__PURE__ */ Object.create(null);
|
|
25315
|
-
const
|
|
25316
|
-
for (const key of Object.keys(
|
|
25317
|
-
const descriptor =
|
|
25404
|
+
const descriptors2 = Object.getOwnPropertyDescriptors(value);
|
|
25405
|
+
for (const key of Object.keys(descriptors2).sort()) {
|
|
25406
|
+
const descriptor = descriptors2[key];
|
|
25318
25407
|
if (!descriptor.enumerable) continue;
|
|
25319
25408
|
if (!("value" in descriptor)) {
|
|
25320
25409
|
throw new TypeError("Host call arguments cannot contain accessor properties.");
|
|
@@ -25556,7 +25645,7 @@ function restore(snapshot, options, owner) {
|
|
|
25556
25645
|
throw new SnapshotMismatchError(snapshot.sourceHash, currentSourceHash);
|
|
25557
25646
|
}
|
|
25558
25647
|
if (snapshot.heap !== void 0 && typeof snapshot.heap === "object" && snapshot.heap !== null) {
|
|
25559
|
-
const closures = Object.entries(snapshot.heap).filter(([, value]) => value !== null && typeof value === "object" && ["guest-function", "guest-generator"].includes(String(value.kind)));
|
|
25648
|
+
const closures = Object.entries(snapshot.heap).filter(([, value]) => value !== null && typeof value === "object" && (["guest-function", "guest-generator"].includes(String(value.kind)) || value.templateNodeId !== void 0));
|
|
25560
25649
|
if (closures.length > 0) {
|
|
25561
25650
|
const functions = /* @__PURE__ */ new Map();
|
|
25562
25651
|
const pending = [parseModule(options.source, "<input>", owner)];
|
|
@@ -25564,13 +25653,14 @@ function restore(snapshot, options, owner) {
|
|
|
25564
25653
|
const value = pending.pop();
|
|
25565
25654
|
if (value === null || typeof value !== "object") continue;
|
|
25566
25655
|
const node = value;
|
|
25567
|
-
if (
|
|
25656
|
+
if (typeof node.nodeId === "number") {
|
|
25568
25657
|
functions.set(node.nodeId, node);
|
|
25569
25658
|
}
|
|
25570
25659
|
for (const entry of Object.values(node)) pending.push(entry);
|
|
25571
25660
|
}
|
|
25572
25661
|
for (const [id, value] of closures) {
|
|
25573
25662
|
const record3 = value;
|
|
25663
|
+
if (record3.kind === "guest-array") continue;
|
|
25574
25664
|
const origin = functions.get(record3.astNodeId);
|
|
25575
25665
|
try {
|
|
25576
25666
|
validateGuestFunctionAst(record3, origin);
|
|
@@ -25578,6 +25668,11 @@ function restore(snapshot, options, owner) {
|
|
|
25578
25668
|
throw new SnapshotValidationError("invalidValue", `$.heap[${JSON.stringify(id)}].astNodeId`, error instanceof Error ? error.message : String(error));
|
|
25579
25669
|
}
|
|
25580
25670
|
}
|
|
25671
|
+
try {
|
|
25672
|
+
validateTemplateObjects(snapshot.heap, functions.values());
|
|
25673
|
+
} catch (error) {
|
|
25674
|
+
throw new SnapshotValidationError("invalidValue", "$.heap", String(error));
|
|
25675
|
+
}
|
|
25581
25676
|
}
|
|
25582
25677
|
}
|
|
25583
25678
|
return snapshot;
|
|
@@ -38782,4 +38877,4 @@ export {
|
|
|
38782
38877
|
FileSnapshotBackend,
|
|
38783
38878
|
run
|
|
38784
38879
|
};
|
|
38785
|
-
//# sourceMappingURL=chunk-
|
|
38880
|
+
//# sourceMappingURL=chunk-PEHO3DVD.js.map
|