104 public InvokeByName call() {
105 return new InvokeByName("toISOString", ScriptObject.class, Object.class, Object.class);
106 }
107 });
108 }
109
110 private double time;
111 private final TimeZone timezone;
112
113 // initialized by nasgen
114 private static PropertyMap $nasgenmap$;
115
116 private NativeDate(final double time, final ScriptObject proto, final PropertyMap map) {
117 super(proto, map);
118 final ScriptEnvironment env = Global.getEnv();
119
120 this.time = time;
121 this.timezone = env._timezone;
122 }
123
124 NativeDate(final double time, final Global global) {
125 this(time, global.getDatePrototype(), $nasgenmap$);
126 }
127
128 private NativeDate (final double time) {
129 this(time, Global.instance());
130 }
131
132 private NativeDate() {
133 this(System.currentTimeMillis());
134 }
135
136 @Override
137 public String getClassName() {
138 return "Date";
139 }
140
141 // ECMA 8.12.8 [[DefaultValue]] (hint)
142 @Override
143 public Object getDefaultValue(final Class<?> hint) {
1259
1260 return nullReturn ? null : d;
1261 }
1262
1263 // ECMA 15.9.1.14 TimeClip (time)
1264 private static double timeClip(final double time) {
1265 if (isInfinite(time) || isNaN(time) || Math.abs(time) > 8.64e15) {
1266 return Double.NaN;
1267 }
1268 return (long)time;
1269 }
1270
1271 private static NativeDate ensureNativeDate(final Object self) {
1272 return getNativeDate(self);
1273 }
1274
1275 private static NativeDate getNativeDate(final Object self) {
1276 if (self instanceof NativeDate) {
1277 return (NativeDate)self;
1278 } else if (self != null && self == Global.instance().getDatePrototype()) {
1279 return Global.instance().DEFAULT_DATE;
1280 } else {
1281 throw typeError("not.a.date", ScriptRuntime.safeToString(self));
1282 }
1283 }
1284
1285 private static double getField(final Object self, final int field) {
1286 final NativeDate nd = getNativeDate(self);
1287 return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getLocalTime()) : Double.NaN;
1288 }
1289
1290 private static double getUTCField(final Object self, final int field) {
1291 final NativeDate nd = getNativeDate(self);
1292 return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getTime()) : Double.NaN;
1293 }
1294
1295 private static void setFields(final NativeDate nd, final int fieldId, final Object[] args, final boolean local) {
1296 int start, length;
1297 if (fieldId < HOUR) {
1298 start = YEAR;
1299 length = 3;
|
104 public InvokeByName call() {
105 return new InvokeByName("toISOString", ScriptObject.class, Object.class, Object.class);
106 }
107 });
108 }
109
110 private double time;
111 private final TimeZone timezone;
112
113 // initialized by nasgen
114 private static PropertyMap $nasgenmap$;
115
116 private NativeDate(final double time, final ScriptObject proto, final PropertyMap map) {
117 super(proto, map);
118 final ScriptEnvironment env = Global.getEnv();
119
120 this.time = time;
121 this.timezone = env._timezone;
122 }
123
124 NativeDate(final double time, final ScriptObject proto) {
125 this(time, proto, $nasgenmap$);
126 }
127
128 NativeDate(final double time, final Global global) {
129 this(time, global.getDatePrototype(), $nasgenmap$);
130 }
131
132 private NativeDate (final double time) {
133 this(time, Global.instance());
134 }
135
136 private NativeDate() {
137 this(System.currentTimeMillis());
138 }
139
140 @Override
141 public String getClassName() {
142 return "Date";
143 }
144
145 // ECMA 8.12.8 [[DefaultValue]] (hint)
146 @Override
147 public Object getDefaultValue(final Class<?> hint) {
1263
1264 return nullReturn ? null : d;
1265 }
1266
1267 // ECMA 15.9.1.14 TimeClip (time)
1268 private static double timeClip(final double time) {
1269 if (isInfinite(time) || isNaN(time) || Math.abs(time) > 8.64e15) {
1270 return Double.NaN;
1271 }
1272 return (long)time;
1273 }
1274
1275 private static NativeDate ensureNativeDate(final Object self) {
1276 return getNativeDate(self);
1277 }
1278
1279 private static NativeDate getNativeDate(final Object self) {
1280 if (self instanceof NativeDate) {
1281 return (NativeDate)self;
1282 } else if (self != null && self == Global.instance().getDatePrototype()) {
1283 return Global.instance().getDefaultDate();
1284 } else {
1285 throw typeError("not.a.date", ScriptRuntime.safeToString(self));
1286 }
1287 }
1288
1289 private static double getField(final Object self, final int field) {
1290 final NativeDate nd = getNativeDate(self);
1291 return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getLocalTime()) : Double.NaN;
1292 }
1293
1294 private static double getUTCField(final Object self, final int field) {
1295 final NativeDate nd = getNativeDate(self);
1296 return (nd != null && nd.isValidDate()) ? (double)valueFromTime(field, nd.getTime()) : Double.NaN;
1297 }
1298
1299 private static void setFields(final NativeDate nd, final int fieldId, final Object[] args, final boolean local) {
1300 int start, length;
1301 if (fieldId < HOUR) {
1302 start = YEAR;
1303 length = 3;
|