@poe-platform/safe-js 0.1.23 → 0.1.25

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.
@@ -4263,8 +4263,9 @@ var Parser = class {
4263
4263
  }
4264
4264
  break;
4265
4265
  }
4266
- this.expectPunctuator("(");
4267
- const args = this.parseArguments();
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 types2 } from "node:util";
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");
@@ -6841,7 +6964,7 @@ function serializeDumpValue(value, path, state) {
6841
6964
  if (hasGuestObjectState(value)) {
6842
6965
  throw new TypeError("Guest function properties and prototype links cannot be serialized.");
6843
6966
  }
6844
- if (isFloat32Array(value)) return serializeHeapReference(value, path, state);
6967
+ if (isSandboxDate(value) || isFloat32Array(value)) return serializeHeapReference(value, path, state);
6845
6968
  if (Array.isArray(value)) {
6846
6969
  const reference2 = serializeHeapReference(value, path, state);
6847
6970
  if (reference2 !== void 0) {
@@ -6865,7 +6988,9 @@ function serializeHeapReference(value, path, state) {
6865
6988
  }
6866
6989
  if (!state.serializedHeapIds.has(id)) {
6867
6990
  state.serializedHeapIds.add(id);
6868
- if (isFloat32Array(value)) {
6991
+ if (isSandboxDate(value)) {
6992
+ state.heap[String(id)] = { kind: "date", time: serializedDateTime(value) };
6993
+ } else if (isFloat32Array(value)) {
6869
6994
  const storage = encodeFloat32Storage(value, id, state.float32Buffers, (id2) => ({
6870
6995
  kind: "ref",
6871
6996
  id: id2
@@ -6922,7 +7047,7 @@ function indexHeapContainers(snapshot) {
6922
7047
  const heapIds = /* @__PURE__ */ new WeakMap();
6923
7048
  let nextId = 1;
6924
7049
  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)) {
7050
+ if (stat2.count > 1 || stat2.cyclic || isSandboxDate(value) || isFloat32Array(value) || Array.isArray(value) && requiresArrayEntries(value) || isSandboxArguments(value) || sandboxErrorTypes.has(value)) {
6926
7051
  heapIds.set(value, nextId);
6927
7052
  nextId += 1;
6928
7053
  }
@@ -6933,7 +7058,7 @@ function collectContainerStats(value, stats, ancestors) {
6933
7058
  if (value === null || typeof value !== "object") {
6934
7059
  return;
6935
7060
  }
6936
- if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value)) {
7061
+ if (!Array.isArray(value) && !isPlainObject(value) && !isFloat32Array(value) && !isSandboxDate(value)) {
6937
7062
  return;
6938
7063
  }
6939
7064
  let stat2 = stats.get(value);
@@ -7069,6 +7194,10 @@ function validateDumpHeap(root, state) {
7069
7194
  addUnique(heapIds, id, path);
7070
7195
  const entry = requireRecord(value, path);
7071
7196
  validateErrorType(entry, path);
7197
+ if (entry.kind === "date") {
7198
+ validateDateRecord(entry, path);
7199
+ continue;
7200
+ }
7072
7201
  if (entry.kind === "float32array") {
7073
7202
  validateFloat32Storage(entry);
7074
7203
  requireRecord(entry.entries, `${path}.entries`);
@@ -7226,6 +7355,14 @@ function validateGeneratorShape(record2, path, state) {
7226
7355
  }
7227
7356
  });
7228
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
+ }
7229
7366
  function validateArrayHeap(record2, path, state) {
7230
7367
  if (Object.hasOwn(record2, "items")) {
7231
7368
  requireArray(record2.items, `${path}.items`, state);
@@ -7309,7 +7446,7 @@ function validateGenericValue(value, path, depth, state) {
7309
7446
  if (typeof value === "object" && value !== null && hasGuestObjectState(value)) {
7310
7447
  fail("invalidState", path, "guest function properties, prototype links and custom descriptors cannot be restored");
7311
7448
  }
7312
- if (state.dataPropertiesOnly && types2.isProxy(value)) {
7449
+ if (state.dataPropertiesOnly && types3.isProxy(value)) {
7313
7450
  fail("invalidType", path, "proxy objects are not snapshot data");
7314
7451
  }
7315
7452
  if (depth > state.limits.maxDepth)
@@ -9552,6 +9689,10 @@ function measureSandboxData(values, options = {}) {
9552
9689
  assertSandboxDataDepth(depth);
9553
9690
  seen.add(value);
9554
9691
  usage += 1;
9692
+ if (isSandboxDate(value)) {
9693
+ usage += 8;
9694
+ return;
9695
+ }
9555
9696
  if (isGuestHostObject(value)) {
9556
9697
  for (const key of getHostObjectKeys(value)) usage += key.length + 1;
9557
9698
  return;
@@ -9746,6 +9887,13 @@ function copyToSandbox(value, state, path = "<root>", cloneSandboxCollections =
9746
9887
  }
9747
9888
  return sandboxPromise;
9748
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
+ }
9749
9897
  if (isFloat32Array(value)) {
9750
9898
  const existing = state.seen.get(value);
9751
9899
  if (existing !== void 0) return existing;
@@ -9905,6 +10053,13 @@ function copyFromSandbox(value, state, path = "<root>", options, depth = 0) {
9905
10053
  if (!Object.isExtensible(value)) Object.preventExtensions(copy);
9906
10054
  return copy;
9907
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
+ }
9908
10063
  if (isSandboxClosure(value)) {
9909
10064
  if (options.wrapClosure === void 0) {
9910
10065
  throw new TypeError(
@@ -10219,6 +10374,8 @@ function encodeReplayData(value, options = {}) {
10219
10374
  id: capabilityId,
10220
10375
  properties: child(entry.properties, "properties")
10221
10376
  };
10377
+ } else if (isSandboxDate(entry)) {
10378
+ nodes[id] = { kind: "date", time: serializedDateTime(entry) };
10222
10379
  } else if (isFloat32Array(entry)) {
10223
10380
  const storage = encodeFloat32Storage(entry, id, float32Buffers, (id2) => ({
10224
10381
  tag: "ref",
@@ -10369,6 +10526,12 @@ function decodeReplayData(input, options = {}, parent) {
10369
10526
  options.onCapabilityRestored?.(capability, copy);
10370
10527
  return copy;
10371
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
+ }
10372
10535
  if (kind === "float32array") {
10373
10536
  if (typeof node.extensible !== "boolean")
10374
10537
  throw new TypeError("Invalid Float32Array extensibility.");
@@ -11059,6 +11222,8 @@ function normalize(value, seen) {
11059
11222
  if (seen.has(value)) throw new TypeError("Host call arguments cannot contain cycles.");
11060
11223
  seen.add(value);
11061
11224
  try {
11225
+ const date = copyNativeDate(value);
11226
+ if (date !== void 0) return Object.assign(/* @__PURE__ */ Object.create(null), { $type: "date", time: serializedDateTime(date) });
11062
11227
  if (isFloat32Array(value)) {
11063
11228
  const storage = float32Storage(value);
11064
11229
  const properties = /* @__PURE__ */ Object.create(null);
@@ -12014,6 +12179,7 @@ var KNOWN_RUNTIME_GLOBALS = [
12014
12179
  "AggregateError",
12015
12180
  "Array",
12016
12181
  "Boolean",
12182
+ "Date",
12017
12183
  "Error",
12018
12184
  "Infinity",
12019
12185
  "isFinite",
@@ -17178,9 +17344,9 @@ var ASFloatingPromiseScanner = class {
17178
17344
  isPromiseFactoryCall(node) {
17179
17345
  return this.isPromiseStaticMethodCall(node, PROMISE_FACTORIES);
17180
17346
  }
17181
- isPromiseStaticMethodCall(node, methodNames) {
17347
+ isPromiseStaticMethodCall(node, methodNames2) {
17182
17348
  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" && methodNames.has(member.property.name);
17349
+ return member !== void 0 && !member.computed && member.object.type === "Identifier" && member.object.name === "Promise" && member.property.type === "Identifier" && methodNames2.has(member.property.name);
17184
17350
  }
17185
17351
  isPromiseChainCall(node) {
17186
17352
  const member = node.callee.type === "MemberExpression" ? node.callee : void 0;
@@ -24818,6 +24984,101 @@ function relativeIndex(value, length, fallback) {
24818
24984
  return integer < 0 ? Math.max(length + integer, 0) : Math.min(integer, length);
24819
24985
  }
24820
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
+
24821
25082
  // packages/safe-js/src/interp/scope.ts
24822
25083
  var uninitialized = /* @__PURE__ */ Symbol("uninitialized");
24823
25084
  var Scope = class _Scope {
@@ -26682,6 +26943,7 @@ function getPropertyValue(target, property, context) {
26682
26943
  if (typeof target === "number") return getNumberMember(target, property, context.budget);
26683
26944
  if (typeof target === "boolean") return void 0;
26684
26945
  if (isFloat32Array(target)) return getFloat32Member(target, property, context.budget);
26946
+ if (isSandboxDate(target)) return getDateMember(property, context.budget, context.compilation?.owner);
26685
26947
  if (isSandboxMap(target)) return getMapMember(target, property, createMapMethodOptions(context));
26686
26948
  if (isSandboxSet(target)) return getSetMember(target, property, createSetMethodOptions(context));
26687
26949
  if (isSandboxGenerator(target)) return getGeneratorMember(target, property, context.budget);
@@ -26918,6 +27180,9 @@ async function evaluateMemberCallExpression(node, context) {
26918
27180
  context
26919
27181
  );
26920
27182
  }
27183
+ if (isSandboxDate(member.object)) {
27184
+ return evaluateResolvedCallExpression(node, getDateMember(member.property, context.budget, context.compilation?.owner), context, member.object);
27185
+ }
26921
27186
  if (isFloat32Array(member.object)) {
26922
27187
  return evaluateResolvedCallExpression(
26923
27188
  node,
@@ -27170,6 +27435,7 @@ function applyBinaryOperator(node, left, right, context) {
27170
27435
  return true;
27171
27436
  }
27172
27437
  if (isFloat32ArrayConstructor(right)) return isFloat32Array(left);
27438
+ if (isDateConstructor(right)) return isSandboxDate(left) && getDatePrototype(left, context.budget, context.compilation?.owner) !== null;
27173
27439
  if (isSandboxSetConstructor(right) && isSandboxSet(left)) {
27174
27440
  return true;
27175
27441
  }
@@ -27233,8 +27499,8 @@ function applyAdditionOperator(left, right, context) {
27233
27499
  return toNumber(leftPrimitive) + toNumber(rightPrimitive);
27234
27500
  }
27235
27501
  function compareRelational(left, right, operator) {
27236
- const leftPrimitive = toPrimitive(left);
27237
- const rightPrimitive = toPrimitive(right);
27502
+ const leftPrimitive = isSandboxDate(left) ? dateTime(left) : toPrimitive(left);
27503
+ const rightPrimitive = isSandboxDate(right) ? dateTime(right) : toPrimitive(right);
27238
27504
  if (typeof leftPrimitive === "string" && typeof rightPrimitive === "string") {
27239
27505
  switch (operator) {
27240
27506
  case "<":
@@ -27317,6 +27583,7 @@ function toPrimitive(value) {
27317
27583
  return toString(value);
27318
27584
  }
27319
27585
  async function toNumericPrimitive(value, context) {
27586
+ if (isSandboxDate(value)) return dateTime(value);
27320
27587
  if (isPrimitiveCoercionType(getCoercionType(value))) {
27321
27588
  return value;
27322
27589
  }
@@ -27346,6 +27613,7 @@ async function toNumericPrimitive(value, context) {
27346
27613
  return toString(value);
27347
27614
  }
27348
27615
  function toNumber(value) {
27616
+ if (isSandboxDate(value)) return dateTime(value);
27349
27617
  if (typeof value === "number") {
27350
27618
  return value;
27351
27619
  }
@@ -27364,6 +27632,7 @@ function toNumber(value) {
27364
27632
  return toNumber(toPrimitive(value));
27365
27633
  }
27366
27634
  function toString(value) {
27635
+ if (isSandboxDate(value)) return dateString(value);
27367
27636
  if (Array.isArray(value)) {
27368
27637
  return value.map((entry) => entry === null || entry === void 0 ? "" : toString(entry)).join(",");
27369
27638
  }
@@ -27409,6 +27678,7 @@ function getArrayMemberValue(target, property, context) {
27409
27678
  return getArrayMember(target, property, createArrayMethodOptions(context));
27410
27679
  }
27411
27680
  function setSandboxProperty(target, property, value, budget) {
27681
+ if (isSandboxDate(target)) throw new TypeError("Date own properties are not supported.");
27412
27682
  if (isGuestHostObject(target)) {
27413
27683
  setHostObjectMember(target, String(property), value);
27414
27684
  return;
@@ -28676,6 +28946,14 @@ function copyHostValueToSandbox(value, stackFrames, options, state, path) {
28676
28946
  state
28677
28947
  );
28678
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
+ }
28679
28957
  if (isFloat32Array(value)) {
28680
28958
  const existing = state.seen.get(value);
28681
28959
  if (existing !== void 0) return existing;
@@ -29077,7 +29355,7 @@ function createReplayableRandom(options = {}) {
29077
29355
 
29078
29356
  // packages/safe-js/src/realm.ts
29079
29357
  import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
29080
- import { types as types3 } from "node:util";
29358
+ import { types as types4 } from "node:util";
29081
29359
 
29082
29360
  // packages/safe-js/src/interp/globals/console-json.ts
29083
29361
  function createConsoleJsonGlobals(options) {
@@ -29191,7 +29469,9 @@ function toJsonParseText(input) {
29191
29469
  }
29192
29470
  async function stringifyProperty(key, holder, state, indent = "") {
29193
29471
  let value = getOwnDataValue(holder, key);
29194
- if (isStringifyContainer(value)) {
29472
+ if (isSandboxDate(value)) {
29473
+ value = dateMethods.get("toJSON").invoke(value, []);
29474
+ } else if (isStringifyContainer(value)) {
29195
29475
  const toJSON = getOwnDataValue(value, "toJSON");
29196
29476
  if (isSandboxClosure(toJSON)) {
29197
29477
  value = await callStringifyClosure(toJSON, [key], value, state);
@@ -29503,6 +29783,7 @@ async function stringifyObject2(value, budget, context, joining) {
29503
29783
  }
29504
29784
  }
29505
29785
  async function defaultToString(value, budget, context, joining) {
29786
+ if (isSandboxDate(value)) return budget.allocateString(dateString(value));
29506
29787
  if (Array.isArray(value) || isFloat32Array(value)) {
29507
29788
  if (Object.hasOwn(value, "join")) {
29508
29789
  const join = ownDataValue(value, "join");
@@ -29606,6 +29887,7 @@ function createObjectArrayGlobals(options) {
29606
29887
  getPrototypeOf: createSandboxClosure({
29607
29888
  sandbox: true,
29608
29889
  call: ([value]) => {
29890
+ if (isSandboxDate(value)) return getDatePrototype(value, options.budget, options.compileOwner);
29609
29891
  objectProperties(value);
29610
29892
  return getSandboxPrototype(value);
29611
29893
  },
@@ -29730,7 +30012,7 @@ function createObjectArrayGlobals(options) {
29730
30012
  }),
29731
30013
  Number: createSandboxClosure({
29732
30014
  sandbox: true,
29733
- call: ([value]) => Number(value),
30015
+ call: ([value]) => isSandboxDate(value) ? dateTime(value) : Number(value),
29734
30016
  name: "Number",
29735
30017
  properties: {
29736
30018
  isFinite: createSandboxClosure({
@@ -29830,6 +30112,10 @@ function assignSandboxValues(target, sources, budget) {
29830
30112
  return target;
29831
30113
  }
29832
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
+ }
29833
30119
  if (isGuestHostObject(value)) throw new TypeError("Live host object descriptors are not supported.");
29834
30120
  if (isGuestClosure(value)) return materializeFunctionProperties(value);
29835
30121
  if (isSandboxClosure(value)) {
@@ -29951,6 +30237,7 @@ function createBuiltinBindings(options) {
29951
30237
  ...createConsoleJsonGlobals(options),
29952
30238
  ...createCollectionGlobals(options),
29953
30239
  Float32Array: createFloat32ArrayGlobal(options.budget),
30240
+ Date: createDateGlobal(options),
29954
30241
  ...createErrorGlobals(options),
29955
30242
  ...createMathGlobals({ random: options.random }),
29956
30243
  ...createObjectArrayGlobals(options),
@@ -30132,7 +30419,7 @@ var RealmState = class {
30132
30419
  throw new TypeError("Realm limits must be positive safe integers with supported names.");
30133
30420
  this.limits[name] = Number(value);
30134
30421
  }
30135
- if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types3.isProxy(options.extensions)))
30422
+ if (options.extensions !== void 0 && (!Array.isArray(options.extensions) || types4.isProxy(options.extensions)))
30136
30423
  throw new TypeError("Extensions must be a registration array.");
30137
30424
  const registrations = options.extensions ?? [];
30138
30425
  const extensions = [];
@@ -30169,6 +30456,7 @@ var RealmState = class {
30169
30456
  budget: this.budget,
30170
30457
  compileOwner: this.lease.owner,
30171
30458
  sink: options.sink,
30459
+ clock: options.clock,
30172
30460
  random: createReplayableRandom({ seed: options.randomSeed }).next
30173
30461
  });
30174
30462
  const names = /* @__PURE__ */ new Set();
@@ -30350,7 +30638,7 @@ var RealmState = class {
30350
30638
  return this.phase.run(phase, () => {
30351
30639
  try {
30352
30640
  const result = call();
30353
- if (types3.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
30641
+ if (types4.isPromise(result) || phase.pending.size > 0 || phase.failure !== void 0) {
30354
30642
  return Promise.resolve(result).then(
30355
30643
  async (value) => {
30356
30644
  await Promise.allSettled(phase.pending);
@@ -30407,7 +30695,7 @@ var RealmState = class {
30407
30695
  chargeWork: this.chargeWork,
30408
30696
  read: (operation) => {
30409
30697
  const value = this.invokeHost(operation, operation);
30410
- if (types3.isPromise(value)) {
30698
+ if (types4.isPromise(value)) {
30411
30699
  void Promise.resolve(value).catch(() => void 0);
30412
30700
  throw new TypeError("Live property getters must be synchronous.");
30413
30701
  }
@@ -30415,7 +30703,7 @@ var RealmState = class {
30415
30703
  },
30416
30704
  write: (operation, value) => {
30417
30705
  const result = this.invokeHost(operation, () => operation(this.exportValue(value)));
30418
- if (types3.isPromise(result)) {
30706
+ if (types4.isPromise(result)) {
30419
30707
  void Promise.resolve(result).catch(() => void 0);
30420
30708
  throw new TypeError("Live property setters must be synchronous.");
30421
30709
  }
@@ -30608,7 +30896,7 @@ var RealmState = class {
30608
30896
  }
30609
30897
  });
30610
30898
  const output = getExtensionSetup(extension)(context);
30611
- if (types3.isPromise(output)) {
30899
+ if (types4.isPromise(output)) {
30612
30900
  void Promise.resolve(output).catch(() => void 0);
30613
30901
  throw new TypeError("Extension setup must be synchronous.");
30614
30902
  }
@@ -30795,7 +31083,7 @@ var RealmState = class {
30795
31083
  };
30796
31084
  function readModules(input) {
30797
31085
  const entries = (value, label) => {
30798
- if (types3.isMap(value) && !types3.isProxy(value)) {
31086
+ if (types4.isMap(value) && !types4.isProxy(value)) {
30799
31087
  const result = [...Map.prototype.entries.call(value)];
30800
31088
  if (result.length > 4096 || result.some(([key]) => typeof key !== "string" || key.length === 0))
30801
31089
  throw new TypeError(`${label} requires bounded string keys.`);
@@ -30869,6 +31157,7 @@ function readRealmOptions(value, oneShot = false) {
30869
31157
  "signal",
30870
31158
  "sink",
30871
31159
  "randomSeed",
31160
+ "clock",
30872
31161
  "limits"
30873
31162
  ]);
30874
31163
  for (const [key, entry] of Object.entries(options)) {
@@ -31515,7 +31804,7 @@ function run(source, options = {}) {
31515
31804
  lifecycle
31516
31805
  })
31517
31806
  );
31518
- 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 });
31519
31808
  const importMeta = convertInitialInput(
31520
31809
  () => deepCopyToSandbox(options.importMeta ?? {})
31521
31810
  );
@@ -32018,4 +32307,4 @@ export {
32018
32307
  FileSnapshotBackend,
32019
32308
  run
32020
32309
  };
32021
- //# sourceMappingURL=chunk-MXUOEOBE.js.map
32310
+ //# sourceMappingURL=chunk-BWVASPJX.js.map