poe-code 14.0.6 → 14.0.7
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 +454 -39
- 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-2M6MNQBY.js → chunk-BWVASPJX.js} +420 -33
- package/packages/safe-js/dist/chunks/chunk-BWVASPJX.js.map +7 -0
- package/packages/safe-js/dist/chunks/{chunk-QSSQJNKE.js → chunk-ETKM3KPA.js} +2 -2
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.d.ts +1 -1
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/extensions.d.ts +2 -0
- package/packages/safe-js/dist/index.d.ts +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/index.js.map +1 -1
- package/packages/safe-js/dist/interp/date.d.ts +19 -0
- package/packages/safe-js/dist/interp/date.js +129 -0
- package/packages/safe-js/dist/interp/globals/console-json.js +5 -1
- package/packages/safe-js/dist/interp/globals/date.d.ts +10 -0
- package/packages/safe-js/dist/interp/globals/date.js +95 -0
- package/packages/safe-js/dist/interp/globals/object-array.d.ts +2 -1
- package/packages/safe-js/dist/interp/globals/object-array.js +10 -1
- package/packages/safe-js/dist/interp/globals.d.ts +3 -0
- package/packages/safe-js/dist/interp/globals.js +2 -0
- package/packages/safe-js/dist/interp/host-bridge.d.ts +4 -0
- package/packages/safe-js/dist/interp/host-bridge.js +21 -2
- package/packages/safe-js/dist/interp/host-call.js +4 -0
- package/packages/safe-js/dist/interp/host-capabilities.d.ts +7 -0
- package/packages/safe-js/dist/interp/host-capabilities.js +29 -1
- package/packages/safe-js/dist/interp/interpreter.js +19 -2
- package/packages/safe-js/dist/interp/string-coercion.js +3 -0
- package/packages/safe-js/dist/interp/values.d.ts +1 -1
- package/packages/safe-js/dist/interp/values.js +21 -0
- package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
- package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
- package/packages/safe-js/dist/parse/parser.js +4 -2
- package/packages/safe-js/dist/realm.d.ts +4 -1
- package/packages/safe-js/dist/realm.js +74 -8
- package/packages/safe-js/dist/run.d.ts +2 -0
- package/packages/safe-js/dist/run.js +1 -1
- package/packages/safe-js/dist/snapshot/dump-format.js +8 -3
- package/packages/safe-js/dist/snapshot/replay-data.d.ts +4 -1
- package/packages/safe-js/dist/snapshot/replay-data.js +11 -0
- package/packages/safe-js/dist/snapshot/restore.js +6 -0
- package/packages/safe-js/dist/snapshot/serialize.d.ts +5 -2
- package/packages/safe-js/dist/snapshot/serialize.js +8 -2
- package/packages/safe-js/dist/snapshot/validation.js +18 -1
- package/packages/safe-js/dist/chunks/chunk-2M6MNQBY.js.map +0 -7
- /package/packages/safe-js/dist/chunks/{chunk-QSSQJNKE.js.map → chunk-ETKM3KPA.js.map} +0 -0
|
@@ -4263,8 +4263,9 @@ var Parser = class {
|
|
|
4263
4263
|
}
|
|
4264
4264
|
break;
|
|
4265
4265
|
}
|
|
4266
|
-
this.
|
|
4267
|
-
|
|
4266
|
+
const optional = this.consumePunctuator("?.");
|
|
4267
|
+
if (optional !== void 0) throw new DisallowedSyntaxError("new optional chain", optional.start);
|
|
4268
|
+
const args = this.consumePunctuator("(") === void 0 ? [] : this.parseArguments();
|
|
4268
4269
|
const end = this.previousToken();
|
|
4269
4270
|
return {
|
|
4270
4271
|
node: {
|
|
@@ -6207,10 +6208,151 @@ function copyFloat32Storage(value, state) {
|
|
|
6207
6208
|
return new Float32Array(buffer, storage.byteOffset, storage.length);
|
|
6208
6209
|
}
|
|
6209
6210
|
|
|
6211
|
+
// packages/safe-js/src/interp/date.ts
|
|
6212
|
+
import { types as types2 } from "node:util";
|
|
6213
|
+
var NativeDate = Date;
|
|
6214
|
+
var readTime = NativeDate.prototype.getTime;
|
|
6215
|
+
var writeTime = NativeDate.prototype.setTime;
|
|
6216
|
+
var dates = /* @__PURE__ */ new WeakSet();
|
|
6217
|
+
function isSandboxDate(value) {
|
|
6218
|
+
return typeof value === "object" && value !== null && dates.has(value);
|
|
6219
|
+
}
|
|
6220
|
+
function createSandboxDate(time) {
|
|
6221
|
+
const value = new NativeDate(time);
|
|
6222
|
+
dates.add(value);
|
|
6223
|
+
return Object.freeze(value);
|
|
6224
|
+
}
|
|
6225
|
+
function dateTime(value) {
|
|
6226
|
+
return Reflect.apply(readTime, value, []);
|
|
6227
|
+
}
|
|
6228
|
+
function copyNativeDate(value) {
|
|
6229
|
+
if (!types2.isDate(value)) return void 0;
|
|
6230
|
+
if (Object.getPrototypeOf(value) !== NativeDate.prototype || Reflect.ownKeys(value).length > 0)
|
|
6231
|
+
throw new TypeError("Date subclasses and own properties are not supported.");
|
|
6232
|
+
return createSandboxDate(dateTime(value));
|
|
6233
|
+
}
|
|
6234
|
+
function exportDate(value) {
|
|
6235
|
+
return new NativeDate(dateTime(value));
|
|
6236
|
+
}
|
|
6237
|
+
function dateNumber(value) {
|
|
6238
|
+
if (isSandboxDate(value)) return dateTime(value);
|
|
6239
|
+
if (typeof value === "object" && value !== null || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint")
|
|
6240
|
+
throw new TypeError("Date arguments require primitive values; custom coercion is unsupported.");
|
|
6241
|
+
return Number(value);
|
|
6242
|
+
}
|
|
6243
|
+
function parseDate(value, budget) {
|
|
6244
|
+
if (typeof value === "object" && value !== null || typeof value === "function")
|
|
6245
|
+
throw new TypeError("Date parsing requires a primitive value.");
|
|
6246
|
+
const text = String(value);
|
|
6247
|
+
if (text.length > 4096) throw new RangeError("Date input exceeds the 4096 character limit.");
|
|
6248
|
+
budget.allocateString(text);
|
|
6249
|
+
for (let index = 0; index < text.length; index++) budget.visitNode();
|
|
6250
|
+
return NativeDate.parse(text);
|
|
6251
|
+
}
|
|
6252
|
+
function dateFromParts(args, utc) {
|
|
6253
|
+
const parts = args.slice(0, 7).map(dateNumber);
|
|
6254
|
+
return utc ? Reflect.apply(NativeDate.UTC, NativeDate, parts) : dateTime(Reflect.construct(NativeDate, parts));
|
|
6255
|
+
}
|
|
6256
|
+
var methodNames = [
|
|
6257
|
+
"getTime",
|
|
6258
|
+
"valueOf",
|
|
6259
|
+
"getDate",
|
|
6260
|
+
"getDay",
|
|
6261
|
+
"getFullYear",
|
|
6262
|
+
"getHours",
|
|
6263
|
+
"getMilliseconds",
|
|
6264
|
+
"getMinutes",
|
|
6265
|
+
"getMonth",
|
|
6266
|
+
"getSeconds",
|
|
6267
|
+
"getTimezoneOffset",
|
|
6268
|
+
"getUTCDate",
|
|
6269
|
+
"getUTCDay",
|
|
6270
|
+
"getUTCFullYear",
|
|
6271
|
+
"getUTCHours",
|
|
6272
|
+
"getUTCMilliseconds",
|
|
6273
|
+
"getUTCMinutes",
|
|
6274
|
+
"getUTCMonth",
|
|
6275
|
+
"getUTCSeconds",
|
|
6276
|
+
"setTime",
|
|
6277
|
+
"setDate",
|
|
6278
|
+
"setFullYear",
|
|
6279
|
+
"setHours",
|
|
6280
|
+
"setMilliseconds",
|
|
6281
|
+
"setMinutes",
|
|
6282
|
+
"setMonth",
|
|
6283
|
+
"setSeconds",
|
|
6284
|
+
"setUTCDate",
|
|
6285
|
+
"setUTCFullYear",
|
|
6286
|
+
"setUTCHours",
|
|
6287
|
+
"setUTCMilliseconds",
|
|
6288
|
+
"setUTCMinutes",
|
|
6289
|
+
"setUTCMonth",
|
|
6290
|
+
"setUTCSeconds",
|
|
6291
|
+
"toDateString",
|
|
6292
|
+
"toISOString",
|
|
6293
|
+
"toString",
|
|
6294
|
+
"toTimeString",
|
|
6295
|
+
"toUTCString",
|
|
6296
|
+
"toJSON"
|
|
6297
|
+
];
|
|
6298
|
+
var dateMethods = new Map(
|
|
6299
|
+
methodNames.map((name) => {
|
|
6300
|
+
const native = NativeDate.prototype[name];
|
|
6301
|
+
return [
|
|
6302
|
+
name,
|
|
6303
|
+
{
|
|
6304
|
+
length: native.length,
|
|
6305
|
+
invoke: (date, args) => {
|
|
6306
|
+
if (name === "toJSON")
|
|
6307
|
+
return Number.isNaN(dateTime(date)) ? null : Reflect.apply(NativeDate.prototype.toISOString, date, []);
|
|
6308
|
+
return Reflect.apply(
|
|
6309
|
+
native,
|
|
6310
|
+
date,
|
|
6311
|
+
name.startsWith("set") ? args.slice(0, native.length).map(dateNumber) : []
|
|
6312
|
+
);
|
|
6313
|
+
}
|
|
6314
|
+
}
|
|
6315
|
+
];
|
|
6316
|
+
})
|
|
6317
|
+
);
|
|
6318
|
+
function dateString(value) {
|
|
6319
|
+
return dateMethods.get("toString").invoke(value, []);
|
|
6320
|
+
}
|
|
6321
|
+
function restoreDateTime(value) {
|
|
6322
|
+
if (value !== null && (typeof value !== "number" || !Number.isInteger(value) || Math.abs(value) > 864e13 || Object.is(value, -0)))
|
|
6323
|
+
throw new TypeError("Invalid serialized Date epoch.");
|
|
6324
|
+
const date = createSandboxDate(0);
|
|
6325
|
+
Reflect.apply(writeTime, date, [value === null ? NaN : value]);
|
|
6326
|
+
return date;
|
|
6327
|
+
}
|
|
6328
|
+
function serializedDateTime(value) {
|
|
6329
|
+
const time = dateTime(value);
|
|
6330
|
+
return Number.isNaN(time) ? null : time;
|
|
6331
|
+
}
|
|
6332
|
+
|
|
6210
6333
|
// packages/safe-js/src/interp/host-capabilities.ts
|
|
6211
6334
|
var hostObjects = /* @__PURE__ */ new WeakMap();
|
|
6212
6335
|
var guestObjects = /* @__PURE__ */ new WeakMap();
|
|
6213
6336
|
var guestCallbacks = /* @__PURE__ */ new WeakMap();
|
|
6337
|
+
var guestReferences = /* @__PURE__ */ new WeakMap();
|
|
6338
|
+
function createGuestReference(root, owner, assertActive) {
|
|
6339
|
+
const reference = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
6340
|
+
guestReferences.set(reference, { root, owner, assertActive });
|
|
6341
|
+
return reference;
|
|
6342
|
+
}
|
|
6343
|
+
function readGuestReference(reference, owner) {
|
|
6344
|
+
const state = typeof reference === "object" && reference !== null ? guestReferences.get(reference) : void 0;
|
|
6345
|
+
if (state === void 0 || state.owner !== owner)
|
|
6346
|
+
throw new TypeError("Foreign or invalid guest reference.");
|
|
6347
|
+
state.assertActive();
|
|
6348
|
+
if (state.root === void 0) throw new TypeError("Guest reference is revoked.");
|
|
6349
|
+
return state.root[0];
|
|
6350
|
+
}
|
|
6351
|
+
function revokeGuestReference(reference, owner) {
|
|
6352
|
+
const state = guestReferences.get(reference);
|
|
6353
|
+
if (state === void 0 || state.owner !== owner) throw new TypeError("Foreign guest reference.");
|
|
6354
|
+
state.root = void 0;
|
|
6355
|
+
}
|
|
6214
6356
|
function createLiveHostObject(definition, controller) {
|
|
6215
6357
|
const input = readDataRecord(definition, "Host object definition");
|
|
6216
6358
|
if (Object.keys(input).some((key) => key !== "properties" && key !== "methods"))
|
|
@@ -6254,9 +6396,10 @@ function isGuestHostObject(value) {
|
|
|
6254
6396
|
return typeof value === "object" && value !== null && guestObjects.has(value);
|
|
6255
6397
|
}
|
|
6256
6398
|
function isLiveCapability(value) {
|
|
6257
|
-
return (typeof value === "object" && value !== null || typeof value === "function") && (hostObjects.has(value) || guestObjects.has(value) || guestCallbacks.has(value));
|
|
6399
|
+
return (typeof value === "object" && value !== null || typeof value === "function") && (hostObjects.has(value) || guestObjects.has(value) || guestCallbacks.has(value) || guestReferences.has(value));
|
|
6258
6400
|
}
|
|
6259
6401
|
function importHostCapability(value, owner) {
|
|
6402
|
+
if (guestReferences.has(value)) return readGuestReference(value, owner);
|
|
6260
6403
|
const object = hostObjects.get(value);
|
|
6261
6404
|
if (object !== void 0) {
|
|
6262
6405
|
if (object.controller.owner !== owner) throw new TypeError("Foreign realm host capability.");
|
|
@@ -6445,7 +6588,7 @@ async function flushPromiseJobs() {
|
|
|
6445
6588
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
6446
6589
|
|
|
6447
6590
|
// packages/safe-js/src/snapshot/validation.ts
|
|
6448
|
-
import { types as
|
|
6591
|
+
import { types as types3 } from "node:util";
|
|
6449
6592
|
|
|
6450
6593
|
// packages/safe-js/src/interp/arguments.ts
|
|
6451
6594
|
var sandboxArgumentsBrand = /* @__PURE__ */ Symbol("SandboxArguments");
|
|
@@ -6821,7 +6964,7 @@ function serializeDumpValue(value, path, state) {
|
|
|
6821
6964
|
if (hasGuestObjectState(value)) {
|
|
6822
6965
|
throw new TypeError("Guest function properties and prototype links cannot be serialized.");
|
|
6823
6966
|
}
|
|
6824
|
-
if (isFloat32Array(value)) return serializeHeapReference(value, path, state);
|
|
6967
|
+
if (isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
|
|
6825
6968
|
if (Array.isArray(value)) {
|
|
6826
6969
|
const reference2 = serializeHeapReference(value, path, state);
|
|
6827
6970
|
if (reference2 !== void 0) {
|
|
@@ -6845,7 +6988,9 @@ function serializeHeapReference(value, path, state) {
|
|
|
6845
6988
|
}
|
|
6846
6989
|
if (!state.serializedHeapIds.has(id)) {
|
|
6847
6990
|
state.serializedHeapIds.add(id);
|
|
6848
|
-
if (
|
|
6991
|
+
if (isSandboxDate(value)) {
|
|
6992
|
+
state.heap[String(id)] = { kind: "date", time: serializedDateTime(value) };
|
|
6993
|
+
} else if (isFloat32Array(value)) {
|
|
6849
6994
|
const storage = encodeFloat32Storage(value, id, state.float32Buffers, (id2) => ({
|
|
6850
6995
|
kind: "ref",
|
|
6851
6996
|
id: id2
|
|
@@ -6902,7 +7047,7 @@ function indexHeapContainers(snapshot) {
|
|
|
6902
7047
|
const heapIds = /* @__PURE__ */ new WeakMap();
|
|
6903
7048
|
let nextId = 1;
|
|
6904
7049
|
for (const [value, stat2] of stats.entries()) {
|
|
6905
|
-
if (stat2.count > 1 || stat2.cyclic || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
7050
|
+
if (stat2.count > 1 || stat2.cyclic || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
6906
7051
|
heapIds.set(value, nextId);
|
|
6907
7052
|
nextId += 1;
|
|
6908
7053
|
}
|
|
@@ -6913,7 +7058,7 @@ function collectContainerStats(value, stats, ancestors) {
|
|
|
6913
7058
|
if (value === null || typeof value !== "object") {
|
|
6914
7059
|
return;
|
|
6915
7060
|
}
|
|
6916
|
-
if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value)) {
|
|
7061
|
+
if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
|
|
6917
7062
|
return;
|
|
6918
7063
|
}
|
|
6919
7064
|
let stat2 = stats.get(value);
|
|
@@ -7049,6 +7194,10 @@ function validateDumpHeap(root, state) {
|
|
|
7049
7194
|
addUnique(heapIds, id, path);
|
|
7050
7195
|
const entry = requireRecord(value, path);
|
|
7051
7196
|
validateErrorType(entry, path);
|
|
7197
|
+
if (entry.kind === "date") {
|
|
7198
|
+
validateDateRecord(entry, path);
|
|
7199
|
+
continue;
|
|
7200
|
+
}
|
|
7052
7201
|
if (entry.kind === "float32array") {
|
|
7053
7202
|
validateFloat32Storage(entry);
|
|
7054
7203
|
requireRecord(entry.entries, `${path}.entries`);
|
|
@@ -7206,6 +7355,14 @@ function validateGeneratorShape(record2, path, state) {
|
|
|
7206
7355
|
}
|
|
7207
7356
|
});
|
|
7208
7357
|
}
|
|
7358
|
+
function validateDateRecord(record2, path) {
|
|
7359
|
+
if (Object.keys(record2).length !== 2) fail("invalidValue", path, "invalid Date fields");
|
|
7360
|
+
try {
|
|
7361
|
+
restoreDateTime(record2.time);
|
|
7362
|
+
} catch {
|
|
7363
|
+
fail("invalidValue", `${path}.time`, "invalid Date epoch");
|
|
7364
|
+
}
|
|
7365
|
+
}
|
|
7209
7366
|
function validateArrayHeap(record2, path, state) {
|
|
7210
7367
|
if (Object.hasOwn(record2, "items")) {
|
|
7211
7368
|
requireArray(record2.items, `${path}.items`, state);
|
|
@@ -7289,7 +7446,7 @@ function validateGenericValue(value, path, depth, state) {
|
|
|
7289
7446
|
if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
|
|
7290
7447
|
fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
|
|
7291
7448
|
}
|
|
7292
|
-
if (state.dataPropertiesOnly &&
|
|
7449
|
+
if (state.dataPropertiesOnly && types3.isProxy(value)) {
|
|
7293
7450
|
fail("invalidType", path, "proxy objects are not snapshot data");
|
|
7294
7451
|
}
|
|
7295
7452
|
if (depth > state.limits.maxDepth)
|
|
@@ -9532,6 +9689,10 @@ function measureSandboxData(values, options = {}) {
|
|
|
9532
9689
|
assertSandboxDataDepth(depth);
|
|
9533
9690
|
seen.add(value);
|
|
9534
9691
|
usage += 1;
|
|
9692
|
+
if (isSandboxDate(value)) {
|
|
9693
|
+
usage += 8;
|
|
9694
|
+
return;
|
|
9695
|
+
}
|
|
9535
9696
|
if (isGuestHostObject(value)) {
|
|
9536
9697
|
for (const key of getHostObjectKeys(value)) usage += key.length + 1;
|
|
9537
9698
|
return;
|
|
@@ -9726,6 +9887,13 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
|
|
|
9726
9887
|
}
|
|
9727
9888
|
return sandboxPromise;
|
|
9728
9889
|
}
|
|
9890
|
+
if (nodeTypes.isDate(value)) {
|
|
9891
|
+
const existing = state.seen.get(value);
|
|
9892
|
+
if (existing !== void 0) return existing;
|
|
9893
|
+
const copy = copyNativeDate(value);
|
|
9894
|
+
state.seen.set(value, copy);
|
|
9895
|
+
return copy;
|
|
9896
|
+
}
|
|
9729
9897
|
if (isFloat32Array(value)) {
|
|
9730
9898
|
const existing = state.seen.get(value);
|
|
9731
9899
|
if (existing !== void 0) return existing;
|
|
@@ -9885,6 +10053,13 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
9885
10053
|
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
9886
10054
|
return copy;
|
|
9887
10055
|
}
|
|
10056
|
+
if (isSandboxDate(value)) {
|
|
10057
|
+
const existing = state.seen.get(value);
|
|
10058
|
+
if (existing !== void 0) return existing;
|
|
10059
|
+
const copy = exportDate(value);
|
|
10060
|
+
state.seen.set(value, copy);
|
|
10061
|
+
return copy;
|
|
10062
|
+
}
|
|
9888
10063
|
if (isSandboxClosure(value)) {
|
|
9889
10064
|
if (options.wrapClosure === void 0) {
|
|
9890
10065
|
throw new TypeError(
|
|
@@ -10199,6 +10374,8 @@ function encodeReplayData(value, options = {}) {
|
|
|
10199
10374
|
id: capabilityId,
|
|
10200
10375
|
properties: child(entry.properties, "properties")
|
|
10201
10376
|
};
|
|
10377
|
+
} else if (isSandboxDate(entry)) {
|
|
10378
|
+
nodes[id] = { kind: "date", time: serializedDateTime(entry) };
|
|
10202
10379
|
} else if (isFloat32Array(entry)) {
|
|
10203
10380
|
const storage = encodeFloat32Storage(entry, id, float32Buffers, (id2) => ({
|
|
10204
10381
|
tag: "ref",
|
|
@@ -10349,6 +10526,12 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
10349
10526
|
options.onCapabilityRestored?.(capability, copy);
|
|
10350
10527
|
return copy;
|
|
10351
10528
|
}
|
|
10529
|
+
if (kind === "date") {
|
|
10530
|
+
if (Object.keys(node).length !== 2) throw new TypeError("Invalid serialized Date fields.");
|
|
10531
|
+
const result3 = restoreDateTime(own(node, "time"));
|
|
10532
|
+
restored.set(id, result3);
|
|
10533
|
+
return result3;
|
|
10534
|
+
}
|
|
10352
10535
|
if (kind === "float32array") {
|
|
10353
10536
|
if (typeof node.extensible !== "boolean")
|
|
10354
10537
|
throw new TypeError("Invalid Float32Array extensibility.");
|
|
@@ -11039,6 +11222,8 @@ function normalize(value, seen) {
|
|
|
11039
11222
|
if (seen.has(value)) throw new TypeError("Host call arguments cannot contain cycles.");
|
|
11040
11223
|
seen.add(value);
|
|
11041
11224
|
try {
|
|
11225
|
+
const date = copyNativeDate(value);
|
|
11226
|
+
if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
|
|
11042
11227
|
if (isFloat32Array(value)) {
|
|
11043
11228
|
const storage = float32Storage(value);
|
|
11044
11229
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
@@ -11994,6 +12179,7 @@ var KNOWN_RUNTIME_GLOBALS = [
|
|
|
11994
12179
|
"AggregateError",
|
|
11995
12180
|
"Array",
|
|
11996
12181
|
"Boolean",
|
|
12182
|
+
"Date",
|
|
11997
12183
|
"Error",
|
|
11998
12184
|
"Infinity",
|
|
11999
12185
|
"isFinite",
|
|
@@ -17158,9 +17344,9 @@ var ASFloatingPromiseScanner = class {
|
|
|
17158
17344
|
isPromiseFactoryCall(node) {
|
|
17159
17345
|
return this.isPromiseStaticMethodCall(node, PROMISE_FACTORIES);
|
|
17160
17346
|
}
|
|
17161
|
-
isPromiseStaticMethodCall(node,
|
|
17347
|
+
isPromiseStaticMethodCall(node, methodNames2) {
|
|
17162
17348
|
const member = node.callee.type === "MemberExpression" ? node.callee : void 0;
|
|
17163
|
-
return member !== void 0 && !member.computed && member.object.type === "Identifier" && member.object.name === "Promise" && member.property.type === "Identifier" &&
|
|
17349
|
+
return member !== void 0 && !member.computed && member.object.type === "Identifier" && member.object.name === "Promise" && member.property.type === "Identifier" && methodNames2.has(member.property.name);
|
|
17164
17350
|
}
|
|
17165
17351
|
isPromiseChainCall(node) {
|
|
17166
17352
|
const member = node.callee.type === "MemberExpression" ? node.callee : void 0;
|
|
@@ -24798,6 +24984,101 @@ function relativeIndex(value, length, fallback) {
|
|
|
24798
24984
|
return integer < 0 ? Math.max(length + integer, 0) : Math.min(integer, length);
|
|
24799
24985
|
}
|
|
24800
24986
|
|
|
24987
|
+
// packages/safe-js/src/interp/globals/date.ts
|
|
24988
|
+
var intrinsics = /* @__PURE__ */ new WeakMap();
|
|
24989
|
+
var constructors2 = /* @__PURE__ */ new WeakSet();
|
|
24990
|
+
function createDateGlobal(options) {
|
|
24991
|
+
const validateClockTime = (value) => {
|
|
24992
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || Math.abs(value) > 864e13)
|
|
24993
|
+
throw new TypeError("Date clock must return a finite integer epoch within the Date range.");
|
|
24994
|
+
return value;
|
|
24995
|
+
};
|
|
24996
|
+
const readNow = declareHostOperation(
|
|
24997
|
+
() => {
|
|
24998
|
+
options.budget.visitNode();
|
|
24999
|
+
const value = options.clock?.now === void 0 ? Date.now() : options.clock.now();
|
|
25000
|
+
return validateClockTime(value);
|
|
25001
|
+
},
|
|
25002
|
+
"re-issue",
|
|
25003
|
+
{
|
|
25004
|
+
onReplay: (_args, outcome) => {
|
|
25005
|
+
if (outcome.status === "fulfilled") {
|
|
25006
|
+
const time = validateClockTime(outcome.value);
|
|
25007
|
+
options.clock?.restore?.({ next: time + 1 });
|
|
25008
|
+
}
|
|
25009
|
+
}
|
|
25010
|
+
}
|
|
25011
|
+
);
|
|
25012
|
+
const now = wrapCallerInjectedBindings({ now: readNow }, { ...options, moduleId: "<Date>" }).now;
|
|
25013
|
+
const prototype = createSandboxDate(NaN);
|
|
25014
|
+
const constructor = createSandboxClosure({
|
|
25015
|
+
sandbox: true,
|
|
25016
|
+
name: "Date",
|
|
25017
|
+
length: 7,
|
|
25018
|
+
call: async (_args, context) => options.budget.allocateString(
|
|
25019
|
+
dateString(createSandboxDate(Number(await now.call([], context))))
|
|
25020
|
+
),
|
|
25021
|
+
construct: async (args, context) => {
|
|
25022
|
+
let time;
|
|
25023
|
+
if (args.length === 0) time = Number(await now.call([], context));
|
|
25024
|
+
else if (args.length > 1) time = dateFromParts(args, false);
|
|
25025
|
+
else if (isSandboxDate(args[0])) time = dateTime(args[0]);
|
|
25026
|
+
else if (typeof args[0] === "string") time = parseDate(args[0], options.budget);
|
|
25027
|
+
else time = dateNumber(args[0]);
|
|
25028
|
+
options.budget.chargeDataUsage(9);
|
|
25029
|
+
return createSandboxDate(time);
|
|
25030
|
+
},
|
|
25031
|
+
properties: {
|
|
25032
|
+
now,
|
|
25033
|
+
prototype,
|
|
25034
|
+
parse: createSandboxClosure({
|
|
25035
|
+
sandbox: true,
|
|
25036
|
+
name: "parse",
|
|
25037
|
+
length: 1,
|
|
25038
|
+
call: ([value]) => parseDate(value, options.budget)
|
|
25039
|
+
}),
|
|
25040
|
+
UTC: createSandboxClosure({
|
|
25041
|
+
sandbox: true,
|
|
25042
|
+
name: "UTC",
|
|
25043
|
+
length: 7,
|
|
25044
|
+
call: (args) => dateFromParts(args, true)
|
|
25045
|
+
})
|
|
25046
|
+
}
|
|
25047
|
+
});
|
|
25048
|
+
const methods = /* @__PURE__ */ new Map();
|
|
25049
|
+
for (const [name, method] of dateMethods)
|
|
25050
|
+
methods.set(
|
|
25051
|
+
name,
|
|
25052
|
+
createSandboxClosure({
|
|
25053
|
+
sandbox: true,
|
|
25054
|
+
name,
|
|
25055
|
+
length: method.length,
|
|
25056
|
+
call: (args, context) => {
|
|
25057
|
+
const receiver = context?.thisValue;
|
|
25058
|
+
if (!isSandboxDate(receiver))
|
|
25059
|
+
throw new TypeError(`Date#${name} requires a Date receiver.`);
|
|
25060
|
+
options.budget.visitNode();
|
|
25061
|
+
const value = method.invoke(receiver, args);
|
|
25062
|
+
return typeof value === "string" ? options.budget.allocateString(value) : value;
|
|
25063
|
+
}
|
|
25064
|
+
})
|
|
25065
|
+
);
|
|
25066
|
+
constructors2.add(constructor);
|
|
25067
|
+
intrinsics.set(options.compileOwner ?? options.budget, { constructor, prototype, methods });
|
|
25068
|
+
return constructor;
|
|
25069
|
+
}
|
|
25070
|
+
function isDateConstructor(value) {
|
|
25071
|
+
return typeof value === "object" && value !== null && constructors2.has(value);
|
|
25072
|
+
}
|
|
25073
|
+
function getDateMember(property, budget, owner) {
|
|
25074
|
+
const state = intrinsics.get(owner ?? budget);
|
|
25075
|
+
return property === "constructor" ? state?.constructor : state?.methods.get(String(property));
|
|
25076
|
+
}
|
|
25077
|
+
function getDatePrototype(value, budget, owner) {
|
|
25078
|
+
const prototype = intrinsics.get(owner ?? budget)?.prototype;
|
|
25079
|
+
return prototype === value ? null : prototype ?? null;
|
|
25080
|
+
}
|
|
25081
|
+
|
|
24801
25082
|
// packages/safe-js/src/interp/scope.ts
|
|
24802
25083
|
var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
|
|
24803
25084
|
var Scope = class _Scope {
|
|
@@ -26662,6 +26943,7 @@ function getPropertyValue(target, property, context) {
|
|
|
26662
26943
|
if (typeof target === "number") return getNumberMember(target, property, context.budget);
|
|
26663
26944
|
if (typeof target === "boolean") return void 0;
|
|
26664
26945
|
if (isFloat32Array(target)) return getFloat32Member(target, property, context.budget);
|
|
26946
|
+
if (isSandboxDate(target)) return getDateMember(property, context.budget, context.compilation?.owner);
|
|
26665
26947
|
if (isSandboxMap(target)) return getMapMember(target, property, createMapMethodOptions(context));
|
|
26666
26948
|
if (isSandboxSet(target)) return getSetMember(target, property, createSetMethodOptions(context));
|
|
26667
26949
|
if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
|
|
@@ -26898,6 +27180,9 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
26898
27180
|
context
|
|
26899
27181
|
);
|
|
26900
27182
|
}
|
|
27183
|
+
if (isSandboxDate(member.object)) {
|
|
27184
|
+
return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
|
|
27185
|
+
}
|
|
26901
27186
|
if (isFloat32Array(member.object)) {
|
|
26902
27187
|
return evaluateResolvedCallExpression(
|
|
26903
27188
|
node,
|
|
@@ -27150,6 +27435,7 @@ function applyBinaryOperator(node, left, right, context) {
|
|
|
27150
27435
|
return true;
|
|
27151
27436
|
}
|
|
27152
27437
|
if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
|
|
27438
|
+
if (isDateConstructor(right)) return isSandboxDate(left) && getDatePrototype(left, context.budget, context.compilation?.owner) !== null;
|
|
27153
27439
|
if (isSandboxSetConstructor(right) && isSandboxSet(left)) {
|
|
27154
27440
|
return true;
|
|
27155
27441
|
}
|
|
@@ -27213,8 +27499,8 @@ function applyAdditionOperator(left, right, context) {
|
|
|
27213
27499
|
return toNumber(leftPrimitive) + toNumber(rightPrimitive);
|
|
27214
27500
|
}
|
|
27215
27501
|
function compareRelational(left, right, operator) {
|
|
27216
|
-
const leftPrimitive = toPrimitive(left);
|
|
27217
|
-
const rightPrimitive = toPrimitive(right);
|
|
27502
|
+
const leftPrimitive = isSandboxDate(left) ? dateTime(left) : toPrimitive(left);
|
|
27503
|
+
const rightPrimitive = isSandboxDate(right) ? dateTime(right) : toPrimitive(right);
|
|
27218
27504
|
if (typeof leftPrimitive === "string" && typeof rightPrimitive === "string") {
|
|
27219
27505
|
switch (operator) {
|
|
27220
27506
|
case "<":
|
|
@@ -27297,6 +27583,7 @@ function toPrimitive(value) {
|
|
|
27297
27583
|
return toString(value);
|
|
27298
27584
|
}
|
|
27299
27585
|
async function toNumericPrimitive(value, context) {
|
|
27586
|
+
if (isSandboxDate(value)) return dateTime(value);
|
|
27300
27587
|
if (isPrimitiveCoercionType(getCoercionType(value))) {
|
|
27301
27588
|
return value;
|
|
27302
27589
|
}
|
|
@@ -27326,6 +27613,7 @@ async function toNumericPrimitive(value, context) {
|
|
|
27326
27613
|
return toString(value);
|
|
27327
27614
|
}
|
|
27328
27615
|
function toNumber(value) {
|
|
27616
|
+
if (isSandboxDate(value)) return dateTime(value);
|
|
27329
27617
|
if (typeof value === "number") {
|
|
27330
27618
|
return value;
|
|
27331
27619
|
}
|
|
@@ -27344,6 +27632,7 @@ function toNumber(value) {
|
|
|
27344
27632
|
return toNumber(toPrimitive(value));
|
|
27345
27633
|
}
|
|
27346
27634
|
function toString(value) {
|
|
27635
|
+
if (isSandboxDate(value)) return dateString(value);
|
|
27347
27636
|
if (Array.isArray(value)) {
|
|
27348
27637
|
return value.map((entry) => entry === null || entry === void 0 ? "" : toString(entry)).join(",");
|
|
27349
27638
|
}
|
|
@@ -27389,6 +27678,7 @@ function getArrayMemberValue(target, property, context) {
|
|
|
27389
27678
|
return getArrayMember(target, property, createArrayMethodOptions(context));
|
|
27390
27679
|
}
|
|
27391
27680
|
function setSandboxProperty(target, property, value, budget) {
|
|
27681
|
+
if (isSandboxDate(target)) throw new TypeError("Date own properties are not supported.");
|
|
27392
27682
|
if (isGuestHostObject(target)) {
|
|
27393
27683
|
setHostObjectMember(target, String(property), value);
|
|
27394
27684
|
return;
|
|
@@ -28043,7 +28333,7 @@ function wrapCallerInjectedFunction(name, value, options, state) {
|
|
|
28043
28333
|
seen: /* @__PURE__ */ new WeakMap(),
|
|
28044
28334
|
restored: []
|
|
28045
28335
|
};
|
|
28046
|
-
const
|
|
28336
|
+
const copyArguments = (values) => deepCopyFromSandbox([...values], {
|
|
28047
28337
|
compilation,
|
|
28048
28338
|
unwrapHostObject: options.realm === void 0 ? void 0 : (object) => exportHostCapability(object, options.realm.owner),
|
|
28049
28339
|
wrapClosure: (closure) => options.realm?.wrapCallback(closure) ?? wrapSandboxClosureForHost(
|
|
@@ -28054,13 +28344,21 @@ function wrapCallerInjectedFunction(name, value, options, state) {
|
|
|
28054
28344
|
callbacks
|
|
28055
28345
|
)
|
|
28056
28346
|
});
|
|
28347
|
+
const captured = options.realm?.captureArguments(callable, args, copyArguments);
|
|
28348
|
+
const hostArgs = captured?.args ?? copyArguments(args);
|
|
28057
28349
|
const hostCalls = options.hostCalls;
|
|
28058
28350
|
const operation = options.operation ?? bindingName;
|
|
28059
28351
|
const moduleId = options.moduleId ?? "<bindings>";
|
|
28060
28352
|
const policy = readHostOperationPolicy(value) ?? readRegisteredPendingHostCallPolicy(moduleId, operation) ?? "re-issue";
|
|
28061
28353
|
if (hostCalls === void 0) {
|
|
28062
28354
|
if (options.realm !== void 0) {
|
|
28063
|
-
|
|
28355
|
+
let result;
|
|
28356
|
+
try {
|
|
28357
|
+
result = options.realm.invoke(callable, () => Reflect.apply(callable, void 0, hostArgs));
|
|
28358
|
+
} catch (error) {
|
|
28359
|
+
captured.rollback();
|
|
28360
|
+
throw error;
|
|
28361
|
+
}
|
|
28064
28362
|
if (options.realm.awaitResult(callable)) {
|
|
28065
28363
|
return Promise.resolve(result).then((value2) => copyHostResultToSandbox(value2, stackFrames, options));
|
|
28066
28364
|
}
|
|
@@ -28648,6 +28946,14 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
|
|
|
28648
28946
|
state
|
|
28649
28947
|
);
|
|
28650
28948
|
}
|
|
28949
|
+
const date = copyNativeDate(value);
|
|
28950
|
+
if (date !== void 0) {
|
|
28951
|
+
const existing = state.seen.get(value);
|
|
28952
|
+
if (existing !== void 0) return existing;
|
|
28953
|
+
budget.chargeDataUsage(9);
|
|
28954
|
+
state.seen.set(value, date);
|
|
28955
|
+
return date;
|
|
28956
|
+
}
|
|
28651
28957
|
if (isFloat32Array(value)) {
|
|
28652
28958
|
const existing = state.seen.get(value);
|
|
28653
28959
|
if (existing !== void 0) return existing;
|
|
@@ -29049,7 +29355,7 @@ function createReplayableRandom(options = {}) {
|
|
|
29049
29355
|
|
|
29050
29356
|
// packages/safe-js/src/realm.ts
|
|
29051
29357
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
29052
|
-
import { types as
|
|
29358
|
+
import { types as types4 } from "node:util";
|
|
29053
29359
|
|
|
29054
29360
|
// packages/safe-js/src/interp/globals/console-json.ts
|
|
29055
29361
|
function createConsoleJsonGlobals(options) {
|
|
@@ -29163,7 +29469,9 @@ function toJsonParseText(input) {
|
|
|
29163
29469
|
}
|
|
29164
29470
|
async function stringifyProperty(key, holder, state, indent = "") {
|
|
29165
29471
|
let value = getOwnDataValue(holder, key);
|
|
29166
|
-
if (
|
|
29472
|
+
if (isSandboxDate(value)) {
|
|
29473
|
+
value = dateMethods.get("toJSON").invoke(value, []);
|
|
29474
|
+
} else if (isStringifyContainer(value)) {
|
|
29167
29475
|
const toJSON = getOwnDataValue(value, "toJSON");
|
|
29168
29476
|
if (isSandboxClosure(toJSON)) {
|
|
29169
29477
|
value = await callStringifyClosure(toJSON, [key], value, state);
|
|
@@ -29475,6 +29783,7 @@ async function stringifyObject2(value, budget, context, joining) {
|
|
|
29475
29783
|
}
|
|
29476
29784
|
}
|
|
29477
29785
|
async function defaultToString(value, budget, context, joining) {
|
|
29786
|
+
if (isSandboxDate(value)) return budget.allocateString(dateString(value));
|
|
29478
29787
|
if (Array.isArray(value) || isFloat32Array(value)) {
|
|
29479
29788
|
if (Object.hasOwn(value, "join")) {
|
|
29480
29789
|
const join = ownDataValue(value, "join");
|
|
@@ -29578,6 +29887,7 @@ function createObjectArrayGlobals(options) {
|
|
|
29578
29887
|
getPrototypeOf: createSandboxClosure({
|
|
29579
29888
|
sandbox: true,
|
|
29580
29889
|
call: ([value]) => {
|
|
29890
|
+
if (isSandboxDate(value)) return getDatePrototype(value, options.budget, options.compileOwner);
|
|
29581
29891
|
objectProperties(value);
|
|
29582
29892
|
return getSandboxPrototype(value);
|
|
29583
29893
|
},
|
|
@@ -29702,7 +30012,7 @@ function createObjectArrayGlobals(options) {
|
|
|
29702
30012
|
}),
|
|
29703
30013
|
Number: createSandboxClosure({
|
|
29704
30014
|
sandbox: true,
|
|
29705
|
-
call: ([value]) => Number(value),
|
|
30015
|
+
call: ([value]) => isSandboxDate(value) ? dateTime(value) : Number(value),
|
|
29706
30016
|
name: "Number",
|
|
29707
30017
|
properties: {
|
|
29708
30018
|
isFinite: createSandboxClosure({
|
|
@@ -29802,6 +30112,10 @@ function assignSandboxValues(target, sources, budget) {
|
|
|
29802
30112
|
return target;
|
|
29803
30113
|
}
|
|
29804
30114
|
function objectProperties(value, mutable = false) {
|
|
30115
|
+
if (isSandboxDate(value)) {
|
|
30116
|
+
if (mutable) throw new TypeError("Date own properties and prototypes are not supported.");
|
|
30117
|
+
return value;
|
|
30118
|
+
}
|
|
29805
30119
|
if (isGuestHostObject(value)) throw new TypeError("Live host object descriptors are not supported.");
|
|
29806
30120
|
if (isGuestClosure(value)) return materializeFunctionProperties(value);
|
|
29807
30121
|
if (isSandboxClosure(value)) {
|
|
@@ -29923,6 +30237,7 @@ function createBuiltinBindings(options) {
|
|
|
29923
30237
|
...createConsoleJsonGlobals(options),
|
|
29924
30238
|
...createCollectionGlobals(options),
|
|
29925
30239
|
Float32Array: createFloat32ArrayGlobal(options.budget),
|
|
30240
|
+
Date: createDateGlobal(options),
|
|
29926
30241
|
...createErrorGlobals(options),
|
|
29927
30242
|
...createMathGlobals({ random: options.random }),
|
|
29928
30243
|
...createObjectArrayGlobals(options),
|
|
@@ -30095,6 +30410,7 @@ var RealmState = class {
|
|
|
30095
30410
|
extensions: 32,
|
|
30096
30411
|
hostObjects: 1024,
|
|
30097
30412
|
callbacks: 1024,
|
|
30413
|
+
guestReferences: 1024,
|
|
30098
30414
|
cleanups: 1024,
|
|
30099
30415
|
nestedEvaluations: 16
|
|
30100
30416
|
};
|
|
@@ -30103,7 +30419,7 @@ var RealmState = class {
|
|
|
30103
30419
|
throw new TypeError("Realm limits must be positive safe integers with supported names.");
|
|
30104
30420
|
this.limits[name] = Number(value);
|
|
30105
30421
|
}
|
|
30106
|
-
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) ||
|
|
30422
|
+
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types4.isProxy(options.extensions)))
|
|
30107
30423
|
throw new TypeError("Extensions must be a registration array.");
|
|
30108
30424
|
const registrations = options.extensions ?? [];
|
|
30109
30425
|
const extensions = [];
|
|
@@ -30131,6 +30447,7 @@ var RealmState = class {
|
|
|
30131
30447
|
owner: this,
|
|
30132
30448
|
assertActive: this.assertOpen,
|
|
30133
30449
|
wrapCallback: this.wrapCallback,
|
|
30450
|
+
captureArguments: this.captureArguments,
|
|
30134
30451
|
invoke: this.invokeHost,
|
|
30135
30452
|
awaitResult: (operation) => this.nestedOperations.has(operation)
|
|
30136
30453
|
};
|
|
@@ -30139,6 +30456,7 @@ var RealmState = class {
|
|
|
30139
30456
|
budget: this.budget,
|
|
30140
30457
|
compileOwner: this.lease.owner,
|
|
30141
30458
|
sink: options.sink,
|
|
30459
|
+
clock: options.clock,
|
|
30142
30460
|
random: createReplayableRandom({ seed: options.randomSeed }).next
|
|
30143
30461
|
});
|
|
30144
30462
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -30170,7 +30488,7 @@ var RealmState = class {
|
|
|
30170
30488
|
}
|
|
30171
30489
|
options.signal?.addEventListener("abort", this.abort, { once: true });
|
|
30172
30490
|
if (options.signal?.aborted) this.abort();
|
|
30173
|
-
this.budget.setRetainedValues(this, this.
|
|
30491
|
+
this.budget.setRetainedValues(this, this.retainedRoots);
|
|
30174
30492
|
this.tracker.onFatalRejection((error) => this.poison(error));
|
|
30175
30493
|
} catch (error) {
|
|
30176
30494
|
this.compilation.dispose();
|
|
@@ -30194,6 +30512,8 @@ var RealmState = class {
|
|
|
30194
30512
|
pendingCallbacks = /* @__PURE__ */ new Set();
|
|
30195
30513
|
callbackCache = /* @__PURE__ */ new WeakMap();
|
|
30196
30514
|
hostObjects = /* @__PURE__ */ new Set();
|
|
30515
|
+
guestReferences = /* @__PURE__ */ new Map();
|
|
30516
|
+
retainedOperations = /* @__PURE__ */ new WeakMap();
|
|
30197
30517
|
nestedOperations = /* @__PURE__ */ new WeakMap();
|
|
30198
30518
|
convertedModules = /* @__PURE__ */ new Map();
|
|
30199
30519
|
nativeConversions = { seen: /* @__PURE__ */ new WeakMap() };
|
|
@@ -30213,10 +30533,56 @@ var RealmState = class {
|
|
|
30213
30533
|
signal: this.controller.signal,
|
|
30214
30534
|
realm: this.bridge
|
|
30215
30535
|
});
|
|
30216
|
-
|
|
30536
|
+
retainedRoots = () => [
|
|
30217
30537
|
...this.callbacks.values(),
|
|
30218
|
-
...Array.from(this.pendingCallbacks, (pending) => pending.closure)
|
|
30538
|
+
...Array.from(this.pendingCallbacks, (pending) => pending.closure),
|
|
30539
|
+
...this.guestReferences.values()
|
|
30219
30540
|
];
|
|
30541
|
+
captureArguments = (operation, args, copy) => {
|
|
30542
|
+
const from = this.retainedOperations.get(operation)?.from ?? args.length;
|
|
30543
|
+
const values = copy(args.slice(0, from));
|
|
30544
|
+
const captured = [];
|
|
30545
|
+
const rollback = () => {
|
|
30546
|
+
for (const reference of captured) {
|
|
30547
|
+
revokeGuestReference(reference, this);
|
|
30548
|
+
this.guestReferences.delete(reference);
|
|
30549
|
+
}
|
|
30550
|
+
};
|
|
30551
|
+
try {
|
|
30552
|
+
for (const value of args.slice(from)) {
|
|
30553
|
+
this.checkCollection(
|
|
30554
|
+
this.guestReferences.size + 1,
|
|
30555
|
+
this.limits.guestReferences,
|
|
30556
|
+
"guest reference"
|
|
30557
|
+
);
|
|
30558
|
+
const root = [value];
|
|
30559
|
+
const reference = createGuestReference(root, this, this.assertOpen);
|
|
30560
|
+
this.guestReferences.set(reference, root);
|
|
30561
|
+
captured.push(reference);
|
|
30562
|
+
values.push(reference);
|
|
30563
|
+
}
|
|
30564
|
+
if (captured.length > 0)
|
|
30565
|
+
this.budget.reconcileDataUsage(
|
|
30566
|
+
measureSandboxData([...this.scope?.retainedValues() ?? [], ...this.retainedRoots()])
|
|
30567
|
+
);
|
|
30568
|
+
return { args: values, rollback };
|
|
30569
|
+
} catch (error) {
|
|
30570
|
+
rollback();
|
|
30571
|
+
if (error instanceof SandboxError) this.poison(error);
|
|
30572
|
+
throw error;
|
|
30573
|
+
}
|
|
30574
|
+
};
|
|
30575
|
+
releaseGuestReference = (reference) => {
|
|
30576
|
+
readGuestReference(reference, this);
|
|
30577
|
+
revokeGuestReference(reference, this);
|
|
30578
|
+
this.guestReferences.delete(reference);
|
|
30579
|
+
if (this.active === void 0)
|
|
30580
|
+
reconcileCompiledValues(
|
|
30581
|
+
this.budget,
|
|
30582
|
+
[...this.scope?.retainedValues() ?? [], ...this.retainedRoots()],
|
|
30583
|
+
this.compilation
|
|
30584
|
+
);
|
|
30585
|
+
};
|
|
30220
30586
|
assertOpen = () => {
|
|
30221
30587
|
if (this.failure !== void 0) throw this.failure.reason;
|
|
30222
30588
|
if (this.closed) throw new Error("SafeJS realm is closed; capabilities are revoked.");
|
|
@@ -30272,7 +30638,7 @@ var RealmState = class {
|
|
|
30272
30638
|
return this.phase.run(phase, () => {
|
|
30273
30639
|
try {
|
|
30274
30640
|
const result = call();
|
|
30275
|
-
if (
|
|
30641
|
+
if (types4.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
|
|
30276
30642
|
return Promise.resolve(result).then(
|
|
30277
30643
|
async (value) => {
|
|
30278
30644
|
await Promise.allSettled(phase.pending);
|
|
@@ -30329,7 +30695,7 @@ var RealmState = class {
|
|
|
30329
30695
|
chargeWork: this.chargeWork,
|
|
30330
30696
|
read: (operation) => {
|
|
30331
30697
|
const value = this.invokeHost(operation, operation);
|
|
30332
|
-
if (
|
|
30698
|
+
if (types4.isPromise(value)) {
|
|
30333
30699
|
void Promise.resolve(value).catch(() => void 0);
|
|
30334
30700
|
throw new TypeError("Live property getters must be synchronous.");
|
|
30335
30701
|
}
|
|
@@ -30337,7 +30703,7 @@ var RealmState = class {
|
|
|
30337
30703
|
},
|
|
30338
30704
|
write: (operation, value) => {
|
|
30339
30705
|
const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
|
|
30340
|
-
if (
|
|
30706
|
+
if (types4.isPromise(result)) {
|
|
30341
30707
|
void Promise.resolve(result).catch(() => void 0);
|
|
30342
30708
|
throw new TypeError("Live property setters must be synchronous.");
|
|
30343
30709
|
}
|
|
@@ -30384,7 +30750,7 @@ var RealmState = class {
|
|
|
30384
30750
|
});
|
|
30385
30751
|
try {
|
|
30386
30752
|
this.budget.reconcileDataUsage(
|
|
30387
|
-
measureSandboxData([...this.scope?.retainedValues() ?? [], ...this.
|
|
30753
|
+
measureSandboxData([...this.scope?.retainedValues() ?? [], ...this.retainedRoots()])
|
|
30388
30754
|
);
|
|
30389
30755
|
} catch (error) {
|
|
30390
30756
|
this.poison(error);
|
|
@@ -30399,7 +30765,7 @@ var RealmState = class {
|
|
|
30399
30765
|
if (this.active === void 0)
|
|
30400
30766
|
reconcileCompiledValues(
|
|
30401
30767
|
this.budget,
|
|
30402
|
-
[...this.scope?.retainedValues() ?? [], ...this.
|
|
30768
|
+
[...this.scope?.retainedValues() ?? [], ...this.retainedRoots()],
|
|
30403
30769
|
this.compilation
|
|
30404
30770
|
);
|
|
30405
30771
|
};
|
|
@@ -30458,7 +30824,7 @@ var RealmState = class {
|
|
|
30458
30824
|
if (!this.closed && this.active === void 0)
|
|
30459
30825
|
reconcileCompiledValues(
|
|
30460
30826
|
this.budget,
|
|
30461
|
-
[...this.scope?.retainedValues() ?? [], ...this.
|
|
30827
|
+
[...this.scope?.retainedValues() ?? [], ...this.retainedRoots()],
|
|
30462
30828
|
this.compilation
|
|
30463
30829
|
);
|
|
30464
30830
|
}
|
|
@@ -30475,6 +30841,23 @@ var RealmState = class {
|
|
|
30475
30841
|
createHostObject: this.createHostObject,
|
|
30476
30842
|
invokeCallback: this.invokeCallback,
|
|
30477
30843
|
releaseCallback: this.releaseCallback,
|
|
30844
|
+
releaseGuestReference: this.releaseGuestReference,
|
|
30845
|
+
retainGuestArguments: (operation, from) => {
|
|
30846
|
+
this.assertOpen();
|
|
30847
|
+
if (!extension.manifest.capabilities?.includes("guest:retain"))
|
|
30848
|
+
throw new TypeError("Retaining arguments requires the guest:retain grant.");
|
|
30849
|
+
if (typeof operation !== "function")
|
|
30850
|
+
throw new TypeError("Retained operation must be a function.");
|
|
30851
|
+
if (!Number.isSafeInteger(from) || from < 0)
|
|
30852
|
+
throw new TypeError("Argument index must be a non-negative safe integer.");
|
|
30853
|
+
if (this.scope !== void 0)
|
|
30854
|
+
throw new TypeError("Retained operations must be registered during setup.");
|
|
30855
|
+
const previous = this.retainedOperations.get(operation);
|
|
30856
|
+
if (previous !== void 0 && (previous.extension !== extension || previous.from !== from))
|
|
30857
|
+
throw new TypeError("Conflicting retained operation declaration.");
|
|
30858
|
+
this.retainedOperations.set(operation, { extension, from });
|
|
30859
|
+
return operation;
|
|
30860
|
+
},
|
|
30478
30861
|
nestedOperation: (operation) => {
|
|
30479
30862
|
this.assertOpen();
|
|
30480
30863
|
if (!extension.manifest.capabilities?.includes("source:nested"))
|
|
@@ -30513,7 +30896,7 @@ var RealmState = class {
|
|
|
30513
30896
|
}
|
|
30514
30897
|
});
|
|
30515
30898
|
const output = getExtensionSetup(extension)(context);
|
|
30516
|
-
if (
|
|
30899
|
+
if (types4.isPromise(output)) {
|
|
30517
30900
|
void Promise.resolve(output).catch(() => void 0);
|
|
30518
30901
|
throw new TypeError("Extension setup must be synchronous.");
|
|
30519
30902
|
}
|
|
@@ -30637,7 +31020,7 @@ var RealmState = class {
|
|
|
30637
31020
|
if (!this.closed)
|
|
30638
31021
|
reconcileCompiledValues(
|
|
30639
31022
|
this.budget,
|
|
30640
|
-
[...this.scope?.retainedValues() ?? [], ...this.
|
|
31023
|
+
[...this.scope?.retainedValues() ?? [], ...this.retainedRoots()],
|
|
30641
31024
|
this.compilation
|
|
30642
31025
|
);
|
|
30643
31026
|
return result;
|
|
@@ -30671,6 +31054,8 @@ var RealmState = class {
|
|
|
30671
31054
|
this.callbacks.clear();
|
|
30672
31055
|
for (const object of this.hostObjects) revokeHostObject(object, this);
|
|
30673
31056
|
this.hostObjects.clear();
|
|
31057
|
+
for (const reference of this.guestReferences.keys()) revokeGuestReference(reference, this);
|
|
31058
|
+
this.guestReferences.clear();
|
|
30674
31059
|
this.budget.setRetainedValues(this, void 0);
|
|
30675
31060
|
this.disposal = (async () => {
|
|
30676
31061
|
const errors = [];
|
|
@@ -30698,7 +31083,7 @@ var RealmState = class {
|
|
|
30698
31083
|
};
|
|
30699
31084
|
function readModules(input) {
|
|
30700
31085
|
const entries = (value, label) => {
|
|
30701
|
-
if (
|
|
31086
|
+
if (types4.isMap(value) && !types4.isProxy(value)) {
|
|
30702
31087
|
const result = [...Map.prototype.entries.call(value)];
|
|
30703
31088
|
if (result.length > 4096 || result.some(([key]) => typeof key !== "string" || key.length === 0))
|
|
30704
31089
|
throw new TypeError(`${label} requires bounded string keys.`);
|
|
@@ -30726,6 +31111,7 @@ function createRealm(options = {}) {
|
|
|
30726
31111
|
evaluate: state.evaluate,
|
|
30727
31112
|
invokeCallback: state.invokeCallback,
|
|
30728
31113
|
releaseCallback: state.releaseCallback,
|
|
31114
|
+
releaseGuestReference: state.releaseGuestReference,
|
|
30729
31115
|
close: state.close
|
|
30730
31116
|
});
|
|
30731
31117
|
}
|
|
@@ -30771,6 +31157,7 @@ function readRealmOptions(value, oneShot = false) {
|
|
|
30771
31157
|
"signal",
|
|
30772
31158
|
"sink",
|
|
30773
31159
|
"randomSeed",
|
|
31160
|
+
"clock",
|
|
30774
31161
|
"limits"
|
|
30775
31162
|
]);
|
|
30776
31163
|
for (const [key, entry] of Object.entries(options)) {
|
|
@@ -31417,7 +31804,7 @@ function run(source, options = {}) {
|
|
|
31417
31804
|
lifecycle
|
|
31418
31805
|
})
|
|
31419
31806
|
);
|
|
31420
|
-
const builtinBindings = createBuiltinBindings({ compileOwner: operation.owner, budget, hostCalls, sink: options.sink, random: random?.generator.next });
|
|
31807
|
+
const builtinBindings = createBuiltinBindings({ compileOwner: operation.owner, budget, hostCalls, sink: options.sink, random: random?.generator.next, clock: options.clock });
|
|
31421
31808
|
const importMeta = convertInitialInput(
|
|
31422
31809
|
() => deepCopyToSandbox(options.importMeta ?? {})
|
|
31423
31810
|
);
|
|
@@ -31920,4 +32307,4 @@ export {
|
|
|
31920
32307
|
FileSnapshotBackend,
|
|
31921
32308
|
run
|
|
31922
32309
|
};
|
|
31923
|
-
//# sourceMappingURL=chunk-
|
|
32310
|
+
//# sourceMappingURL=chunk-BWVASPJX.js.map
|