@poe-platform/safe-js 0.1.162 → 0.1.164
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-MLVHXQVK.js → chunk-JPANSO6U.js} +2 -2
- package/dist/safe-js/chunks/{chunk-56XYHJCY.js → chunk-VHZYRV5Q.js} +261 -247
- package/dist/safe-js/chunks/chunk-VHZYRV5Q.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/dist/safe-js/interp/patterns.d.ts +3 -2
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-56XYHJCY.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-MLVHXQVK.js.map → chunk-JPANSO6U.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-VHZYRV5Q.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-JPANSO6U.js.map
|
|
@@ -2567,6 +2567,7 @@ var Parser = class {
|
|
|
2567
2567
|
loopDepth = 0;
|
|
2568
2568
|
scopes = [/* @__PURE__ */ new Map()];
|
|
2569
2569
|
functionScopes = /* @__PURE__ */ new WeakSet();
|
|
2570
|
+
parenthesizedNodes = /* @__PURE__ */ new WeakSet();
|
|
2570
2571
|
varNames = /* @__PURE__ */ new WeakMap();
|
|
2571
2572
|
withFunctionSource(node) {
|
|
2572
2573
|
functionSources.set(node, {
|
|
@@ -3941,13 +3942,12 @@ var Parser = class {
|
|
|
3941
3942
|
parseAssignmentObjectPatternProperty() {
|
|
3942
3943
|
if (this.consumePunctuator("...") !== void 0) {
|
|
3943
3944
|
const start = this.previousToken().start;
|
|
3944
|
-
const
|
|
3945
|
-
if (
|
|
3945
|
+
const argument = this.parseAssignmentTarget();
|
|
3946
|
+
if (argument.type !== "Identifier" && (argument.type !== "MemberExpression" || this.hasOptionalAssignmentChain(argument))) {
|
|
3946
3947
|
throw new Error(
|
|
3947
|
-
`Object rest
|
|
3948
|
+
`Object rest assignment requires an identifier or member target at line ${argument.span.start.line}, column ${argument.span.start.column}.`
|
|
3948
3949
|
);
|
|
3949
3950
|
}
|
|
3950
|
-
const argument = this.parseBindingIdentifier();
|
|
3951
3951
|
return {
|
|
3952
3952
|
type: "RestElement",
|
|
3953
3953
|
argument,
|
|
@@ -4427,6 +4427,7 @@ var Parser = class {
|
|
|
4427
4427
|
const expression = this.parseExpression({ allowSequence: true });
|
|
4428
4428
|
const end = this.expectPunctuator(")");
|
|
4429
4429
|
expression.node.span = createSpan2(start.start, end.end);
|
|
4430
|
+
this.parenthesizedNodes.add(expression.node);
|
|
4430
4431
|
return {
|
|
4431
4432
|
node: expression.node,
|
|
4432
4433
|
parenthesized: true
|
|
@@ -4963,9 +4964,9 @@ var Parser = class {
|
|
|
4963
4964
|
}
|
|
4964
4965
|
toObjectPatternProperty(property) {
|
|
4965
4966
|
if (property.type === "SpreadElement") {
|
|
4966
|
-
if (property.argument.type !== "Identifier") {
|
|
4967
|
+
if (property.argument.type !== "Identifier" && (property.argument.type !== "MemberExpression" || this.hasOptionalAssignmentChain(property.argument))) {
|
|
4967
4968
|
throw new Error(
|
|
4968
|
-
`Object rest
|
|
4969
|
+
`Object rest assignment requires an identifier or member target at line ${property.argument.span.start.line}, column ${property.argument.span.start.column}.`
|
|
4969
4970
|
);
|
|
4970
4971
|
}
|
|
4971
4972
|
return {
|
|
@@ -4984,6 +4985,15 @@ var Parser = class {
|
|
|
4984
4985
|
span: property.span
|
|
4985
4986
|
};
|
|
4986
4987
|
}
|
|
4988
|
+
hasOptionalAssignmentChain(node) {
|
|
4989
|
+
while (node.type === "MemberExpression" || node.type === "CallExpression") {
|
|
4990
|
+
if (node.optional) return true;
|
|
4991
|
+
const base = node.type === "MemberExpression" ? node.object : node.callee;
|
|
4992
|
+
if (this.parenthesizedNodes.has(base)) return false;
|
|
4993
|
+
node = base;
|
|
4994
|
+
}
|
|
4995
|
+
return false;
|
|
4996
|
+
}
|
|
4987
4997
|
toObjectPropertyValue(value) {
|
|
4988
4998
|
if (value.type === "AssignmentExpression" && value.operator === "=") {
|
|
4989
4999
|
return {
|
|
@@ -9070,221 +9080,6 @@ async function withRunResources(signal, execute) {
|
|
|
9070
9080
|
return result;
|
|
9071
9081
|
}
|
|
9072
9082
|
|
|
9073
|
-
// packages/safe-js/src/interp/patterns.ts
|
|
9074
|
-
async function bindPattern(pattern, value, target, scope, context) {
|
|
9075
|
-
switch (pattern.type) {
|
|
9076
|
-
case "Identifier":
|
|
9077
|
-
bindIdentifier(pattern, value, target, scope);
|
|
9078
|
-
return { ok: true };
|
|
9079
|
-
case "MemberExpression":
|
|
9080
|
-
if ("kind" in target) {
|
|
9081
|
-
throw new TypeError("Destructuring declarations cannot bind to member expressions.");
|
|
9082
|
-
}
|
|
9083
|
-
return bindMemberExpression(pattern, value, scope, context);
|
|
9084
|
-
case "AssignmentPattern":
|
|
9085
|
-
return bindAssignmentPattern(pattern, value, target, scope, context);
|
|
9086
|
-
case "ArrayPattern":
|
|
9087
|
-
return bindArrayPattern(pattern, value, target, scope, context);
|
|
9088
|
-
case "ObjectPattern":
|
|
9089
|
-
return bindObjectPattern(pattern, value, target, scope, context);
|
|
9090
|
-
case "RestElement":
|
|
9091
|
-
return bindPattern(pattern.argument, value, target, scope, context);
|
|
9092
|
-
}
|
|
9093
|
-
}
|
|
9094
|
-
function bindIdentifier(pattern, value, target, scope) {
|
|
9095
|
-
if ("assign" in target || target.kind === "var" && target.initialize !== true) {
|
|
9096
|
-
if ("assign" in target) {
|
|
9097
|
-
const binding = scope.lookup(pattern.name);
|
|
9098
|
-
if (!binding.found) {
|
|
9099
|
-
throw new ReferenceError(`Cannot assign to undeclared binding '${pattern.name}'.`);
|
|
9100
|
-
}
|
|
9101
|
-
if (binding.kind === "const") {
|
|
9102
|
-
throw new TypeError(`Cannot assign to const '${pattern.name}'`);
|
|
9103
|
-
}
|
|
9104
|
-
}
|
|
9105
|
-
scope.assign(pattern.name, value);
|
|
9106
|
-
return;
|
|
9107
|
-
}
|
|
9108
|
-
scope.declare(pattern.name, target.kind, value);
|
|
9109
|
-
}
|
|
9110
|
-
async function bindAssignmentPattern(pattern, value, target, scope, context) {
|
|
9111
|
-
if (value !== void 0) {
|
|
9112
|
-
return bindPattern(pattern.left, value, target, scope, context);
|
|
9113
|
-
}
|
|
9114
|
-
const defaultValue = await context.evaluate(
|
|
9115
|
-
pattern.right,
|
|
9116
|
-
pattern.left.type === "Identifier" ? pattern.left.name : void 0
|
|
9117
|
-
);
|
|
9118
|
-
if (defaultValue.kind !== "normal") {
|
|
9119
|
-
return { ok: false, result: defaultValue };
|
|
9120
|
-
}
|
|
9121
|
-
return bindPattern(pattern.left, defaultValue.value, target, scope, context);
|
|
9122
|
-
}
|
|
9123
|
-
async function bindArrayPattern(pattern, value, target, scope, context) {
|
|
9124
|
-
const iterator = isSandboxCollectionIterator(value) ? value : void 0;
|
|
9125
|
-
const values = iterator === void 0 ? getArrayPatternValues(value) : void 0;
|
|
9126
|
-
let cursor = 0;
|
|
9127
|
-
let done = false;
|
|
9128
|
-
const next = async () => {
|
|
9129
|
-
if (iterator !== void 0) return nextCollectionIterator(iterator, context.budget);
|
|
9130
|
-
if (done || cursor >= values.length) {
|
|
9131
|
-
done = true;
|
|
9132
|
-
return { done: true, value: void 0 };
|
|
9133
|
-
}
|
|
9134
|
-
return { done: false, value: await context.getProperty(values, cursor++) };
|
|
9135
|
-
};
|
|
9136
|
-
for (let index = 0; index < pattern.elements.length; index += 1) {
|
|
9137
|
-
const element = pattern.elements[index];
|
|
9138
|
-
if (element === null) {
|
|
9139
|
-
await next();
|
|
9140
|
-
continue;
|
|
9141
|
-
}
|
|
9142
|
-
let elementValue;
|
|
9143
|
-
if (element.type === "RestElement") {
|
|
9144
|
-
const rest = [];
|
|
9145
|
-
for (let entry = await next(); !entry.done; entry = await next()) {
|
|
9146
|
-
context.budget?.allocateArrayLength(rest.length + 1);
|
|
9147
|
-
rest.push(entry.value);
|
|
9148
|
-
}
|
|
9149
|
-
elementValue = rest;
|
|
9150
|
-
} else {
|
|
9151
|
-
elementValue = (await next()).value;
|
|
9152
|
-
}
|
|
9153
|
-
const binding = await bindPattern(element, elementValue, target, scope, context);
|
|
9154
|
-
if (!binding.ok) {
|
|
9155
|
-
return binding;
|
|
9156
|
-
}
|
|
9157
|
-
}
|
|
9158
|
-
return { ok: true };
|
|
9159
|
-
}
|
|
9160
|
-
async function bindObjectPattern(pattern, value, target, scope, context) {
|
|
9161
|
-
if (typeof value !== "object" || value === null) {
|
|
9162
|
-
throw new TypeError("Object destructuring declarations require a non-null object value.");
|
|
9163
|
-
}
|
|
9164
|
-
const excludedKeys = /* @__PURE__ */ new Set();
|
|
9165
|
-
for (const property of pattern.properties) {
|
|
9166
|
-
if (property.type === "RestElement") {
|
|
9167
|
-
const binding2 = await bindPattern(
|
|
9168
|
-
property,
|
|
9169
|
-
await copyObjectRestValue(value, excludedKeys, context),
|
|
9170
|
-
target,
|
|
9171
|
-
scope,
|
|
9172
|
-
context
|
|
9173
|
-
);
|
|
9174
|
-
if (!binding2.ok) {
|
|
9175
|
-
return binding2;
|
|
9176
|
-
}
|
|
9177
|
-
continue;
|
|
9178
|
-
}
|
|
9179
|
-
const key = await evaluatePatternKey(property, context);
|
|
9180
|
-
if (!key.ok) {
|
|
9181
|
-
return key;
|
|
9182
|
-
}
|
|
9183
|
-
excludedKeys.add(typeof key.value === "symbol" ? key.value : String(key.value));
|
|
9184
|
-
const binding = await bindPattern(
|
|
9185
|
-
property.value,
|
|
9186
|
-
await context.getProperty(value, key.value),
|
|
9187
|
-
target,
|
|
9188
|
-
scope,
|
|
9189
|
-
context
|
|
9190
|
-
);
|
|
9191
|
-
if (!binding.ok) {
|
|
9192
|
-
return binding;
|
|
9193
|
-
}
|
|
9194
|
-
}
|
|
9195
|
-
return { ok: true };
|
|
9196
|
-
}
|
|
9197
|
-
async function bindMemberExpression(pattern, value, scope, context) {
|
|
9198
|
-
const object = await context.evaluate(pattern.object);
|
|
9199
|
-
if (object.kind !== "normal") {
|
|
9200
|
-
return { ok: false, result: object };
|
|
9201
|
-
}
|
|
9202
|
-
const property = pattern.computed ? await context.evaluate(pattern.property) : { kind: "normal", value: getStaticPropertyName(pattern.property) };
|
|
9203
|
-
if (property.kind !== "normal") {
|
|
9204
|
-
return { ok: false, result: property };
|
|
9205
|
-
}
|
|
9206
|
-
if (object.value === null || object.value === void 0) {
|
|
9207
|
-
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
9208
|
-
}
|
|
9209
|
-
if (!isIndexableValue(object.value)) {
|
|
9210
|
-
throw new TypeError("Assignment expressions require a sandbox object property.");
|
|
9211
|
-
}
|
|
9212
|
-
await context.setProperty(object.value, await context.toPropertyKey(property.value), value);
|
|
9213
|
-
return { ok: true };
|
|
9214
|
-
}
|
|
9215
|
-
async function evaluatePatternKey(property, context) {
|
|
9216
|
-
return property.computed ? evaluateProperty(property.key, context) : { ok: true, value: getStaticPropertyName(property.key) };
|
|
9217
|
-
}
|
|
9218
|
-
async function evaluateProperty(property, context) {
|
|
9219
|
-
const result = await context.evaluate(property);
|
|
9220
|
-
if (result.kind !== "normal") {
|
|
9221
|
-
return { ok: false, result };
|
|
9222
|
-
}
|
|
9223
|
-
return { ok: true, value: await context.toPropertyKey(result.value) };
|
|
9224
|
-
}
|
|
9225
|
-
function getStaticPropertyName(property) {
|
|
9226
|
-
if (property.type === "Identifier") {
|
|
9227
|
-
return property.name;
|
|
9228
|
-
}
|
|
9229
|
-
if (property.type === "StringLiteral" || property.type === "NumericLiteral") {
|
|
9230
|
-
return property.value;
|
|
9231
|
-
}
|
|
9232
|
-
throw new TypeError(`Unsupported static property node '${property.type}'.`);
|
|
9233
|
-
}
|
|
9234
|
-
function getArrayPatternValues(value) {
|
|
9235
|
-
if (Array.isArray(value)) {
|
|
9236
|
-
return value;
|
|
9237
|
-
}
|
|
9238
|
-
if (typeof value === "string") {
|
|
9239
|
-
return Array.from(value);
|
|
9240
|
-
}
|
|
9241
|
-
if (isSandboxMap(value)) {
|
|
9242
|
-
return Array.from(value.entries, ([key, entry]) => [key, entry]);
|
|
9243
|
-
}
|
|
9244
|
-
if (isSandboxSet(value)) {
|
|
9245
|
-
return [...value.values];
|
|
9246
|
-
}
|
|
9247
|
-
if (isIterableValue(value)) {
|
|
9248
|
-
throw new TypeError(
|
|
9249
|
-
`Array destructuring declarations support only arrays and strings; received ${describeRuntimeValue(value)}.`
|
|
9250
|
-
);
|
|
9251
|
-
}
|
|
9252
|
-
throw new TypeError("Array destructuring declarations require an array or string iterable.");
|
|
9253
|
-
}
|
|
9254
|
-
function isIterableValue(value) {
|
|
9255
|
-
return typeof value === "object" && value !== null && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
9256
|
-
}
|
|
9257
|
-
function describeRuntimeValue(value) {
|
|
9258
|
-
if (value === null) return "null";
|
|
9259
|
-
if (value === void 0) return "undefined";
|
|
9260
|
-
if (typeof value === "object") return value.constructor?.name ?? "Object";
|
|
9261
|
-
return typeof value;
|
|
9262
|
-
}
|
|
9263
|
-
async function copyObjectRestValue(value, excludedKeys, context) {
|
|
9264
|
-
const rest = /* @__PURE__ */ Object.create(null);
|
|
9265
|
-
const release = context.budget === void 0 ? () => void 0 : retainValues(context.budget, () => [value, rest]);
|
|
9266
|
-
try {
|
|
9267
|
-
for (const key of ownEnumerableSandboxKeys(value, true)) {
|
|
9268
|
-
if (excludedKeys.has(key) || !hasOwnSandboxProperty(value, key, true)) continue;
|
|
9269
|
-
defineProperty(rest, key, await context.getProperty(value, key));
|
|
9270
|
-
}
|
|
9271
|
-
return rest;
|
|
9272
|
-
} finally {
|
|
9273
|
-
release();
|
|
9274
|
-
}
|
|
9275
|
-
}
|
|
9276
|
-
function isIndexableValue(value) {
|
|
9277
|
-
return typeof value === "object" && value !== null;
|
|
9278
|
-
}
|
|
9279
|
-
function defineProperty(target, key, value) {
|
|
9280
|
-
Object.defineProperty(target, key, {
|
|
9281
|
-
configurable: true,
|
|
9282
|
-
enumerable: true,
|
|
9283
|
-
value,
|
|
9284
|
-
writable: true
|
|
9285
|
-
});
|
|
9286
|
-
}
|
|
9287
|
-
|
|
9288
9083
|
// packages/safe-js/src/interp/jobs.ts
|
|
9289
9084
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
9290
9085
|
var activeJob = new AsyncLocalStorage4();
|
|
@@ -9377,31 +9172,6 @@ async function suspendJob(pending) {
|
|
|
9377
9172
|
}
|
|
9378
9173
|
}
|
|
9379
9174
|
|
|
9380
|
-
// packages/safe-js/src/interp/var-hoist.ts
|
|
9381
|
-
function hoistVarDeclarations(node, scope) {
|
|
9382
|
-
for (const declaration of hoistedVarDeclarations([node])) {
|
|
9383
|
-
for (const declarator of declaration.declarations) {
|
|
9384
|
-
for (const identifier of boundIdentifiers(declarator.id)) {
|
|
9385
|
-
scope.declareVar(identifier.name);
|
|
9386
|
-
}
|
|
9387
|
-
}
|
|
9388
|
-
}
|
|
9389
|
-
}
|
|
9390
|
-
|
|
9391
|
-
// packages/safe-js/src/interp/data-checkpoint.ts
|
|
9392
|
-
function createDataCheckpoint(budget, context) {
|
|
9393
|
-
let estimatedDataSize = 0;
|
|
9394
|
-
return (value, growth = 0, force = false) => {
|
|
9395
|
-
const limit = budget.limits.dataSize;
|
|
9396
|
-
if (limit === void 0) return;
|
|
9397
|
-
estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
|
|
9398
|
-
if (!force && estimatedDataSize <= limit) return;
|
|
9399
|
-
if (context?.reconcileData !== void 0) context.reconcileData(value);
|
|
9400
|
-
else reconcileCompiledValues(budget, [value], context?.compilation);
|
|
9401
|
-
estimatedDataSize = budget.currentDataSize;
|
|
9402
|
-
};
|
|
9403
|
-
}
|
|
9404
|
-
|
|
9405
9175
|
// packages/safe-js/src/interp/iteration.ts
|
|
9406
9176
|
async function acquireSandboxIterator(value, budget, context, asyncProtocol = false, signal) {
|
|
9407
9177
|
const key = asyncProtocol ? Symbol.asyncIterator : Symbol.iterator;
|
|
@@ -9715,6 +9485,249 @@ function syncIterator(iterator) {
|
|
|
9715
9485
|
};
|
|
9716
9486
|
}
|
|
9717
9487
|
|
|
9488
|
+
// packages/safe-js/src/interp/patterns.ts
|
|
9489
|
+
async function bindPattern(pattern, value, target, scope, context) {
|
|
9490
|
+
switch (pattern.type) {
|
|
9491
|
+
case "Identifier":
|
|
9492
|
+
bindIdentifier(pattern, value, target, scope);
|
|
9493
|
+
return { ok: true };
|
|
9494
|
+
case "MemberExpression":
|
|
9495
|
+
if ("kind" in target) {
|
|
9496
|
+
throw new TypeError("Destructuring declarations cannot bind to member expressions.");
|
|
9497
|
+
}
|
|
9498
|
+
return bindMemberExpression(pattern, value, scope, context);
|
|
9499
|
+
case "AssignmentPattern":
|
|
9500
|
+
return bindAssignmentPattern(pattern, value, target, scope, context);
|
|
9501
|
+
case "ArrayPattern":
|
|
9502
|
+
return bindArrayPattern(pattern, value, target, scope, context);
|
|
9503
|
+
case "ObjectPattern":
|
|
9504
|
+
return bindObjectPattern(pattern, value, target, scope, context);
|
|
9505
|
+
case "RestElement":
|
|
9506
|
+
return bindPattern(pattern.argument, value, target, scope, context);
|
|
9507
|
+
}
|
|
9508
|
+
}
|
|
9509
|
+
function bindIdentifier(pattern, value, target, scope) {
|
|
9510
|
+
if ("assign" in target || target.kind === "var" && target.initialize !== true) {
|
|
9511
|
+
if ("assign" in target) {
|
|
9512
|
+
const binding = scope.lookup(pattern.name);
|
|
9513
|
+
if (!binding.found) {
|
|
9514
|
+
throw new ReferenceError(`Cannot assign to undeclared binding '${pattern.name}'.`);
|
|
9515
|
+
}
|
|
9516
|
+
if (binding.kind === "const") {
|
|
9517
|
+
throw new TypeError(`Cannot assign to const '${pattern.name}'`);
|
|
9518
|
+
}
|
|
9519
|
+
}
|
|
9520
|
+
scope.assign(pattern.name, value);
|
|
9521
|
+
return;
|
|
9522
|
+
}
|
|
9523
|
+
scope.declare(pattern.name, target.kind, value);
|
|
9524
|
+
}
|
|
9525
|
+
async function bindAssignmentPattern(pattern, value, target, scope, context) {
|
|
9526
|
+
if (value !== void 0) {
|
|
9527
|
+
return bindPattern(pattern.left, value, target, scope, context);
|
|
9528
|
+
}
|
|
9529
|
+
const defaultValue = await context.evaluate(
|
|
9530
|
+
pattern.right,
|
|
9531
|
+
pattern.left.type === "Identifier" ? pattern.left.name : void 0
|
|
9532
|
+
);
|
|
9533
|
+
if (defaultValue.kind !== "normal") {
|
|
9534
|
+
return { ok: false, result: defaultValue };
|
|
9535
|
+
}
|
|
9536
|
+
return bindPattern(pattern.left, defaultValue.value, target, scope, context);
|
|
9537
|
+
}
|
|
9538
|
+
async function bindArrayPattern(pattern, value, target, scope, context) {
|
|
9539
|
+
const budget = context.budget ?? new Budget();
|
|
9540
|
+
const iterator = await acquireSandboxIterator(
|
|
9541
|
+
value,
|
|
9542
|
+
budget,
|
|
9543
|
+
context.callContext ?? {
|
|
9544
|
+
stack: [],
|
|
9545
|
+
thisValue: void 0,
|
|
9546
|
+
getProperty: context.getProperty
|
|
9547
|
+
}
|
|
9548
|
+
);
|
|
9549
|
+
if (iterator === void 0) throw new TypeError("Array destructuring requires an iterable.");
|
|
9550
|
+
let done = false;
|
|
9551
|
+
const next = async (readValue = true) => {
|
|
9552
|
+
if (done) return { value: void 0 };
|
|
9553
|
+
try {
|
|
9554
|
+
const result = await iterator.next();
|
|
9555
|
+
if (typeof result !== "object" && typeof result !== "function" || result === null)
|
|
9556
|
+
throw new TypeError("Iterator result must be an object.");
|
|
9557
|
+
done = Boolean((await readIteratorResult(iterator, result, "done")).value);
|
|
9558
|
+
return done || !readValue ? { value: void 0 } : await readIteratorResult(iterator, result, "value");
|
|
9559
|
+
} catch (error) {
|
|
9560
|
+
done = true;
|
|
9561
|
+
throw error;
|
|
9562
|
+
}
|
|
9563
|
+
};
|
|
9564
|
+
let retained;
|
|
9565
|
+
const release = retainValues(budget, () => [value, iterator.retainedValue, retained]);
|
|
9566
|
+
try {
|
|
9567
|
+
for (let index = 0; index < pattern.elements.length; index += 1) {
|
|
9568
|
+
const element = pattern.elements[index];
|
|
9569
|
+
if (element === null) {
|
|
9570
|
+
await next(false);
|
|
9571
|
+
continue;
|
|
9572
|
+
}
|
|
9573
|
+
let elementValue;
|
|
9574
|
+
if (element.type === "RestElement") {
|
|
9575
|
+
const rest = [];
|
|
9576
|
+
retained = rest;
|
|
9577
|
+
for (let entry = await next(); !done; entry = await next()) {
|
|
9578
|
+
budget.allocateArrayLength(rest.length + 1);
|
|
9579
|
+
rest.push(entry.value);
|
|
9580
|
+
}
|
|
9581
|
+
elementValue = rest;
|
|
9582
|
+
} else {
|
|
9583
|
+
elementValue = (await next()).value;
|
|
9584
|
+
}
|
|
9585
|
+
retained = elementValue;
|
|
9586
|
+
const binding = await bindPattern(element, elementValue, target, scope, context);
|
|
9587
|
+
if (!binding.ok) {
|
|
9588
|
+
if (!done) {
|
|
9589
|
+
done = true;
|
|
9590
|
+
await closeIterator(iterator, binding.result.kind === "throw");
|
|
9591
|
+
}
|
|
9592
|
+
return binding;
|
|
9593
|
+
}
|
|
9594
|
+
}
|
|
9595
|
+
if (!done) {
|
|
9596
|
+
done = true;
|
|
9597
|
+
await closeIterator(iterator);
|
|
9598
|
+
}
|
|
9599
|
+
return { ok: true };
|
|
9600
|
+
} catch (error) {
|
|
9601
|
+
if (!done && !isFatalSandboxError(error)) await closeIterator(iterator, true);
|
|
9602
|
+
throw error;
|
|
9603
|
+
} finally {
|
|
9604
|
+
release();
|
|
9605
|
+
}
|
|
9606
|
+
}
|
|
9607
|
+
async function bindObjectPattern(pattern, value, target, scope, context) {
|
|
9608
|
+
if (typeof value !== "object" || value === null) {
|
|
9609
|
+
throw new TypeError("Object destructuring declarations require a non-null object value.");
|
|
9610
|
+
}
|
|
9611
|
+
const excludedKeys = /* @__PURE__ */ new Set();
|
|
9612
|
+
for (const property of pattern.properties) {
|
|
9613
|
+
if (property.type === "RestElement") {
|
|
9614
|
+
const binding2 = await bindPattern(
|
|
9615
|
+
property,
|
|
9616
|
+
await copyObjectRestValue(value, excludedKeys, context),
|
|
9617
|
+
target,
|
|
9618
|
+
scope,
|
|
9619
|
+
context
|
|
9620
|
+
);
|
|
9621
|
+
if (!binding2.ok) {
|
|
9622
|
+
return binding2;
|
|
9623
|
+
}
|
|
9624
|
+
continue;
|
|
9625
|
+
}
|
|
9626
|
+
const key = await evaluatePatternKey(property, context);
|
|
9627
|
+
if (!key.ok) {
|
|
9628
|
+
return key;
|
|
9629
|
+
}
|
|
9630
|
+
excludedKeys.add(typeof key.value === "symbol" ? key.value : String(key.value));
|
|
9631
|
+
const binding = await bindPattern(
|
|
9632
|
+
property.value,
|
|
9633
|
+
await context.getProperty(value, key.value),
|
|
9634
|
+
target,
|
|
9635
|
+
scope,
|
|
9636
|
+
context
|
|
9637
|
+
);
|
|
9638
|
+
if (!binding.ok) {
|
|
9639
|
+
return binding;
|
|
9640
|
+
}
|
|
9641
|
+
}
|
|
9642
|
+
return { ok: true };
|
|
9643
|
+
}
|
|
9644
|
+
async function bindMemberExpression(pattern, value, scope, context) {
|
|
9645
|
+
const object = await context.evaluate(pattern.object);
|
|
9646
|
+
if (object.kind !== "normal") {
|
|
9647
|
+
return { ok: false, result: object };
|
|
9648
|
+
}
|
|
9649
|
+
const property = pattern.computed ? await context.evaluate(pattern.property) : { kind: "normal", value: getStaticPropertyName(pattern.property) };
|
|
9650
|
+
if (property.kind !== "normal") {
|
|
9651
|
+
return { ok: false, result: property };
|
|
9652
|
+
}
|
|
9653
|
+
if (object.value === null || object.value === void 0) {
|
|
9654
|
+
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
9655
|
+
}
|
|
9656
|
+
if (!isIndexableValue(object.value)) {
|
|
9657
|
+
throw new TypeError("Assignment expressions require a sandbox object property.");
|
|
9658
|
+
}
|
|
9659
|
+
await context.setProperty(object.value, await context.toPropertyKey(property.value), value);
|
|
9660
|
+
return { ok: true };
|
|
9661
|
+
}
|
|
9662
|
+
async function evaluatePatternKey(property, context) {
|
|
9663
|
+
return property.computed ? evaluateProperty(property.key, context) : { ok: true, value: getStaticPropertyName(property.key) };
|
|
9664
|
+
}
|
|
9665
|
+
async function evaluateProperty(property, context) {
|
|
9666
|
+
const result = await context.evaluate(property);
|
|
9667
|
+
if (result.kind !== "normal") {
|
|
9668
|
+
return { ok: false, result };
|
|
9669
|
+
}
|
|
9670
|
+
return { ok: true, value: await context.toPropertyKey(result.value) };
|
|
9671
|
+
}
|
|
9672
|
+
function getStaticPropertyName(property) {
|
|
9673
|
+
if (property.type === "Identifier") {
|
|
9674
|
+
return property.name;
|
|
9675
|
+
}
|
|
9676
|
+
if (property.type === "StringLiteral" || property.type === "NumericLiteral") {
|
|
9677
|
+
return property.value;
|
|
9678
|
+
}
|
|
9679
|
+
throw new TypeError(`Unsupported static property node '${property.type}'.`);
|
|
9680
|
+
}
|
|
9681
|
+
async function copyObjectRestValue(value, excludedKeys, context) {
|
|
9682
|
+
const rest = /* @__PURE__ */ Object.create(null);
|
|
9683
|
+
const release = context.budget === void 0 ? () => void 0 : retainValues(context.budget, () => [value, rest]);
|
|
9684
|
+
try {
|
|
9685
|
+
for (const key of ownEnumerableSandboxKeys(value, true)) {
|
|
9686
|
+
if (excludedKeys.has(key) || !hasOwnSandboxProperty(value, key, true)) continue;
|
|
9687
|
+
defineProperty(rest, key, await context.getProperty(value, key));
|
|
9688
|
+
}
|
|
9689
|
+
return rest;
|
|
9690
|
+
} finally {
|
|
9691
|
+
release();
|
|
9692
|
+
}
|
|
9693
|
+
}
|
|
9694
|
+
function isIndexableValue(value) {
|
|
9695
|
+
return typeof value === "object" && value !== null;
|
|
9696
|
+
}
|
|
9697
|
+
function defineProperty(target, key, value) {
|
|
9698
|
+
Object.defineProperty(target, key, {
|
|
9699
|
+
configurable: true,
|
|
9700
|
+
enumerable: true,
|
|
9701
|
+
value,
|
|
9702
|
+
writable: true
|
|
9703
|
+
});
|
|
9704
|
+
}
|
|
9705
|
+
|
|
9706
|
+
// packages/safe-js/src/interp/var-hoist.ts
|
|
9707
|
+
function hoistVarDeclarations(node, scope) {
|
|
9708
|
+
for (const declaration of hoistedVarDeclarations([node])) {
|
|
9709
|
+
for (const declarator of declaration.declarations) {
|
|
9710
|
+
for (const identifier of boundIdentifiers(declarator.id)) {
|
|
9711
|
+
scope.declareVar(identifier.name);
|
|
9712
|
+
}
|
|
9713
|
+
}
|
|
9714
|
+
}
|
|
9715
|
+
}
|
|
9716
|
+
|
|
9717
|
+
// packages/safe-js/src/interp/data-checkpoint.ts
|
|
9718
|
+
function createDataCheckpoint(budget, context) {
|
|
9719
|
+
let estimatedDataSize = 0;
|
|
9720
|
+
return (value, growth = 0, force = false) => {
|
|
9721
|
+
const limit = budget.limits.dataSize;
|
|
9722
|
+
if (limit === void 0) return;
|
|
9723
|
+
estimatedDataSize = Math.max(estimatedDataSize, budget.currentDataSize) + growth;
|
|
9724
|
+
if (!force && estimatedDataSize <= limit) return;
|
|
9725
|
+
if (context?.reconcileData !== void 0) context.reconcileData(value);
|
|
9726
|
+
else reconcileCompiledValues(budget, [value], context?.compilation);
|
|
9727
|
+
estimatedDataSize = budget.currentDataSize;
|
|
9728
|
+
};
|
|
9729
|
+
}
|
|
9730
|
+
|
|
9718
9731
|
// packages/safe-js/src/interp/globals/numeric-parsers.ts
|
|
9719
9732
|
function createNumericParsers(budget) {
|
|
9720
9733
|
return {
|
|
@@ -15492,6 +15505,7 @@ function createPatternContext(context, scope = context.scope, evaluate = evaluat
|
|
|
15492
15505
|
const evaluationContext = { ...context, scope };
|
|
15493
15506
|
return {
|
|
15494
15507
|
budget: context.budget,
|
|
15508
|
+
callContext: createCoercionContext(evaluationContext),
|
|
15495
15509
|
evaluate: (node, inferredName) => evaluate(node, { ...evaluationContext, inferredName }),
|
|
15496
15510
|
toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
|
|
15497
15511
|
getProperty: (value, key) => getPropertyValue(value, key, evaluationContext),
|
|
@@ -35882,4 +35896,4 @@ export {
|
|
|
35882
35896
|
FileSnapshotBackend,
|
|
35883
35897
|
run
|
|
35884
35898
|
};
|
|
35885
|
-
//# sourceMappingURL=chunk-
|
|
35899
|
+
//# sourceMappingURL=chunk-VHZYRV5Q.js.map
|