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MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,MAAM,CAAU;IACxB,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { rootRealmGlobal } from '../globalObject';\n\n/**\n * Creates a {@link Date} constructor, with most of the same properties as the global object.\n * The Date.now() function has added noise as to limit its precision and prevent potential timing attacks.\n * The Date constructor uses this now() function to seed itself if no arguments are given to the constructor.\n *\n * @returns A modified {@link Date} constructor with limited precision.\n */\nfunction createDate() {\n  const keys = Object.getOwnPropertyNames(\n    rootRealmGlobal.Date,\n  ) as (keyof typeof Date)[];\n\n  let currentTime = 0;\n  const now = () => {\n    const actual = rootRealmGlobal.Date.now();\n    const newTime = Math.round(actual + Math.random());\n    if (newTime > currentTime) {\n      currentTime = newTime;\n    }\n    return currentTime;\n  };\n\n  const NewDate = function (...args: unknown[]) {\n    return Reflect.construct(\n      rootRealmGlobal.Date,\n      args.length === 0 ? [now()] : args,\n      new.target,\n    );\n  } as DateConstructor;\n\n  keys.forEach((key) => {\n    Reflect.defineProperty(NewDate, key, {\n      configurable: false,\n      writable: false,\n      value: key === 'now' ? now : rootRealmGlobal.Date[key],\n    });\n  });\n\n  return { Date: harden(NewDate) };\n}\n\nconst endowmentModule = {\n  names: ['Date'] as const,\n  factory: createDate,\n};\n\nexport default endowmentModule;\n"]}