@poe-platform/safe-js 0.1.87 → 0.1.89
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-J6FLHEO5.js → chunk-KWV4LCEU.js} +2 -2
- package/dist/safe-js/chunks/{chunk-GO774BRE.js → chunk-M4M56OCI.js} +240 -184
- package/dist/safe-js/chunks/chunk-M4M56OCI.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/async.d.ts +1 -0
- package/dist/safe-js/interp/exceptions.d.ts +1 -0
- package/dist/safe-js/interp/interpreter.d.ts +1 -0
- package/dist/safe-js/interp/patterns.d.ts +1 -0
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-GO774BRE.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-J6FLHEO5.js.map → chunk-KWV4LCEU.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-M4M56OCI.js";
|
|
31
31
|
|
|
32
32
|
// packages/safe-js/src/migrate.ts
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
@@ -8245,4 +8245,4 @@ export {
|
|
|
8245
8245
|
parseMcpConfig,
|
|
8246
8246
|
makeMcpModule
|
|
8247
8247
|
};
|
|
8248
|
-
//# sourceMappingURL=chunk-
|
|
8248
|
+
//# sourceMappingURL=chunk-KWV4LCEU.js.map
|
|
@@ -6997,6 +6997,27 @@ function getSandboxPrototype(value, budget) {
|
|
|
6997
6997
|
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
6998
6998
|
return budget !== void 0 && isPrototypeRecord(value) ? intrinsicPrototypes.get(budget) ?? null : null;
|
|
6999
6999
|
}
|
|
7000
|
+
function getSandboxDataProperty(value, key, budget) {
|
|
7001
|
+
let current = value;
|
|
7002
|
+
let depth = 0;
|
|
7003
|
+
while (typeof current === "object" && current !== null) {
|
|
7004
|
+
if (isGuestHostObject(current)) return getHostObjectMember(current, String(key));
|
|
7005
|
+
if (isGuestClosure(current)) return getGuestFunctionProperty(current, String(key));
|
|
7006
|
+
if (isSandboxClosure(current)) {
|
|
7007
|
+
const properties = current.properties;
|
|
7008
|
+
return properties !== void 0 && Object.hasOwn(properties, String(key)) ? properties[String(key)] : void 0;
|
|
7009
|
+
}
|
|
7010
|
+
if (isSandboxMap(current) || isSandboxSet(current) || isSandboxPromise(current) || isSandboxRegex(current) || isSandboxGenerator(current))
|
|
7011
|
+
return void 0;
|
|
7012
|
+
if (Object.hasOwn(current, String(key))) return current[String(key)];
|
|
7013
|
+
current = getSandboxPrototype(current, budget);
|
|
7014
|
+
if (current !== null) {
|
|
7015
|
+
budget?.visitNode();
|
|
7016
|
+
assertSandboxDataDepth(++depth);
|
|
7017
|
+
}
|
|
7018
|
+
}
|
|
7019
|
+
return void 0;
|
|
7020
|
+
}
|
|
7000
7021
|
function setSandboxPrototype(value, prototype, budget) {
|
|
7001
7022
|
if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
|
|
7002
7023
|
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
@@ -8157,6 +8178,119 @@ function isCounter(value) {
|
|
|
8157
8178
|
// packages/safe-js/src/interp/cancel.ts
|
|
8158
8179
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
8159
8180
|
|
|
8181
|
+
// packages/safe-js/src/interp/string-coercion.ts
|
|
8182
|
+
function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
|
|
8183
|
+
if (value === null || typeof value !== "object") {
|
|
8184
|
+
if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
|
|
8185
|
+
return budget.allocateString(String(value));
|
|
8186
|
+
}
|
|
8187
|
+
return stringifyObject(value, budget, context, joining);
|
|
8188
|
+
}
|
|
8189
|
+
async function stringifyObject(value, budget, context, joining) {
|
|
8190
|
+
const leaveCall = budget.enterCall();
|
|
8191
|
+
try {
|
|
8192
|
+
budget.visitNode();
|
|
8193
|
+
for (const name of ["toString", "valueOf"]) {
|
|
8194
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
8195
|
+
let result;
|
|
8196
|
+
if (descriptor === void 0) {
|
|
8197
|
+
if (name === "valueOf") continue;
|
|
8198
|
+
result = await defaultToString(value, budget, context, joining);
|
|
8199
|
+
} else {
|
|
8200
|
+
const hook = ownDataValue(value, name);
|
|
8201
|
+
if (!isSandboxClosure(hook)) continue;
|
|
8202
|
+
if (context?.invokeClosure === void 0) {
|
|
8203
|
+
throw new TypeError("String hooks require a sandbox call context.");
|
|
8204
|
+
}
|
|
8205
|
+
result = await context.invokeClosure(hook, [], value);
|
|
8206
|
+
}
|
|
8207
|
+
if (result === null || typeof result !== "object") {
|
|
8208
|
+
return sandboxString(result, budget, context, joining);
|
|
8209
|
+
}
|
|
8210
|
+
}
|
|
8211
|
+
throw new TypeError("Cannot convert object to primitive value");
|
|
8212
|
+
} finally {
|
|
8213
|
+
leaveCall();
|
|
8214
|
+
}
|
|
8215
|
+
}
|
|
8216
|
+
async function defaultToString(value, budget, context, joining) {
|
|
8217
|
+
if (isSandboxDate(value)) return budget.allocateString(dateString(value));
|
|
8218
|
+
if (Array.isArray(value) || isFloat32Array(value)) {
|
|
8219
|
+
if (Object.hasOwn(value, "join")) {
|
|
8220
|
+
const join = ownDataValue(value, "join");
|
|
8221
|
+
if (!isSandboxClosure(join))
|
|
8222
|
+
return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
|
|
8223
|
+
if (context?.invokeClosure === void 0) {
|
|
8224
|
+
throw new TypeError("String hooks require a sandbox call context.");
|
|
8225
|
+
}
|
|
8226
|
+
return context.invokeClosure(join, [], value);
|
|
8227
|
+
}
|
|
8228
|
+
if (joining.has(value)) return "";
|
|
8229
|
+
joining.add(value);
|
|
8230
|
+
try {
|
|
8231
|
+
const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
|
|
8232
|
+
let text = "";
|
|
8233
|
+
for (let index = 0; index < length; index++) {
|
|
8234
|
+
budget.visitNode();
|
|
8235
|
+
const element = ownDataValue(value, String(index));
|
|
8236
|
+
const part = element === null || element === void 0 ? "" : await sandboxString(element, budget, context, joining);
|
|
8237
|
+
text = budget.allocateString(text + (index === 0 ? "" : ",") + part);
|
|
8238
|
+
}
|
|
8239
|
+
return text;
|
|
8240
|
+
} finally {
|
|
8241
|
+
joining.delete(value);
|
|
8242
|
+
}
|
|
8243
|
+
}
|
|
8244
|
+
if (sandboxErrorTypes.has(value)) {
|
|
8245
|
+
const nameValue = ownDataValue(value, "name");
|
|
8246
|
+
const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
|
|
8247
|
+
const messageValue = ownDataValue(value, "message");
|
|
8248
|
+
const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
|
|
8249
|
+
return name === "" ? message : message === "" ? name : `${name}: ${message}`;
|
|
8250
|
+
}
|
|
8251
|
+
return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
|
|
8252
|
+
}
|
|
8253
|
+
function ownDataValue(value, name) {
|
|
8254
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
8255
|
+
if (descriptor !== void 0 && !Object.hasOwn(descriptor, "value")) {
|
|
8256
|
+
throw new TypeError("String conversion requires sandbox data properties.");
|
|
8257
|
+
}
|
|
8258
|
+
return descriptor?.value;
|
|
8259
|
+
}
|
|
8260
|
+
|
|
8261
|
+
// packages/safe-js/src/interp/property-key.ts
|
|
8262
|
+
async function toPropertyKey(value, budget, context) {
|
|
8263
|
+
if (typeof value === "string") return value;
|
|
8264
|
+
const invocation = context.invokeClosure === void 0 ? {
|
|
8265
|
+
...context,
|
|
8266
|
+
invokeClosure: async (closure, args, thisValue) => {
|
|
8267
|
+
const leaveCall = budget.enterCall();
|
|
8268
|
+
try {
|
|
8269
|
+
const result = closure.call(args, { ...invocation, thisValue });
|
|
8270
|
+
if (isSandboxPromise(result)) {
|
|
8271
|
+
await result.synchronousPrefix;
|
|
8272
|
+
return result;
|
|
8273
|
+
}
|
|
8274
|
+
return await result;
|
|
8275
|
+
} finally {
|
|
8276
|
+
leaveCall();
|
|
8277
|
+
}
|
|
8278
|
+
}
|
|
8279
|
+
} : context;
|
|
8280
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) && !isSandboxClosure(value) && !isSandboxMap(value) && !isSandboxSet(value) && !isSandboxPromise(value) && !isSandboxRegex(value) && !isSandboxDate(value) && !isFloat32Array(value) && !isSandboxGenerator(value) && !isGuestHostObject(value)) {
|
|
8281
|
+
for (const name of ["toString", "valueOf"]) {
|
|
8282
|
+
const method = getSandboxDataProperty(value, name, budget);
|
|
8283
|
+
if (!isSandboxClosure(method)) continue;
|
|
8284
|
+
const primitive = await invocation.invokeClosure(method, [], value);
|
|
8285
|
+
if (primitive === null || typeof primitive !== "object") {
|
|
8286
|
+
return budget.allocateString(String(primitive));
|
|
8287
|
+
}
|
|
8288
|
+
}
|
|
8289
|
+
throw new TypeError("Cannot convert object to primitive value.");
|
|
8290
|
+
}
|
|
8291
|
+
return sandboxString(value, budget, invocation);
|
|
8292
|
+
}
|
|
8293
|
+
|
|
8160
8294
|
// packages/safe-js/src/interp/exceptions.ts
|
|
8161
8295
|
var capturedExceptionBrand = /* @__PURE__ */ Symbol("CapturedException");
|
|
8162
8296
|
async function evaluateThrowStatement(node, context, evaluateNode2) {
|
|
@@ -8547,12 +8681,13 @@ async function resolvePatternPropertyKey(property, context, evaluateNode2) {
|
|
|
8547
8681
|
result: computedKey
|
|
8548
8682
|
};
|
|
8549
8683
|
}
|
|
8550
|
-
if (typeof computedKey.value !== "string" && typeof computedKey.value !== "number") {
|
|
8551
|
-
throw new TypeError("Computed catch binding keys must evaluate to a string or number.");
|
|
8552
|
-
}
|
|
8553
8684
|
return {
|
|
8554
8685
|
ok: true,
|
|
8555
|
-
value: computedKey.value
|
|
8686
|
+
value: await (context.toPropertyKey?.(computedKey.value) ?? toPropertyKey(
|
|
8687
|
+
computedKey.value,
|
|
8688
|
+
context.budget,
|
|
8689
|
+
{ stack: context.callStack, thisValue: void 0 }
|
|
8690
|
+
))
|
|
8556
8691
|
};
|
|
8557
8692
|
}
|
|
8558
8693
|
function getStaticPropertyKey(property) {
|
|
@@ -23089,17 +23224,17 @@ async function bindMemberExpression(pattern, value, scope, context) {
|
|
|
23089
23224
|
if (object.kind !== "normal") {
|
|
23090
23225
|
return { ok: false, result: object };
|
|
23091
23226
|
}
|
|
23227
|
+
const property = pattern.computed ? await context.evaluate(pattern.property) : { kind: "normal", value: getStaticPropertyName(pattern.property) };
|
|
23228
|
+
if (property.kind !== "normal") {
|
|
23229
|
+
return { ok: false, result: property };
|
|
23230
|
+
}
|
|
23092
23231
|
if (object.value === null || object.value === void 0) {
|
|
23093
23232
|
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
23094
23233
|
}
|
|
23095
23234
|
if (!isIndexableValue(object.value)) {
|
|
23096
23235
|
throw new TypeError("Assignment expressions require a sandbox object property.");
|
|
23097
23236
|
}
|
|
23098
|
-
|
|
23099
|
-
if (!property.ok) {
|
|
23100
|
-
return property;
|
|
23101
|
-
}
|
|
23102
|
-
context.setProperty(object.value, property.value, value);
|
|
23237
|
+
context.setProperty(object.value, await context.toPropertyKey(property.value), value);
|
|
23103
23238
|
return { ok: true };
|
|
23104
23239
|
}
|
|
23105
23240
|
async function evaluatePatternKey(property, context) {
|
|
@@ -23110,10 +23245,7 @@ async function evaluateProperty(property, context) {
|
|
|
23110
23245
|
if (result.kind !== "normal") {
|
|
23111
23246
|
return { ok: false, result };
|
|
23112
23247
|
}
|
|
23113
|
-
|
|
23114
|
-
throw new TypeError("Computed property access requires a string or number key.");
|
|
23115
|
-
}
|
|
23116
|
-
return { ok: true, value: result.value };
|
|
23248
|
+
return { ok: true, value: await context.toPropertyKey(result.value) };
|
|
23117
23249
|
}
|
|
23118
23250
|
function getStaticPropertyName(property) {
|
|
23119
23251
|
if (property.type === "Identifier") {
|
|
@@ -23185,86 +23317,6 @@ function hoistVarDeclarations(node, scope) {
|
|
|
23185
23317
|
}
|
|
23186
23318
|
}
|
|
23187
23319
|
|
|
23188
|
-
// packages/safe-js/src/interp/string-coercion.ts
|
|
23189
|
-
function sandboxString(value, budget, context, joining = /* @__PURE__ */ new Set()) {
|
|
23190
|
-
if (value === null || typeof value !== "object") {
|
|
23191
|
-
if (typeof value === "function") throw new TypeError("Expected a sandbox value.");
|
|
23192
|
-
return budget.allocateString(String(value));
|
|
23193
|
-
}
|
|
23194
|
-
return stringifyObject(value, budget, context, joining);
|
|
23195
|
-
}
|
|
23196
|
-
async function stringifyObject(value, budget, context, joining) {
|
|
23197
|
-
const leaveCall = budget.enterCall();
|
|
23198
|
-
try {
|
|
23199
|
-
budget.visitNode();
|
|
23200
|
-
for (const name of ["toString", "valueOf"]) {
|
|
23201
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
23202
|
-
let result;
|
|
23203
|
-
if (descriptor === void 0) {
|
|
23204
|
-
if (name === "valueOf") continue;
|
|
23205
|
-
result = await defaultToString(value, budget, context, joining);
|
|
23206
|
-
} else {
|
|
23207
|
-
const hook = ownDataValue(value, name);
|
|
23208
|
-
if (!isSandboxClosure(hook)) continue;
|
|
23209
|
-
if (context?.invokeClosure === void 0) {
|
|
23210
|
-
throw new TypeError("String hooks require a sandbox call context.");
|
|
23211
|
-
}
|
|
23212
|
-
result = await context.invokeClosure(hook, [], value);
|
|
23213
|
-
}
|
|
23214
|
-
if (result === null || typeof result !== "object") {
|
|
23215
|
-
return sandboxString(result, budget, context, joining);
|
|
23216
|
-
}
|
|
23217
|
-
}
|
|
23218
|
-
throw new TypeError("Cannot convert object to primitive value");
|
|
23219
|
-
} finally {
|
|
23220
|
-
leaveCall();
|
|
23221
|
-
}
|
|
23222
|
-
}
|
|
23223
|
-
async function defaultToString(value, budget, context, joining) {
|
|
23224
|
-
if (isSandboxDate(value)) return budget.allocateString(dateString(value));
|
|
23225
|
-
if (Array.isArray(value) || isFloat32Array(value)) {
|
|
23226
|
-
if (Object.hasOwn(value, "join")) {
|
|
23227
|
-
const join = ownDataValue(value, "join");
|
|
23228
|
-
if (!isSandboxClosure(join))
|
|
23229
|
-
return isFloat32Array(value) ? "[object Float32Array]" : "[object Array]";
|
|
23230
|
-
if (context?.invokeClosure === void 0) {
|
|
23231
|
-
throw new TypeError("String hooks require a sandbox call context.");
|
|
23232
|
-
}
|
|
23233
|
-
return context.invokeClosure(join, [], value);
|
|
23234
|
-
}
|
|
23235
|
-
if (joining.has(value)) return "";
|
|
23236
|
-
joining.add(value);
|
|
23237
|
-
try {
|
|
23238
|
-
const length = isFloat32Array(value) ? float32Storage(value).length : value.length;
|
|
23239
|
-
let text = "";
|
|
23240
|
-
for (let index = 0; index < length; index++) {
|
|
23241
|
-
budget.visitNode();
|
|
23242
|
-
const element = ownDataValue(value, String(index));
|
|
23243
|
-
const part = element === null || element === void 0 ? "" : await sandboxString(element, budget, context, joining);
|
|
23244
|
-
text = budget.allocateString(text + (index === 0 ? "" : ",") + part);
|
|
23245
|
-
}
|
|
23246
|
-
return text;
|
|
23247
|
-
} finally {
|
|
23248
|
-
joining.delete(value);
|
|
23249
|
-
}
|
|
23250
|
-
}
|
|
23251
|
-
if (sandboxErrorTypes.has(value)) {
|
|
23252
|
-
const nameValue = ownDataValue(value, "name");
|
|
23253
|
-
const name = nameValue === void 0 ? "Error" : await sandboxString(nameValue, budget, context, joining);
|
|
23254
|
-
const messageValue = ownDataValue(value, "message");
|
|
23255
|
-
const message = messageValue === void 0 ? "" : await sandboxString(messageValue, budget, context, joining);
|
|
23256
|
-
return name === "" ? message : message === "" ? name : `${name}: ${message}`;
|
|
23257
|
-
}
|
|
23258
|
-
return isSandboxPromise(value) ? "[object Promise]" : "[object Object]";
|
|
23259
|
-
}
|
|
23260
|
-
function ownDataValue(value, name) {
|
|
23261
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
23262
|
-
if (descriptor !== void 0 && !Object.hasOwn(descriptor, "value")) {
|
|
23263
|
-
throw new TypeError("String conversion requires sandbox data properties.");
|
|
23264
|
-
}
|
|
23265
|
-
return descriptor?.value;
|
|
23266
|
-
}
|
|
23267
|
-
|
|
23268
23320
|
// packages/safe-js/src/interp/methods/array.ts
|
|
23269
23321
|
var activeArrayCallbacks = /* @__PURE__ */ new WeakMap();
|
|
23270
23322
|
var arrayMethodNames = /* @__PURE__ */ new Set([
|
|
@@ -25840,6 +25892,7 @@ async function interpret(node, options = {}) {
|
|
|
25840
25892
|
budget,
|
|
25841
25893
|
callStack: [],
|
|
25842
25894
|
onYield: options.onYield,
|
|
25895
|
+
onSuspend: options.onSuspend,
|
|
25843
25896
|
captureReplayState: options.captureReplayState,
|
|
25844
25897
|
rootNode: node,
|
|
25845
25898
|
scope,
|
|
@@ -26216,7 +26269,7 @@ async function evaluateBinaryExpression(node, context) {
|
|
|
26216
26269
|
if (typeof right.value !== "object" || right.value === null) {
|
|
26217
26270
|
throw new TypeError("Right-hand side of 'in' must be an object.");
|
|
26218
26271
|
}
|
|
26219
|
-
leftValue = await toPropertyKey(leftValue, context);
|
|
26272
|
+
leftValue = await toPropertyKey(leftValue, context.budget, createCoercionContext(context));
|
|
26220
26273
|
}
|
|
26221
26274
|
const value = applyBinaryOperator(node, leftValue, right.value, context);
|
|
26222
26275
|
return {
|
|
@@ -26306,7 +26359,15 @@ async function evaluateMemberAssignmentExpression(node, context) {
|
|
|
26306
26359
|
if (member.kind === "nullish") {
|
|
26307
26360
|
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26308
26361
|
}
|
|
26309
|
-
|
|
26362
|
+
let property;
|
|
26363
|
+
let current = void 0;
|
|
26364
|
+
if (node.operator !== "=") {
|
|
26365
|
+
if (member.object === null || member.object === void 0) {
|
|
26366
|
+
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26367
|
+
}
|
|
26368
|
+
property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
26369
|
+
current = getPropertyValue(member.object, property, context);
|
|
26370
|
+
}
|
|
26310
26371
|
if (node.operator === "&&=" && !isTruthy(current)) {
|
|
26311
26372
|
return {
|
|
26312
26373
|
kind: "normal",
|
|
@@ -26333,7 +26394,11 @@ async function evaluateMemberAssignmentExpression(node, context) {
|
|
|
26333
26394
|
return right;
|
|
26334
26395
|
}
|
|
26335
26396
|
const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : await applyCompoundAssignmentOperator(node.operator, current, right.value, context);
|
|
26336
|
-
|
|
26397
|
+
if (member.object === null || member.object === void 0) {
|
|
26398
|
+
throw new TypeError("Cannot assign properties of null or undefined.");
|
|
26399
|
+
}
|
|
26400
|
+
property ??= await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
26401
|
+
setSandboxProperty(member.object, property, value, context.budget);
|
|
26337
26402
|
return {
|
|
26338
26403
|
kind: "normal",
|
|
26339
26404
|
hasValue: true,
|
|
@@ -27272,7 +27337,10 @@ async function evaluateThrowStatement2(node, context) {
|
|
|
27272
27337
|
return evaluateThrowStatement(node, context, evaluateNode);
|
|
27273
27338
|
}
|
|
27274
27339
|
async function evaluateTryStatement2(node, context) {
|
|
27275
|
-
return evaluateTryStatement(node,
|
|
27340
|
+
return evaluateTryStatement(node, {
|
|
27341
|
+
...context,
|
|
27342
|
+
toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(context))
|
|
27343
|
+
}, evaluateNode);
|
|
27276
27344
|
}
|
|
27277
27345
|
async function evaluateUnaryExpression(node, context) {
|
|
27278
27346
|
if (node.operator === "delete") {
|
|
@@ -27317,8 +27385,8 @@ async function evaluateDeleteExpression(node, context) {
|
|
|
27317
27385
|
if (member.kind === "completion") {
|
|
27318
27386
|
return member.result;
|
|
27319
27387
|
}
|
|
27320
|
-
if (member.kind === "nullish") {
|
|
27321
|
-
if (node.argument.optional) {
|
|
27388
|
+
if (member.kind === "nullish" || member.object === null || member.object === void 0) {
|
|
27389
|
+
if (member.kind === "nullish" && node.argument.optional) {
|
|
27322
27390
|
return {
|
|
27323
27391
|
kind: "normal",
|
|
27324
27392
|
hasValue: true,
|
|
@@ -27330,7 +27398,8 @@ async function evaluateDeleteExpression(node, context) {
|
|
|
27330
27398
|
if (!isIndexableSandboxValue(member.object)) {
|
|
27331
27399
|
throw new TypeError("Unary operator 'delete' requires a sandbox object property.");
|
|
27332
27400
|
}
|
|
27333
|
-
const
|
|
27401
|
+
const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
27402
|
+
const deleted = deleteSandboxProperty(member.object, property);
|
|
27334
27403
|
return {
|
|
27335
27404
|
kind: "normal",
|
|
27336
27405
|
hasValue: true,
|
|
@@ -27378,14 +27447,15 @@ async function evaluateMemberUpdateExpression(node, context) {
|
|
|
27378
27447
|
if (member.kind === "completion") {
|
|
27379
27448
|
return member.result;
|
|
27380
27449
|
}
|
|
27381
|
-
if (member.kind === "nullish") {
|
|
27450
|
+
if (member.kind === "nullish" || member.object === null || member.object === void 0) {
|
|
27382
27451
|
throw new TypeError("Cannot update properties of null or undefined.");
|
|
27383
27452
|
}
|
|
27453
|
+
const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
|
|
27384
27454
|
const current = toNumber(
|
|
27385
|
-
await toNumericPrimitive(getPropertyValue(member.object,
|
|
27455
|
+
await toNumericPrimitive(getPropertyValue(member.object, property, context), context)
|
|
27386
27456
|
);
|
|
27387
27457
|
const next = node.operator === "++" ? current + 1 : current - 1;
|
|
27388
|
-
setSandboxProperty(member.object,
|
|
27458
|
+
setSandboxProperty(member.object, property, next, context.budget);
|
|
27389
27459
|
return {
|
|
27390
27460
|
kind: "normal",
|
|
27391
27461
|
hasValue: true,
|
|
@@ -27396,14 +27466,14 @@ async function evaluateMemberExpression(node, context) {
|
|
|
27396
27466
|
const member = await evaluateMemberAccess(node, context);
|
|
27397
27467
|
if (member.kind === "error") return member;
|
|
27398
27468
|
if (member.kind === "completion") return member.result;
|
|
27399
|
-
if (member.kind === "nullish") {
|
|
27400
|
-
if (node.optional) return { kind: "normal", hasValue: true, value: void 0 };
|
|
27469
|
+
if (member.kind === "nullish" || member.object === null || member.object === void 0) {
|
|
27470
|
+
if (member.kind === "nullish" && node.optional) return { kind: "normal", hasValue: true, value: void 0 };
|
|
27401
27471
|
throw new TypeError("Cannot read properties of null or undefined.");
|
|
27402
27472
|
}
|
|
27403
27473
|
return {
|
|
27404
27474
|
kind: "normal",
|
|
27405
27475
|
hasValue: true,
|
|
27406
|
-
value: getPropertyValue(member.object, member.property, context)
|
|
27476
|
+
value: getPropertyValue(member.object, await toPropertyKey(member.property, context.budget, createCoercionContext(context)), context)
|
|
27407
27477
|
};
|
|
27408
27478
|
}
|
|
27409
27479
|
function getPropertyValue(target, property, context) {
|
|
@@ -27428,6 +27498,7 @@ function createPatternContext(context, scope = context.scope, evaluate = evaluat
|
|
|
27428
27498
|
const evaluationContext = { ...context, scope };
|
|
27429
27499
|
return {
|
|
27430
27500
|
evaluate: (node) => evaluate(node, evaluationContext),
|
|
27501
|
+
toPropertyKey: (value) => toPropertyKey(value, context.budget, createCoercionContext(evaluationContext)),
|
|
27431
27502
|
getProperty: (value, key) => getPropertyValue(value, key, evaluationContext),
|
|
27432
27503
|
setProperty: (target, key, value) => setSandboxProperty(target, key, value, context.budget)
|
|
27433
27504
|
};
|
|
@@ -27522,21 +27593,8 @@ async function evaluateMemberAccess(node, context) {
|
|
|
27522
27593
|
kind: "nullish"
|
|
27523
27594
|
};
|
|
27524
27595
|
}
|
|
27525
|
-
const property = node.computed ? await
|
|
27526
|
-
if (
|
|
27527
|
-
return property.result.kind === "error" ? {
|
|
27528
|
-
kind: "error",
|
|
27529
|
-
error: property.result.error
|
|
27530
|
-
} : {
|
|
27531
|
-
kind: "completion",
|
|
27532
|
-
result: property.result
|
|
27533
|
-
};
|
|
27534
|
-
}
|
|
27535
|
-
if (object.value === null || object.value === void 0) {
|
|
27536
|
-
return {
|
|
27537
|
-
kind: "nullish"
|
|
27538
|
-
};
|
|
27539
|
-
}
|
|
27596
|
+
const property = node.computed ? await evaluateNode(node.property, context) : { kind: "normal", value: getStaticPropertyName2(node.property) };
|
|
27597
|
+
if (property.kind !== "normal") return { kind: "completion", result: property };
|
|
27540
27598
|
return {
|
|
27541
27599
|
kind: "resolved",
|
|
27542
27600
|
object: object.value,
|
|
@@ -27551,13 +27609,10 @@ async function evaluateMemberProperty(node, context) {
|
|
|
27551
27609
|
result: property
|
|
27552
27610
|
};
|
|
27553
27611
|
}
|
|
27554
|
-
|
|
27555
|
-
|
|
27556
|
-
|
|
27557
|
-
|
|
27558
|
-
};
|
|
27559
|
-
}
|
|
27560
|
-
throw new TypeError("Computed property access requires a string or number key.");
|
|
27612
|
+
return {
|
|
27613
|
+
ok: true,
|
|
27614
|
+
value: await toPropertyKey(property.value, context.budget, createCoercionContext(context))
|
|
27615
|
+
};
|
|
27561
27616
|
}
|
|
27562
27617
|
async function evaluateObjectPropertyKey(node, context) {
|
|
27563
27618
|
if (!node.computed) {
|
|
@@ -27581,15 +27636,15 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
27581
27636
|
if (node.callee.type !== "MemberExpression") {
|
|
27582
27637
|
throw new TypeError("Expected member call expression.");
|
|
27583
27638
|
}
|
|
27584
|
-
const
|
|
27585
|
-
if (
|
|
27586
|
-
return
|
|
27639
|
+
const reference = await evaluateMemberAccess(node.callee, context);
|
|
27640
|
+
if (reference.kind === "error") {
|
|
27641
|
+
return reference;
|
|
27587
27642
|
}
|
|
27588
|
-
if (
|
|
27589
|
-
return
|
|
27643
|
+
if (reference.kind === "completion") {
|
|
27644
|
+
return reference.result;
|
|
27590
27645
|
}
|
|
27591
|
-
if (
|
|
27592
|
-
if (
|
|
27646
|
+
if (reference.kind === "nullish" || reference.object === null || reference.object === void 0) {
|
|
27647
|
+
if (reference.kind === "nullish") {
|
|
27593
27648
|
return {
|
|
27594
27649
|
kind: "normal",
|
|
27595
27650
|
hasValue: true,
|
|
@@ -27598,6 +27653,10 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
27598
27653
|
}
|
|
27599
27654
|
throw new TypeError("Cannot read properties of null or undefined.");
|
|
27600
27655
|
}
|
|
27656
|
+
const member = {
|
|
27657
|
+
...reference,
|
|
27658
|
+
property: await toPropertyKey(reference.property, context.budget, createCoercionContext(context))
|
|
27659
|
+
};
|
|
27601
27660
|
if (typeof member.object === "string" && isStringMethodName(member.property)) {
|
|
27602
27661
|
return evaluateStringMethodCall(node, member.object, member.property, context);
|
|
27603
27662
|
}
|
|
@@ -27929,23 +27988,13 @@ function applyBinaryOperator(node, left, right, context) {
|
|
|
27929
27988
|
return hasSandboxProperty(right, left, context);
|
|
27930
27989
|
}
|
|
27931
27990
|
}
|
|
27932
|
-
|
|
27933
|
-
|
|
27934
|
-
for (const name of ["toString", "valueOf"]) {
|
|
27935
|
-
const method = getMemberValue(value, name, context);
|
|
27936
|
-
if (!isSandboxClosure(method)) continue;
|
|
27937
|
-
const primitive = await invokeSandboxClosure(method, [], context, context.callStack, void 0, value);
|
|
27938
|
-
if (primitive === null || typeof primitive !== "object") {
|
|
27939
|
-
return context.budget.allocateString(String(primitive));
|
|
27940
|
-
}
|
|
27941
|
-
}
|
|
27942
|
-
throw new TypeError("Cannot convert object to primitive value.");
|
|
27943
|
-
}
|
|
27944
|
-
return sandboxString(value, context.budget, {
|
|
27991
|
+
function createCoercionContext(context) {
|
|
27992
|
+
return {
|
|
27945
27993
|
stack: context.callStack,
|
|
27946
27994
|
thisValue: void 0,
|
|
27995
|
+
compilation: context.compilation,
|
|
27947
27996
|
invokeClosure: (closure, args, thisValue) => invokeSandboxClosure(closure, args, context, context.callStack, void 0, thisValue)
|
|
27948
|
-
}
|
|
27997
|
+
};
|
|
27949
27998
|
}
|
|
27950
27999
|
function hasSandboxProperty(value, key, context) {
|
|
27951
28000
|
let current = value;
|
|
@@ -28559,44 +28608,51 @@ function createInterpretedClosure(node, context, evaluateNode2) {
|
|
|
28559
28608
|
};
|
|
28560
28609
|
if (!node.async)
|
|
28561
28610
|
return executeClosure(node, args, callContext?.thisValue, invocationContext, evaluateNode2);
|
|
28562
|
-
|
|
28563
|
-
|
|
28564
|
-
|
|
28565
|
-
|
|
28566
|
-
|
|
28567
|
-
|
|
28568
|
-
|
|
28569
|
-
|
|
28570
|
-
|
|
28571
|
-
|
|
28572
|
-
|
|
28573
|
-
{ ...invocationContext, onSuspend: completePrefix },
|
|
28574
|
-
evaluateNode2
|
|
28575
|
-
);
|
|
28576
|
-
resolve(
|
|
28577
|
-
isSandboxPromise(value) || getThenable(value) !== void 0 ? awaitSandboxValue(
|
|
28578
|
-
createSandboxPromise(resolveSandboxValue(value, { budget: context.budget }), {
|
|
28579
|
-
trackReplay: false
|
|
28580
|
-
}),
|
|
28581
|
-
context.signal,
|
|
28582
|
-
context.budget
|
|
28583
|
-
) : allocateProducedSandboxValue(value, context.budget)
|
|
28584
|
-
);
|
|
28585
|
-
} catch (error) {
|
|
28586
|
-
reject(error);
|
|
28587
|
-
} finally {
|
|
28588
|
-
completePrefix();
|
|
28589
|
-
}
|
|
28590
|
-
}).catch((error) => {
|
|
28591
|
-
reject(error);
|
|
28592
|
-
completePrefix();
|
|
28593
|
-
});
|
|
28594
|
-
});
|
|
28595
|
-
return createSandboxPromise(promise, { synchronousPrefix });
|
|
28611
|
+
return executeAsyncFunction(
|
|
28612
|
+
(onSuspend) => executeClosure(
|
|
28613
|
+
node,
|
|
28614
|
+
args,
|
|
28615
|
+
callContext?.thisValue,
|
|
28616
|
+
{ ...invocationContext, onSuspend },
|
|
28617
|
+
evaluateNode2
|
|
28618
|
+
),
|
|
28619
|
+
context.budget,
|
|
28620
|
+
context.signal
|
|
28621
|
+
);
|
|
28596
28622
|
}
|
|
28597
28623
|
});
|
|
28598
28624
|
return closure;
|
|
28599
28625
|
}
|
|
28626
|
+
function executeAsyncFunction(execute, budget, signal) {
|
|
28627
|
+
let completePrefix;
|
|
28628
|
+
const synchronousPrefix = new Promise((resolve) => {
|
|
28629
|
+
completePrefix = resolve;
|
|
28630
|
+
});
|
|
28631
|
+
const promise = new Promise((resolve, reject) => {
|
|
28632
|
+
runAsyncPrefix(async () => {
|
|
28633
|
+
try {
|
|
28634
|
+
const value = await execute(completePrefix);
|
|
28635
|
+
resolve(
|
|
28636
|
+
isSandboxPromise(value) || getThenable(value) !== void 0 ? awaitSandboxValue(
|
|
28637
|
+
createSandboxPromise(resolveSandboxValue(value, { budget }), {
|
|
28638
|
+
trackReplay: false
|
|
28639
|
+
}),
|
|
28640
|
+
signal,
|
|
28641
|
+
budget
|
|
28642
|
+
) : allocateProducedSandboxValue(value, budget)
|
|
28643
|
+
);
|
|
28644
|
+
} catch (error) {
|
|
28645
|
+
reject(error);
|
|
28646
|
+
} finally {
|
|
28647
|
+
completePrefix();
|
|
28648
|
+
}
|
|
28649
|
+
}).catch((error) => {
|
|
28650
|
+
reject(error);
|
|
28651
|
+
completePrefix();
|
|
28652
|
+
});
|
|
28653
|
+
});
|
|
28654
|
+
return createSandboxPromise(promise, { synchronousPrefix });
|
|
28655
|
+
}
|
|
28600
28656
|
function createGeneratorClosure(node, context, evaluateNode2) {
|
|
28601
28657
|
return createSandboxClosure({
|
|
28602
28658
|
guest: true,
|
|
@@ -32810,4 +32866,4 @@ export {
|
|
|
32810
32866
|
FileSnapshotBackend,
|
|
32811
32867
|
run
|
|
32812
32868
|
};
|
|
32813
|
-
//# sourceMappingURL=chunk-
|
|
32869
|
+
//# sourceMappingURL=chunk-M4M56OCI.js.map
|