@poe-platform/safe-js 0.1.24 → 0.1.26
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/README.md +56 -4
- package/dist/safe-js/chunks/{chunk-MXUOEOBE.js → chunk-2LVAGOJR.js} +494 -39
- package/dist/safe-js/chunks/chunk-2LVAGOJR.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-X32RVLSM.js → chunk-I2SNTMRS.js} +2 -2
- 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/values.d.ts +3 -1
- package/dist/safe-js/realm.d.ts +2 -1
- package/dist/safe-js/run.d.ts +2 -0
- package/dist/safe-js/snapshot/replay-data.d.ts +4 -1
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-MXUOEOBE.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-X32RVLSM.js.map → chunk-I2SNTMRS.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,6 +6208,128 @@ 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();
|
|
@@ -6465,7 +6588,7 @@ async function flushPromiseJobs() {
|
|
|
6465
6588
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
6466
6589
|
|
|
6467
6590
|
// packages/safe-js/src/snapshot/validation.ts
|
|
6468
|
-
import { types as
|
|
6591
|
+
import { types as types3 } from "node:util";
|
|
6469
6592
|
|
|
6470
6593
|
// packages/safe-js/src/interp/arguments.ts
|
|
6471
6594
|
var sandboxArgumentsBrand = /* @__PURE__ */ Symbol("SandboxArguments");
|
|
@@ -6595,6 +6718,8 @@ function graphEntries(value) {
|
|
|
6595
6718
|
var guestClosures = /* @__PURE__ */ new WeakSet();
|
|
6596
6719
|
var functionProperties = /* @__PURE__ */ new WeakMap();
|
|
6597
6720
|
var prototypes = /* @__PURE__ */ new WeakMap();
|
|
6721
|
+
var intrinsicPrototypes = /* @__PURE__ */ new WeakMap();
|
|
6722
|
+
var intrinsicConstructors = /* @__PURE__ */ new WeakMap();
|
|
6598
6723
|
var descriptorObjects = /* @__PURE__ */ new WeakSet();
|
|
6599
6724
|
function registerGuestClosure(closure) {
|
|
6600
6725
|
guestClosures.add(closure);
|
|
@@ -6639,27 +6764,49 @@ function getGuestFunctionProperty(closure, key) {
|
|
|
6639
6764
|
}
|
|
6640
6765
|
return properties === void 0 ? void 0 : Object.getOwnPropertyDescriptor(properties, key)?.value;
|
|
6641
6766
|
}
|
|
6642
|
-
function
|
|
6643
|
-
|
|
6767
|
+
function installObjectPrototype(budget, prototype, constructor) {
|
|
6768
|
+
prototypes.set(prototype, null);
|
|
6769
|
+
intrinsicPrototypes.set(budget, prototype);
|
|
6770
|
+
const records = [prototype, materializeFunctionProperties(constructor)].map((value) => ({
|
|
6771
|
+
value,
|
|
6772
|
+
descriptors: new Map(Object.entries(Object.getOwnPropertyDescriptors(value)))
|
|
6773
|
+
}));
|
|
6774
|
+
const unchanged = (before, after) => before !== void 0 && after !== void 0 && before.value === after.value && before.writable === after.writable && before.configurable === after.configurable && before.enumerable === after.enumerable;
|
|
6775
|
+
intrinsicConstructors.set(constructor, () => records.every(({ value, descriptors }) => {
|
|
6776
|
+
const current = Object.getOwnPropertyDescriptors(value);
|
|
6777
|
+
return Object.keys(current).length === descriptors.size && Object.keys(current).every((key) => unchanged(descriptors.get(key), current[key]));
|
|
6778
|
+
}));
|
|
6779
|
+
budget.setRetainedValues(prototype, () => records.flatMap(({ value, descriptors }) => Object.entries(Object.getOwnPropertyDescriptors(value)).flatMap(([key, descriptor]) => unchanged(descriptors.get(key), descriptor) ? [] : [key, descriptor.value])));
|
|
6780
|
+
}
|
|
6781
|
+
function releaseObjectPrototype(budget) {
|
|
6782
|
+
const prototype = intrinsicPrototypes.get(budget);
|
|
6783
|
+
if (prototype !== void 0) budget.setRetainedValues(prototype, void 0);
|
|
6784
|
+
intrinsicPrototypes.delete(budget);
|
|
6785
|
+
}
|
|
6786
|
+
function getSandboxPrototype(value, budget) {
|
|
6787
|
+
if (prototypes.has(value)) return prototypes.get(value) ?? null;
|
|
6788
|
+
return budget !== void 0 && isPrototypeRecord(value) ? intrinsicPrototypes.get(budget) ?? null : null;
|
|
6644
6789
|
}
|
|
6645
6790
|
function setSandboxPrototype(value, prototype, budget) {
|
|
6791
|
+
if (budget !== void 0 && intrinsicPrototypes.get(budget) === value && prototype !== null) {
|
|
6792
|
+
throw new TypeError("Object.prototype has an immutable null prototype.");
|
|
6793
|
+
}
|
|
6646
6794
|
if (!isPrototypeRecord(value) || prototype !== null && !isPrototypeRecord(prototype)) {
|
|
6647
6795
|
throw new TypeError(
|
|
6648
6796
|
"Prototype links require ordinary sandbox objects; callable and exotic prototype chains are not supported."
|
|
6649
6797
|
);
|
|
6650
6798
|
}
|
|
6651
|
-
if (getSandboxPrototype(value) === prototype) return;
|
|
6799
|
+
if (prototypes.has(value) && getSandboxPrototype(value, budget) === prototype) return;
|
|
6652
6800
|
if (!Object.isExtensible(isGuestClosure(value) ? materializeFunctionProperties(value) : value)) {
|
|
6653
6801
|
throw new TypeError("Cannot change the prototype of a non-extensible object.");
|
|
6654
6802
|
}
|
|
6655
6803
|
let depth = 0;
|
|
6656
|
-
for (let current = prototype; current !== null; current = getSandboxPrototype(current)) {
|
|
6804
|
+
for (let current = prototype; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
6657
6805
|
budget?.visitNode();
|
|
6658
6806
|
assertSandboxDataDepth(depth++);
|
|
6659
6807
|
if (current === value) throw new TypeError("Cyclic prototype value.");
|
|
6660
6808
|
}
|
|
6661
|
-
|
|
6662
|
-
else prototypes.set(value, prototype);
|
|
6809
|
+
prototypes.set(value, prototype);
|
|
6663
6810
|
}
|
|
6664
6811
|
function isPrototypeRecord(value) {
|
|
6665
6812
|
if (isGuestHostObject(value)) return false;
|
|
@@ -6675,6 +6822,8 @@ function hasManagedDescriptors(value) {
|
|
|
6675
6822
|
return descriptorObjects.has(value);
|
|
6676
6823
|
}
|
|
6677
6824
|
function hasGuestObjectState(value) {
|
|
6825
|
+
const intrinsicUnchanged = intrinsicConstructors.get(value);
|
|
6826
|
+
if (intrinsicUnchanged !== void 0) return !intrinsicUnchanged();
|
|
6678
6827
|
if (isLiveCapability(value)) return true;
|
|
6679
6828
|
if (functionProperties.has(value) || prototypes.has(value)) return true;
|
|
6680
6829
|
return descriptorObjects.has(value) && Object.values(Object.getOwnPropertyDescriptors(value)).some(
|
|
@@ -6841,7 +6990,7 @@ function serializeDumpValue(value, path, state) {
|
|
|
6841
6990
|
if (hasGuestObjectState(value)) {
|
|
6842
6991
|
throw new TypeError("Guest function properties and prototype links cannot be serialized.");
|
|
6843
6992
|
}
|
|
6844
|
-
if (isFloat32Array(value)) return serializeHeapReference(value, path, state);
|
|
6993
|
+
if (isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
|
|
6845
6994
|
if (Array.isArray(value)) {
|
|
6846
6995
|
const reference2 = serializeHeapReference(value, path, state);
|
|
6847
6996
|
if (reference2 !== void 0) {
|
|
@@ -6865,7 +7014,9 @@ function serializeHeapReference(value, path, state) {
|
|
|
6865
7014
|
}
|
|
6866
7015
|
if (!state.serializedHeapIds.has(id)) {
|
|
6867
7016
|
state.serializedHeapIds.add(id);
|
|
6868
|
-
if (
|
|
7017
|
+
if (isSandboxDate(value)) {
|
|
7018
|
+
state.heap[String(id)] = { kind: "date", time: serializedDateTime(value) };
|
|
7019
|
+
} else if (isFloat32Array(value)) {
|
|
6869
7020
|
const storage = encodeFloat32Storage(value, id, state.float32Buffers, (id2) => ({
|
|
6870
7021
|
kind: "ref",
|
|
6871
7022
|
id: id2
|
|
@@ -6922,7 +7073,7 @@ function indexHeapContainers(snapshot) {
|
|
|
6922
7073
|
const heapIds = /* @__PURE__ */ new WeakMap();
|
|
6923
7074
|
let nextId = 1;
|
|
6924
7075
|
for (const [value, stat2] of stats.entries()) {
|
|
6925
|
-
if (stat2.count > 1 || stat2.cyclic || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
7076
|
+
if (stat2.count > 1 || stat2.cyclic || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
|
|
6926
7077
|
heapIds.set(value, nextId);
|
|
6927
7078
|
nextId += 1;
|
|
6928
7079
|
}
|
|
@@ -6933,7 +7084,7 @@ function collectContainerStats(value, stats, ancestors) {
|
|
|
6933
7084
|
if (value === null || typeof value !== "object") {
|
|
6934
7085
|
return;
|
|
6935
7086
|
}
|
|
6936
|
-
if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value)) {
|
|
7087
|
+
if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
|
|
6937
7088
|
return;
|
|
6938
7089
|
}
|
|
6939
7090
|
let stat2 = stats.get(value);
|
|
@@ -7069,6 +7220,10 @@ function validateDumpHeap(root, state) {
|
|
|
7069
7220
|
addUnique(heapIds, id, path);
|
|
7070
7221
|
const entry = requireRecord(value, path);
|
|
7071
7222
|
validateErrorType(entry, path);
|
|
7223
|
+
if (entry.kind === "date") {
|
|
7224
|
+
validateDateRecord(entry, path);
|
|
7225
|
+
continue;
|
|
7226
|
+
}
|
|
7072
7227
|
if (entry.kind === "float32array") {
|
|
7073
7228
|
validateFloat32Storage(entry);
|
|
7074
7229
|
requireRecord(entry.entries, `${path}.entries`);
|
|
@@ -7226,6 +7381,14 @@ function validateGeneratorShape(record2, path, state) {
|
|
|
7226
7381
|
}
|
|
7227
7382
|
});
|
|
7228
7383
|
}
|
|
7384
|
+
function validateDateRecord(record2, path) {
|
|
7385
|
+
if (Object.keys(record2).length !== 2) fail("invalidValue", path, "invalid Date fields");
|
|
7386
|
+
try {
|
|
7387
|
+
restoreDateTime(record2.time);
|
|
7388
|
+
} catch {
|
|
7389
|
+
fail("invalidValue", `${path}.time`, "invalid Date epoch");
|
|
7390
|
+
}
|
|
7391
|
+
}
|
|
7229
7392
|
function validateArrayHeap(record2, path, state) {
|
|
7230
7393
|
if (Object.hasOwn(record2, "items")) {
|
|
7231
7394
|
requireArray(record2.items, `${path}.items`, state);
|
|
@@ -7309,7 +7472,7 @@ function validateGenericValue(value, path, depth, state) {
|
|
|
7309
7472
|
if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
|
|
7310
7473
|
fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
|
|
7311
7474
|
}
|
|
7312
|
-
if (state.dataPropertiesOnly &&
|
|
7475
|
+
if (state.dataPropertiesOnly && types3.isProxy(value)) {
|
|
7313
7476
|
fail("invalidType", path, "proxy objects are not snapshot data");
|
|
7314
7477
|
}
|
|
7315
7478
|
if (depth > state.limits.maxDepth)
|
|
@@ -9367,6 +9530,7 @@ function createSandboxClosure(input) {
|
|
|
9367
9530
|
if (input.sandbox === true) {
|
|
9368
9531
|
Object.defineProperty(closure, "sandbox", { value: true });
|
|
9369
9532
|
}
|
|
9533
|
+
if (input.generator === true) Object.defineProperty(closure, "generator", { value: true });
|
|
9370
9534
|
if (input.length !== void 0) {
|
|
9371
9535
|
Object.defineProperty(closure, "length", { value: input.length });
|
|
9372
9536
|
}
|
|
@@ -9552,6 +9716,10 @@ function measureSandboxData(values, options = {}) {
|
|
|
9552
9716
|
assertSandboxDataDepth(depth);
|
|
9553
9717
|
seen.add(value);
|
|
9554
9718
|
usage += 1;
|
|
9719
|
+
if (isSandboxDate(value)) {
|
|
9720
|
+
usage += 8;
|
|
9721
|
+
return;
|
|
9722
|
+
}
|
|
9555
9723
|
if (isGuestHostObject(value)) {
|
|
9556
9724
|
for (const key of getHostObjectKeys(value)) usage += key.length + 1;
|
|
9557
9725
|
return;
|
|
@@ -9650,7 +9818,7 @@ function measureSandboxData(values, options = {}) {
|
|
|
9650
9818
|
function reconcileCompiledValues(budget, values, compilation, parent, escaping = []) {
|
|
9651
9819
|
while (parent?.closed) parent = parent.parent;
|
|
9652
9820
|
const included = /* @__PURE__ */ new Set();
|
|
9653
|
-
const usage = measureSandboxData(values, { compileTickets: included });
|
|
9821
|
+
const usage = measureSandboxData([...values, ...budget.retainedValues()], { compileTickets: included });
|
|
9654
9822
|
const kept = /* @__PURE__ */ new Set();
|
|
9655
9823
|
if (parent !== void 0) measureSandboxData(escaping, { compileTickets: kept });
|
|
9656
9824
|
const transferred = /* @__PURE__ */ new Set();
|
|
@@ -9746,6 +9914,13 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
|
|
|
9746
9914
|
}
|
|
9747
9915
|
return sandboxPromise;
|
|
9748
9916
|
}
|
|
9917
|
+
if (nodeTypes.isDate(value)) {
|
|
9918
|
+
const existing = state.seen.get(value);
|
|
9919
|
+
if (existing !== void 0) return existing;
|
|
9920
|
+
const copy = copyNativeDate(value);
|
|
9921
|
+
state.seen.set(value, copy);
|
|
9922
|
+
return copy;
|
|
9923
|
+
}
|
|
9749
9924
|
if (isFloat32Array(value)) {
|
|
9750
9925
|
const existing = state.seen.get(value);
|
|
9751
9926
|
if (existing !== void 0) return existing;
|
|
@@ -9905,6 +10080,13 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
|
|
|
9905
10080
|
if (!Object.isExtensible(value)) Object.preventExtensions(copy);
|
|
9906
10081
|
return copy;
|
|
9907
10082
|
}
|
|
10083
|
+
if (isSandboxDate(value)) {
|
|
10084
|
+
const existing = state.seen.get(value);
|
|
10085
|
+
if (existing !== void 0) return existing;
|
|
10086
|
+
const copy = exportDate(value);
|
|
10087
|
+
state.seen.set(value, copy);
|
|
10088
|
+
return copy;
|
|
10089
|
+
}
|
|
9908
10090
|
if (isSandboxClosure(value)) {
|
|
9909
10091
|
if (options.wrapClosure === void 0) {
|
|
9910
10092
|
throw new TypeError(
|
|
@@ -10219,6 +10401,8 @@ function encodeReplayData(value, options = {}) {
|
|
|
10219
10401
|
id: capabilityId,
|
|
10220
10402
|
properties: child(entry.properties, "properties")
|
|
10221
10403
|
};
|
|
10404
|
+
} else if (isSandboxDate(entry)) {
|
|
10405
|
+
nodes[id] = { kind: "date", time: serializedDateTime(entry) };
|
|
10222
10406
|
} else if (isFloat32Array(entry)) {
|
|
10223
10407
|
const storage = encodeFloat32Storage(entry, id, float32Buffers, (id2) => ({
|
|
10224
10408
|
tag: "ref",
|
|
@@ -10369,6 +10553,12 @@ function decodeReplayData(input, options = {}, parent) {
|
|
|
10369
10553
|
options.onCapabilityRestored?.(capability, copy);
|
|
10370
10554
|
return copy;
|
|
10371
10555
|
}
|
|
10556
|
+
if (kind === "date") {
|
|
10557
|
+
if (Object.keys(node).length !== 2) throw new TypeError("Invalid serialized Date fields.");
|
|
10558
|
+
const result3 = restoreDateTime(own(node, "time"));
|
|
10559
|
+
restored.set(id, result3);
|
|
10560
|
+
return result3;
|
|
10561
|
+
}
|
|
10372
10562
|
if (kind === "float32array") {
|
|
10373
10563
|
if (typeof node.extensible !== "boolean")
|
|
10374
10564
|
throw new TypeError("Invalid Float32Array extensibility.");
|
|
@@ -11059,6 +11249,8 @@ function normalize(value, seen) {
|
|
|
11059
11249
|
if (seen.has(value)) throw new TypeError("Host call arguments cannot contain cycles.");
|
|
11060
11250
|
seen.add(value);
|
|
11061
11251
|
try {
|
|
11252
|
+
const date = copyNativeDate(value);
|
|
11253
|
+
if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
|
|
11062
11254
|
if (isFloat32Array(value)) {
|
|
11063
11255
|
const storage = float32Storage(value);
|
|
11064
11256
|
const properties = /* @__PURE__ */ Object.create(null);
|
|
@@ -12014,6 +12206,7 @@ var KNOWN_RUNTIME_GLOBALS = [
|
|
|
12014
12206
|
"AggregateError",
|
|
12015
12207
|
"Array",
|
|
12016
12208
|
"Boolean",
|
|
12209
|
+
"Date",
|
|
12017
12210
|
"Error",
|
|
12018
12211
|
"Infinity",
|
|
12019
12212
|
"isFinite",
|
|
@@ -17178,9 +17371,9 @@ var ASFloatingPromiseScanner = class {
|
|
|
17178
17371
|
isPromiseFactoryCall(node) {
|
|
17179
17372
|
return this.isPromiseStaticMethodCall(node, PROMISE_FACTORIES);
|
|
17180
17373
|
}
|
|
17181
|
-
isPromiseStaticMethodCall(node,
|
|
17374
|
+
isPromiseStaticMethodCall(node, methodNames2) {
|
|
17182
17375
|
const member = node.callee.type === "MemberExpression" ? node.callee : void 0;
|
|
17183
|
-
return member !== void 0 && !member.computed && member.object.type === "Identifier" && member.object.name === "Promise" && member.property.type === "Identifier" &&
|
|
17376
|
+
return member !== void 0 && !member.computed && member.object.type === "Identifier" && member.object.name === "Promise" && member.property.type === "Identifier" && methodNames2.has(member.property.name);
|
|
17184
17377
|
}
|
|
17185
17378
|
isPromiseChainCall(node) {
|
|
17186
17379
|
const member = node.callee.type === "MemberExpression" ? node.callee : void 0;
|
|
@@ -24818,6 +25011,101 @@ function relativeIndex(value, length, fallback) {
|
|
|
24818
25011
|
return integer < 0 ? Math.max(length + integer, 0) : Math.min(integer, length);
|
|
24819
25012
|
}
|
|
24820
25013
|
|
|
25014
|
+
// packages/safe-js/src/interp/globals/date.ts
|
|
25015
|
+
var intrinsics = /* @__PURE__ */ new WeakMap();
|
|
25016
|
+
var constructors2 = /* @__PURE__ */ new WeakSet();
|
|
25017
|
+
function createDateGlobal(options) {
|
|
25018
|
+
const validateClockTime = (value) => {
|
|
25019
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || Math.abs(value) > 864e13)
|
|
25020
|
+
throw new TypeError("Date clock must return a finite integer epoch within the Date range.");
|
|
25021
|
+
return value;
|
|
25022
|
+
};
|
|
25023
|
+
const readNow = declareHostOperation(
|
|
25024
|
+
() => {
|
|
25025
|
+
options.budget.visitNode();
|
|
25026
|
+
const value = options.clock?.now === void 0 ? Date.now() : options.clock.now();
|
|
25027
|
+
return validateClockTime(value);
|
|
25028
|
+
},
|
|
25029
|
+
"re-issue",
|
|
25030
|
+
{
|
|
25031
|
+
onReplay: (_args, outcome) => {
|
|
25032
|
+
if (outcome.status === "fulfilled") {
|
|
25033
|
+
const time = validateClockTime(outcome.value);
|
|
25034
|
+
options.clock?.restore?.({ next: time + 1 });
|
|
25035
|
+
}
|
|
25036
|
+
}
|
|
25037
|
+
}
|
|
25038
|
+
);
|
|
25039
|
+
const now = wrapCallerInjectedBindings({ now: readNow }, { ...options, moduleId: "<Date>" }).now;
|
|
25040
|
+
const prototype = createSandboxDate(NaN);
|
|
25041
|
+
const constructor = createSandboxClosure({
|
|
25042
|
+
sandbox: true,
|
|
25043
|
+
name: "Date",
|
|
25044
|
+
length: 7,
|
|
25045
|
+
call: async (_args, context) => options.budget.allocateString(
|
|
25046
|
+
dateString(createSandboxDate(Number(await now.call([], context))))
|
|
25047
|
+
),
|
|
25048
|
+
construct: async (args, context) => {
|
|
25049
|
+
let time;
|
|
25050
|
+
if (args.length === 0) time = Number(await now.call([], context));
|
|
25051
|
+
else if (args.length > 1) time = dateFromParts(args, false);
|
|
25052
|
+
else if (isSandboxDate(args[0])) time = dateTime(args[0]);
|
|
25053
|
+
else if (typeof args[0] === "string") time = parseDate(args[0], options.budget);
|
|
25054
|
+
else time = dateNumber(args[0]);
|
|
25055
|
+
options.budget.chargeDataUsage(9);
|
|
25056
|
+
return createSandboxDate(time);
|
|
25057
|
+
},
|
|
25058
|
+
properties: {
|
|
25059
|
+
now,
|
|
25060
|
+
prototype,
|
|
25061
|
+
parse: createSandboxClosure({
|
|
25062
|
+
sandbox: true,
|
|
25063
|
+
name: "parse",
|
|
25064
|
+
length: 1,
|
|
25065
|
+
call: ([value]) => parseDate(value, options.budget)
|
|
25066
|
+
}),
|
|
25067
|
+
UTC: createSandboxClosure({
|
|
25068
|
+
sandbox: true,
|
|
25069
|
+
name: "UTC",
|
|
25070
|
+
length: 7,
|
|
25071
|
+
call: (args) => dateFromParts(args, true)
|
|
25072
|
+
})
|
|
25073
|
+
}
|
|
25074
|
+
});
|
|
25075
|
+
const methods = /* @__PURE__ */ new Map();
|
|
25076
|
+
for (const [name, method] of dateMethods)
|
|
25077
|
+
methods.set(
|
|
25078
|
+
name,
|
|
25079
|
+
createSandboxClosure({
|
|
25080
|
+
sandbox: true,
|
|
25081
|
+
name,
|
|
25082
|
+
length: method.length,
|
|
25083
|
+
call: (args, context) => {
|
|
25084
|
+
const receiver = context?.thisValue;
|
|
25085
|
+
if (!isSandboxDate(receiver))
|
|
25086
|
+
throw new TypeError(`Date#${name} requires a Date receiver.`);
|
|
25087
|
+
options.budget.visitNode();
|
|
25088
|
+
const value = method.invoke(receiver, args);
|
|
25089
|
+
return typeof value === "string" ? options.budget.allocateString(value) : value;
|
|
25090
|
+
}
|
|
25091
|
+
})
|
|
25092
|
+
);
|
|
25093
|
+
constructors2.add(constructor);
|
|
25094
|
+
intrinsics.set(options.compileOwner ?? options.budget, { constructor, prototype, methods });
|
|
25095
|
+
return constructor;
|
|
25096
|
+
}
|
|
25097
|
+
function isDateConstructor(value) {
|
|
25098
|
+
return typeof value === "object" && value !== null && constructors2.has(value);
|
|
25099
|
+
}
|
|
25100
|
+
function getDateMember(property, budget, owner) {
|
|
25101
|
+
const state = intrinsics.get(owner ?? budget);
|
|
25102
|
+
return property === "constructor" ? state?.constructor : state?.methods.get(String(property));
|
|
25103
|
+
}
|
|
25104
|
+
function getDatePrototype(value, budget, owner) {
|
|
25105
|
+
const prototype = intrinsics.get(owner ?? budget)?.prototype;
|
|
25106
|
+
return prototype === value ? null : prototype ?? null;
|
|
25107
|
+
}
|
|
25108
|
+
|
|
24821
25109
|
// packages/safe-js/src/interp/scope.ts
|
|
24822
25110
|
var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
|
|
24823
25111
|
var Scope = class _Scope {
|
|
@@ -25367,6 +25655,9 @@ async function evaluateObjectExpression(node, context) {
|
|
|
25367
25655
|
return value;
|
|
25368
25656
|
}
|
|
25369
25657
|
if (isObjectPrototypeSetterProperty(property, key.value)) {
|
|
25658
|
+
if (value.value === null || typeof value.value === "object") {
|
|
25659
|
+
setSandboxPrototype(object, value.value, context.budget);
|
|
25660
|
+
}
|
|
25370
25661
|
continue;
|
|
25371
25662
|
}
|
|
25372
25663
|
defineSandboxProperty(object, String(key.value), value.value);
|
|
@@ -26171,7 +26462,7 @@ function forInKeys(object, budget) {
|
|
|
26171
26462
|
const keys = [];
|
|
26172
26463
|
const seen = /* @__PURE__ */ new Set();
|
|
26173
26464
|
let depth = 0;
|
|
26174
|
-
for (let current = object; current !== null; current = getSandboxPrototype(current)) {
|
|
26465
|
+
for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
26175
26466
|
if (depth > 0) budget.visitNode();
|
|
26176
26467
|
assertSandboxDataDepth(depth++);
|
|
26177
26468
|
const properties = isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : current;
|
|
@@ -26187,7 +26478,7 @@ function forInKeys(object, budget) {
|
|
|
26187
26478
|
function hasForInProperty(object, key, budget) {
|
|
26188
26479
|
if (isGuestHostObject(object)) return getHostObjectKeys(object).includes(key);
|
|
26189
26480
|
let depth = 0;
|
|
26190
|
-
for (let current = object; current !== null; current = getSandboxPrototype(current)) {
|
|
26481
|
+
for (let current = object; current !== null; current = getSandboxPrototype(current, budget)) {
|
|
26191
26482
|
if (depth > 0) budget.visitNode();
|
|
26192
26483
|
assertSandboxDataDepth(depth++);
|
|
26193
26484
|
const properties = isGuestClosure(current) ? materializeFunctionProperties(current) : isSandboxClosure(current) ? current.properties ?? {} : current;
|
|
@@ -26682,6 +26973,7 @@ function getPropertyValue(target, property, context) {
|
|
|
26682
26973
|
if (typeof target === "number") return getNumberMember(target, property, context.budget);
|
|
26683
26974
|
if (typeof target === "boolean") return void 0;
|
|
26684
26975
|
if (isFloat32Array(target)) return getFloat32Member(target, property, context.budget);
|
|
26976
|
+
if (isSandboxDate(target)) return getDateMember(property, context.budget, context.compilation?.owner);
|
|
26685
26977
|
if (isSandboxMap(target)) return getMapMember(target, property, createMapMethodOptions(context));
|
|
26686
26978
|
if (isSandboxSet(target)) return getSetMember(target, property, createSetMethodOptions(context));
|
|
26687
26979
|
if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
|
|
@@ -26918,6 +27210,9 @@ async function evaluateMemberCallExpression(node, context) {
|
|
|
26918
27210
|
context
|
|
26919
27211
|
);
|
|
26920
27212
|
}
|
|
27213
|
+
if (isSandboxDate(member.object)) {
|
|
27214
|
+
return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
|
|
27215
|
+
}
|
|
26921
27216
|
if (isFloat32Array(member.object)) {
|
|
26922
27217
|
return evaluateResolvedCallExpression(
|
|
26923
27218
|
node,
|
|
@@ -27170,6 +27465,7 @@ function applyBinaryOperator(node, left, right, context) {
|
|
|
27170
27465
|
return true;
|
|
27171
27466
|
}
|
|
27172
27467
|
if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
|
|
27468
|
+
if (isDateConstructor(right)) return isSandboxDate(left) && getDatePrototype(left, context.budget, context.compilation?.owner) !== null;
|
|
27173
27469
|
if (isSandboxSetConstructor(right) && isSandboxSet(left)) {
|
|
27174
27470
|
return true;
|
|
27175
27471
|
}
|
|
@@ -27183,7 +27479,7 @@ function applyBinaryOperator(node, left, right, context) {
|
|
|
27183
27479
|
throw new TypeError("Function has a non-object prototype in instanceof check.");
|
|
27184
27480
|
}
|
|
27185
27481
|
let depth = 0;
|
|
27186
|
-
for (let current = getSandboxPrototype(left); current !== null; current = getSandboxPrototype(current)) {
|
|
27482
|
+
for (let current = getSandboxPrototype(left, context.budget); current !== null; current = getSandboxPrototype(current, context.budget)) {
|
|
27187
27483
|
context.budget.visitNode();
|
|
27188
27484
|
assertSandboxDataDepth(depth++);
|
|
27189
27485
|
if (current === prototype) return true;
|
|
@@ -27233,8 +27529,8 @@ function applyAdditionOperator(left, right, context) {
|
|
|
27233
27529
|
return toNumber(leftPrimitive) + toNumber(rightPrimitive);
|
|
27234
27530
|
}
|
|
27235
27531
|
function compareRelational(left, right, operator) {
|
|
27236
|
-
const leftPrimitive = toPrimitive(left);
|
|
27237
|
-
const rightPrimitive = toPrimitive(right);
|
|
27532
|
+
const leftPrimitive = isSandboxDate(left) ? dateTime(left) : toPrimitive(left);
|
|
27533
|
+
const rightPrimitive = isSandboxDate(right) ? dateTime(right) : toPrimitive(right);
|
|
27238
27534
|
if (typeof leftPrimitive === "string" && typeof rightPrimitive === "string") {
|
|
27239
27535
|
switch (operator) {
|
|
27240
27536
|
case "<":
|
|
@@ -27317,6 +27613,7 @@ function toPrimitive(value) {
|
|
|
27317
27613
|
return toString(value);
|
|
27318
27614
|
}
|
|
27319
27615
|
async function toNumericPrimitive(value, context) {
|
|
27616
|
+
if (isSandboxDate(value)) return dateTime(value);
|
|
27320
27617
|
if (isPrimitiveCoercionType(getCoercionType(value))) {
|
|
27321
27618
|
return value;
|
|
27322
27619
|
}
|
|
@@ -27346,6 +27643,7 @@ async function toNumericPrimitive(value, context) {
|
|
|
27346
27643
|
return toString(value);
|
|
27347
27644
|
}
|
|
27348
27645
|
function toNumber(value) {
|
|
27646
|
+
if (isSandboxDate(value)) return dateTime(value);
|
|
27349
27647
|
if (typeof value === "number") {
|
|
27350
27648
|
return value;
|
|
27351
27649
|
}
|
|
@@ -27364,6 +27662,7 @@ function toNumber(value) {
|
|
|
27364
27662
|
return toNumber(toPrimitive(value));
|
|
27365
27663
|
}
|
|
27366
27664
|
function toString(value) {
|
|
27665
|
+
if (isSandboxDate(value)) return dateString(value);
|
|
27367
27666
|
if (Array.isArray(value)) {
|
|
27368
27667
|
return value.map((entry) => entry === null || entry === void 0 ? "" : toString(entry)).join(",");
|
|
27369
27668
|
}
|
|
@@ -27394,7 +27693,7 @@ function getMemberValue(target, property, context) {
|
|
|
27394
27693
|
return getPropertyValue(current, property, context);
|
|
27395
27694
|
}
|
|
27396
27695
|
if (Object.hasOwn(current, String(property))) return current[String(property)];
|
|
27397
|
-
current = getSandboxPrototype(current);
|
|
27696
|
+
current = getSandboxPrototype(current, context.budget);
|
|
27398
27697
|
if (current !== null) {
|
|
27399
27698
|
context.budget.visitNode();
|
|
27400
27699
|
assertSandboxDataDepth(++depth);
|
|
@@ -27409,6 +27708,7 @@ function getArrayMemberValue(target, property, context) {
|
|
|
27409
27708
|
return getArrayMember(target, property, createArrayMethodOptions(context));
|
|
27410
27709
|
}
|
|
27411
27710
|
function setSandboxProperty(target, property, value, budget) {
|
|
27711
|
+
if (isSandboxDate(target)) throw new TypeError("Date own properties are not supported.");
|
|
27412
27712
|
if (isGuestHostObject(target)) {
|
|
27413
27713
|
setHostObjectMember(target, String(property), value);
|
|
27414
27714
|
return;
|
|
@@ -27443,7 +27743,7 @@ function setSandboxProperty(target, property, value, budget) {
|
|
|
27443
27743
|
} else {
|
|
27444
27744
|
if (typeof prototypeOwner === "object" && prototypeOwner !== null) {
|
|
27445
27745
|
let depth = 0;
|
|
27446
|
-
for (let prototype = getSandboxPrototype(prototypeOwner); prototype !== null; prototype = getSandboxPrototype(prototype)) {
|
|
27746
|
+
for (let prototype = getSandboxPrototype(prototypeOwner, budget); prototype !== null; prototype = getSandboxPrototype(prototype, budget)) {
|
|
27447
27747
|
budget.visitNode();
|
|
27448
27748
|
assertSandboxDataDepth(depth++);
|
|
27449
27749
|
const properties = isSandboxClosure(prototype) ? prototype.properties : prototype;
|
|
@@ -27819,6 +28119,7 @@ function createInterpretedClosure(node, context, evaluateNode2) {
|
|
|
27819
28119
|
function createGeneratorClosure(node, context, evaluateNode2) {
|
|
27820
28120
|
return createSandboxClosure({
|
|
27821
28121
|
guest: true,
|
|
28122
|
+
generator: true,
|
|
27822
28123
|
sandbox: true,
|
|
27823
28124
|
length: getFunctionLength(node.params),
|
|
27824
28125
|
...node.id === void 0 ? {} : { name: node.id.name },
|
|
@@ -28676,6 +28977,14 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
|
|
|
28676
28977
|
state
|
|
28677
28978
|
);
|
|
28678
28979
|
}
|
|
28980
|
+
const date = copyNativeDate(value);
|
|
28981
|
+
if (date !== void 0) {
|
|
28982
|
+
const existing = state.seen.get(value);
|
|
28983
|
+
if (existing !== void 0) return existing;
|
|
28984
|
+
budget.chargeDataUsage(9);
|
|
28985
|
+
state.seen.set(value, date);
|
|
28986
|
+
return date;
|
|
28987
|
+
}
|
|
28679
28988
|
if (isFloat32Array(value)) {
|
|
28680
28989
|
const existing = state.seen.get(value);
|
|
28681
28990
|
if (existing !== void 0) return existing;
|
|
@@ -29077,7 +29386,7 @@ function createReplayableRandom(options = {}) {
|
|
|
29077
29386
|
|
|
29078
29387
|
// packages/safe-js/src/realm.ts
|
|
29079
29388
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
29080
|
-
import { types as
|
|
29389
|
+
import { types as types4 } from "node:util";
|
|
29081
29390
|
|
|
29082
29391
|
// packages/safe-js/src/interp/globals/console-json.ts
|
|
29083
29392
|
function createConsoleJsonGlobals(options) {
|
|
@@ -29191,7 +29500,9 @@ function toJsonParseText(input) {
|
|
|
29191
29500
|
}
|
|
29192
29501
|
async function stringifyProperty(key, holder, state, indent = "") {
|
|
29193
29502
|
let value = getOwnDataValue(holder, key);
|
|
29194
|
-
if (
|
|
29503
|
+
if (isSandboxDate(value)) {
|
|
29504
|
+
value = dateMethods.get("toJSON").invoke(value, []);
|
|
29505
|
+
} else if (isStringifyContainer(value)) {
|
|
29195
29506
|
const toJSON = getOwnDataValue(value, "toJSON");
|
|
29196
29507
|
if (isSandboxClosure(toJSON)) {
|
|
29197
29508
|
value = await callStringifyClosure(toJSON, [key], value, state);
|
|
@@ -29503,6 +29814,7 @@ async function stringifyObject2(value, budget, context, joining) {
|
|
|
29503
29814
|
}
|
|
29504
29815
|
}
|
|
29505
29816
|
async function defaultToString(value, budget, context, joining) {
|
|
29817
|
+
if (isSandboxDate(value)) return budget.allocateString(dateString(value));
|
|
29506
29818
|
if (Array.isArray(value) || isFloat32Array(value)) {
|
|
29507
29819
|
if (Object.hasOwn(value, "join")) {
|
|
29508
29820
|
const join = ownDataValue(value, "join");
|
|
@@ -29546,10 +29858,138 @@ function ownDataValue(value, name) {
|
|
|
29546
29858
|
return descriptor?.value;
|
|
29547
29859
|
}
|
|
29548
29860
|
|
|
29861
|
+
// packages/safe-js/src/interp/globals/object.ts
|
|
29862
|
+
function createObjectGlobal(methods, budget) {
|
|
29863
|
+
const construct = ([value]) => {
|
|
29864
|
+
if (value === null || value === void 0) {
|
|
29865
|
+
budget.chargeDataUsage(1);
|
|
29866
|
+
return /* @__PURE__ */ Object.create(null);
|
|
29867
|
+
}
|
|
29868
|
+
if (typeof value !== "object") throw new TypeError("Object primitive boxing is not supported.");
|
|
29869
|
+
return value;
|
|
29870
|
+
};
|
|
29871
|
+
const constructor = createSandboxClosure({
|
|
29872
|
+
guest: true,
|
|
29873
|
+
sandbox: true,
|
|
29874
|
+
name: "Object",
|
|
29875
|
+
length: 1,
|
|
29876
|
+
call: construct,
|
|
29877
|
+
construct
|
|
29878
|
+
});
|
|
29879
|
+
const properties = materializeFunctionProperties(constructor);
|
|
29880
|
+
const prototype = properties.prototype;
|
|
29881
|
+
Object.defineProperty(properties, "prototype", { writable: false });
|
|
29882
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
29883
|
+
Object.defineProperty(properties, name, { value: method, writable: true, configurable: true });
|
|
29884
|
+
}
|
|
29885
|
+
const prototypeMethods = {
|
|
29886
|
+
toString: createSandboxClosure({
|
|
29887
|
+
sandbox: true,
|
|
29888
|
+
name: "toString",
|
|
29889
|
+
length: 0,
|
|
29890
|
+
call: (_args, context) => budget.allocateString(`[object ${typeTag(context?.thisValue)}]`)
|
|
29891
|
+
}),
|
|
29892
|
+
valueOf: createSandboxClosure({
|
|
29893
|
+
sandbox: true,
|
|
29894
|
+
name: "valueOf",
|
|
29895
|
+
length: 0,
|
|
29896
|
+
call: (_args, context) => {
|
|
29897
|
+
const value = requireReceiver(context?.thisValue);
|
|
29898
|
+
if (typeof value !== "object")
|
|
29899
|
+
throw new TypeError("Object primitive boxing is not supported.");
|
|
29900
|
+
return value;
|
|
29901
|
+
}
|
|
29902
|
+
}),
|
|
29903
|
+
hasOwnProperty: createSandboxClosure({
|
|
29904
|
+
sandbox: true,
|
|
29905
|
+
name: "hasOwnProperty",
|
|
29906
|
+
length: 1,
|
|
29907
|
+
call: async ([key], context) => hasOwnSandboxProperty(
|
|
29908
|
+
requireReceiver(context?.thisValue),
|
|
29909
|
+
await sandboxString(key, budget, context),
|
|
29910
|
+
false
|
|
29911
|
+
)
|
|
29912
|
+
}),
|
|
29913
|
+
propertyIsEnumerable: createSandboxClosure({
|
|
29914
|
+
sandbox: true,
|
|
29915
|
+
name: "propertyIsEnumerable",
|
|
29916
|
+
length: 1,
|
|
29917
|
+
call: async ([key], context) => hasOwnSandboxProperty(
|
|
29918
|
+
requireReceiver(context?.thisValue),
|
|
29919
|
+
await sandboxString(key, budget, context),
|
|
29920
|
+
true
|
|
29921
|
+
)
|
|
29922
|
+
}),
|
|
29923
|
+
isPrototypeOf: createSandboxClosure({
|
|
29924
|
+
sandbox: true,
|
|
29925
|
+
name: "isPrototypeOf",
|
|
29926
|
+
length: 1,
|
|
29927
|
+
call: ([value], context) => {
|
|
29928
|
+
if (typeof value !== "object" || value === null) return false;
|
|
29929
|
+
const receiver = requireReceiver(context?.thisValue);
|
|
29930
|
+
let depth = 0;
|
|
29931
|
+
for (let current = getSandboxPrototype(value, budget); current !== null; current = getSandboxPrototype(current, budget)) {
|
|
29932
|
+
budget.visitNode();
|
|
29933
|
+
assertSandboxDataDepth(depth++);
|
|
29934
|
+
if (current === receiver) return true;
|
|
29935
|
+
}
|
|
29936
|
+
return false;
|
|
29937
|
+
}
|
|
29938
|
+
})
|
|
29939
|
+
};
|
|
29940
|
+
for (const [name, method] of Object.entries(prototypeMethods)) {
|
|
29941
|
+
Object.defineProperty(prototype, name, { value: method, writable: true, configurable: true });
|
|
29942
|
+
}
|
|
29943
|
+
markDescriptorObject(prototype);
|
|
29944
|
+
installObjectPrototype(budget, prototype, constructor);
|
|
29945
|
+
return constructor;
|
|
29946
|
+
}
|
|
29947
|
+
function requireReceiver(value) {
|
|
29948
|
+
if (value === null || value === void 0)
|
|
29949
|
+
throw new TypeError("Object method requires a non-null receiver.");
|
|
29950
|
+
return value;
|
|
29951
|
+
}
|
|
29952
|
+
function hasOwnSandboxProperty(value, key, enumerable) {
|
|
29953
|
+
requireReceiver(value);
|
|
29954
|
+
if (isGuestHostObject(value)) return getHostObjectKeys(value).includes(key);
|
|
29955
|
+
let properties;
|
|
29956
|
+
if (isGuestClosure(value)) properties = materializeFunctionProperties(value);
|
|
29957
|
+
else if (isSandboxClosure(value)) {
|
|
29958
|
+
if (key === "length" || key === "name") return !enumerable;
|
|
29959
|
+
properties = value.properties ?? /* @__PURE__ */ Object.create(null);
|
|
29960
|
+
} else if (isSandboxMap(value) || isSandboxSet(value) || isSandboxPromise(value) || isSandboxGenerator(value))
|
|
29961
|
+
return false;
|
|
29962
|
+
else if (isSandboxRegex(value)) return key === "lastIndex" && !enumerable;
|
|
29963
|
+
else properties = Object(value);
|
|
29964
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
29965
|
+
return descriptor !== void 0 && (!enumerable || descriptor.enumerable === true);
|
|
29966
|
+
}
|
|
29967
|
+
function typeTag(value) {
|
|
29968
|
+
if (value === void 0) return "Undefined";
|
|
29969
|
+
if (value === null) return "Null";
|
|
29970
|
+
if (typeof value === "string") return "String";
|
|
29971
|
+
if (typeof value === "number") return "Number";
|
|
29972
|
+
if (typeof value === "boolean") return "Boolean";
|
|
29973
|
+
if (isSandboxClosure(value)) {
|
|
29974
|
+
while (value.boundTarget !== void 0) value = value.boundTarget;
|
|
29975
|
+
return value.generator ? "GeneratorFunction" : value.async ? "AsyncFunction" : "Function";
|
|
29976
|
+
}
|
|
29977
|
+
if (Array.isArray(value)) return "Array";
|
|
29978
|
+
if (isSandboxDate(value)) return "Date";
|
|
29979
|
+
if (isSandboxErrorConstructorInstance(value, "Error")) return "Error";
|
|
29980
|
+
if (isSandboxRegex(value)) return "RegExp";
|
|
29981
|
+
if (isSandboxMap(value)) return "Map";
|
|
29982
|
+
if (isSandboxSet(value)) return "Set";
|
|
29983
|
+
if (isSandboxPromise(value)) return "Promise";
|
|
29984
|
+
if (isSandboxGenerator(value)) return "Generator";
|
|
29985
|
+
if (isFloat32Array(value)) return "Float32Array";
|
|
29986
|
+
return "Object";
|
|
29987
|
+
}
|
|
29988
|
+
|
|
29549
29989
|
// packages/safe-js/src/interp/globals/object-array.ts
|
|
29550
29990
|
function createObjectArrayGlobals(options) {
|
|
29551
29991
|
return {
|
|
29552
|
-
Object: {
|
|
29992
|
+
Object: createObjectGlobal({
|
|
29553
29993
|
keys: createSandboxClosure({
|
|
29554
29994
|
sandbox: true,
|
|
29555
29995
|
call: ([value]) => budgetSandboxValue2(getOwnEnumerableKeys(value), options.budget),
|
|
@@ -29567,7 +30007,11 @@ function createObjectArrayGlobals(options) {
|
|
|
29567
30007
|
}),
|
|
29568
30008
|
hasOwn: createSandboxClosure({
|
|
29569
30009
|
sandbox: true,
|
|
29570
|
-
call: ([value, key]
|
|
30010
|
+
call: ([value, key], context) => {
|
|
30011
|
+
if (value === null || value === void 0) throw new TypeError("Cannot convert undefined or null to object.");
|
|
30012
|
+
const name = sandboxString(key, options.budget, context);
|
|
30013
|
+
return typeof name === "string" ? hasOwnSandboxProperty(value, name, false) : name.then((property) => hasOwnSandboxProperty(value, property, false));
|
|
30014
|
+
},
|
|
29571
30015
|
name: "hasOwn"
|
|
29572
30016
|
}),
|
|
29573
30017
|
getOwnPropertyDescriptor: createSandboxClosure({
|
|
@@ -29606,8 +30050,9 @@ function createObjectArrayGlobals(options) {
|
|
|
29606
30050
|
getPrototypeOf: createSandboxClosure({
|
|
29607
30051
|
sandbox: true,
|
|
29608
30052
|
call: ([value]) => {
|
|
30053
|
+
if (isSandboxDate(value)) return getDatePrototype(value, options.budget, options.compileOwner);
|
|
29609
30054
|
objectProperties(value);
|
|
29610
|
-
return getSandboxPrototype(value);
|
|
30055
|
+
return getSandboxPrototype(value, options.budget);
|
|
29611
30056
|
},
|
|
29612
30057
|
name: "getPrototypeOf"
|
|
29613
30058
|
}),
|
|
@@ -29682,7 +30127,7 @@ function createObjectArrayGlobals(options) {
|
|
|
29682
30127
|
call: ([target, ...sources]) => assignSandboxValues(target, sources, options.budget),
|
|
29683
30128
|
name: "assign"
|
|
29684
30129
|
})
|
|
29685
|
-
},
|
|
30130
|
+
}, options.budget),
|
|
29686
30131
|
Array: createSandboxClosure({
|
|
29687
30132
|
sandbox: true,
|
|
29688
30133
|
call: (args) => createArrayFromConstructorArgs(args, options.budget),
|
|
@@ -29730,7 +30175,7 @@ function createObjectArrayGlobals(options) {
|
|
|
29730
30175
|
}),
|
|
29731
30176
|
Number: createSandboxClosure({
|
|
29732
30177
|
sandbox: true,
|
|
29733
|
-
call: ([value]) => Number(value),
|
|
30178
|
+
call: ([value]) => isSandboxDate(value) ? dateTime(value) : Number(value),
|
|
29734
30179
|
name: "Number",
|
|
29735
30180
|
properties: {
|
|
29736
30181
|
isFinite: createSandboxClosure({
|
|
@@ -29830,6 +30275,10 @@ function assignSandboxValues(target, sources, budget) {
|
|
|
29830
30275
|
return target;
|
|
29831
30276
|
}
|
|
29832
30277
|
function objectProperties(value, mutable = false) {
|
|
30278
|
+
if (isSandboxDate(value)) {
|
|
30279
|
+
if (mutable) throw new TypeError("Date own properties and prototypes are not supported.");
|
|
30280
|
+
return value;
|
|
30281
|
+
}
|
|
29833
30282
|
if (isGuestHostObject(value)) throw new TypeError("Live host object descriptors are not supported.");
|
|
29834
30283
|
if (isGuestClosure(value)) return materializeFunctionProperties(value);
|
|
29835
30284
|
if (isSandboxClosure(value)) {
|
|
@@ -29951,6 +30400,7 @@ function createBuiltinBindings(options) {
|
|
|
29951
30400
|
...createConsoleJsonGlobals(options),
|
|
29952
30401
|
...createCollectionGlobals(options),
|
|
29953
30402
|
Float32Array: createFloat32ArrayGlobal(options.budget),
|
|
30403
|
+
Date: createDateGlobal(options),
|
|
29954
30404
|
...createErrorGlobals(options),
|
|
29955
30405
|
...createMathGlobals({ random: options.random }),
|
|
29956
30406
|
...createObjectArrayGlobals(options),
|
|
@@ -30132,7 +30582,7 @@ var RealmState = class {
|
|
|
30132
30582
|
throw new TypeError("Realm limits must be positive safe integers with supported names.");
|
|
30133
30583
|
this.limits[name] = Number(value);
|
|
30134
30584
|
}
|
|
30135
|
-
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) ||
|
|
30585
|
+
if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types4.isProxy(options.extensions)))
|
|
30136
30586
|
throw new TypeError("Extensions must be a registration array.");
|
|
30137
30587
|
const registrations = options.extensions ?? [];
|
|
30138
30588
|
const extensions = [];
|
|
@@ -30169,6 +30619,7 @@ var RealmState = class {
|
|
|
30169
30619
|
budget: this.budget,
|
|
30170
30620
|
compileOwner: this.lease.owner,
|
|
30171
30621
|
sink: options.sink,
|
|
30622
|
+
clock: options.clock,
|
|
30172
30623
|
random: createReplayableRandom({ seed: options.randomSeed }).next
|
|
30173
30624
|
});
|
|
30174
30625
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -30203,6 +30654,7 @@ var RealmState = class {
|
|
|
30203
30654
|
this.budget.setRetainedValues(this, this.retainedRoots);
|
|
30204
30655
|
this.tracker.onFatalRejection((error) => this.poison(error));
|
|
30205
30656
|
} catch (error) {
|
|
30657
|
+
releaseObjectPrototype(this.budget);
|
|
30206
30658
|
this.compilation.dispose();
|
|
30207
30659
|
this.lease.release();
|
|
30208
30660
|
throw error;
|
|
@@ -30350,7 +30802,7 @@ var RealmState = class {
|
|
|
30350
30802
|
return this.phase.run(phase, () => {
|
|
30351
30803
|
try {
|
|
30352
30804
|
const result = call();
|
|
30353
|
-
if (
|
|
30805
|
+
if (types4.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
|
|
30354
30806
|
return Promise.resolve(result).then(
|
|
30355
30807
|
async (value) => {
|
|
30356
30808
|
await Promise.allSettled(phase.pending);
|
|
@@ -30407,7 +30859,7 @@ var RealmState = class {
|
|
|
30407
30859
|
chargeWork: this.chargeWork,
|
|
30408
30860
|
read: (operation) => {
|
|
30409
30861
|
const value = this.invokeHost(operation, operation);
|
|
30410
|
-
if (
|
|
30862
|
+
if (types4.isPromise(value)) {
|
|
30411
30863
|
void Promise.resolve(value).catch(() => void 0);
|
|
30412
30864
|
throw new TypeError("Live property getters must be synchronous.");
|
|
30413
30865
|
}
|
|
@@ -30415,7 +30867,7 @@ var RealmState = class {
|
|
|
30415
30867
|
},
|
|
30416
30868
|
write: (operation, value) => {
|
|
30417
30869
|
const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
|
|
30418
|
-
if (
|
|
30870
|
+
if (types4.isPromise(result)) {
|
|
30419
30871
|
void Promise.resolve(result).catch(() => void 0);
|
|
30420
30872
|
throw new TypeError("Live property setters must be synchronous.");
|
|
30421
30873
|
}
|
|
@@ -30608,7 +31060,7 @@ var RealmState = class {
|
|
|
30608
31060
|
}
|
|
30609
31061
|
});
|
|
30610
31062
|
const output = getExtensionSetup(extension)(context);
|
|
30611
|
-
if (
|
|
31063
|
+
if (types4.isPromise(output)) {
|
|
30612
31064
|
void Promise.resolve(output).catch(() => void 0);
|
|
30613
31065
|
throw new TypeError("Extension setup must be synchronous.");
|
|
30614
31066
|
}
|
|
@@ -30769,6 +31221,7 @@ var RealmState = class {
|
|
|
30769
31221
|
for (const reference of this.guestReferences.keys()) revokeGuestReference(reference, this);
|
|
30770
31222
|
this.guestReferences.clear();
|
|
30771
31223
|
this.budget.setRetainedValues(this, void 0);
|
|
31224
|
+
releaseObjectPrototype(this.budget);
|
|
30772
31225
|
this.disposal = (async () => {
|
|
30773
31226
|
const errors = [];
|
|
30774
31227
|
for (const cleanup of this.cleanups.splice(0).reverse()) {
|
|
@@ -30795,7 +31248,7 @@ var RealmState = class {
|
|
|
30795
31248
|
};
|
|
30796
31249
|
function readModules(input) {
|
|
30797
31250
|
const entries = (value, label) => {
|
|
30798
|
-
if (
|
|
31251
|
+
if (types4.isMap(value) && !types4.isProxy(value)) {
|
|
30799
31252
|
const result = [...Map.prototype.entries.call(value)];
|
|
30800
31253
|
if (result.length > 4096 || result.some(([key]) => typeof key !== "string" || key.length === 0))
|
|
30801
31254
|
throw new TypeError(`${label} requires bounded string keys.`);
|
|
@@ -30869,6 +31322,7 @@ function readRealmOptions(value, oneShot = false) {
|
|
|
30869
31322
|
"signal",
|
|
30870
31323
|
"sink",
|
|
30871
31324
|
"randomSeed",
|
|
31325
|
+
"clock",
|
|
30872
31326
|
"limits"
|
|
30873
31327
|
]);
|
|
30874
31328
|
for (const [key, entry] of Object.entries(options)) {
|
|
@@ -31515,7 +31969,7 @@ function run(source, options = {}) {
|
|
|
31515
31969
|
lifecycle
|
|
31516
31970
|
})
|
|
31517
31971
|
);
|
|
31518
|
-
const builtinBindings = createBuiltinBindings({ compileOwner: operation.owner, budget, hostCalls, sink: options.sink, random: random?.generator.next });
|
|
31972
|
+
const builtinBindings = createBuiltinBindings({ compileOwner: operation.owner, budget, hostCalls, sink: options.sink, random: random?.generator.next, clock: options.clock });
|
|
31519
31973
|
const importMeta = convertInitialInput(
|
|
31520
31974
|
() => deepCopyToSandbox(options.importMeta ?? {})
|
|
31521
31975
|
);
|
|
@@ -31776,6 +32230,7 @@ function run(source, options = {}) {
|
|
|
31776
32230
|
}
|
|
31777
32231
|
});
|
|
31778
32232
|
} finally {
|
|
32233
|
+
releaseObjectPrototype(budget);
|
|
31779
32234
|
compilation.dispose();
|
|
31780
32235
|
operation.release();
|
|
31781
32236
|
}
|
|
@@ -32018,4 +32473,4 @@ export {
|
|
|
32018
32473
|
FileSnapshotBackend,
|
|
32019
32474
|
run
|
|
32020
32475
|
};
|
|
32021
|
-
//# sourceMappingURL=chunk-
|
|
32476
|
+
//# sourceMappingURL=chunk-2LVAGOJR.js.map
|