@@ -168,29 +168,33 @@ Value DateConstructor::call()
168
168
169
169
Value DateConstructor::construct (Function&)
170
170
{
171
- if (vm ().argument_count () == 0 ) {
171
+ auto & vm = this ->vm ();
172
+ if (vm.argument_count () == 0 ) {
172
173
struct timeval tv;
173
174
gettimeofday (&tv, nullptr );
174
175
auto datetime = Core::DateTime::now ();
175
176
auto milliseconds = static_cast <u16 >(tv.tv_usec / 1000 );
176
177
return Date::create (global_object (), datetime, milliseconds);
177
178
}
178
- if (vm () .argument_count () == 1 ) {
179
- auto value = vm () .argument (0 );
179
+ if (vm.argument_count () == 1 ) {
180
+ auto value = vm.argument (0 );
180
181
if (value.is_string ())
181
182
value = parse_simplified_iso8601 (value.as_string ().string ());
182
183
// A timestamp since the epoch, in UTC.
184
+ // FIXME: This doesn't construct an "Invalid Date" object if the argument is NaN.
183
185
// FIXME: Date() probably should use a double as internal representation, so that NaN arguments and larger offsets are handled correctly.
184
186
double value_as_double = value.to_double (global_object ());
187
+ if (vm.exception ())
188
+ return {};
185
189
auto datetime = Core::DateTime::from_timestamp (static_cast <time_t >(value_as_double / 1000 ));
186
190
auto milliseconds = static_cast <u16 >(fmod (value_as_double, 1000 ));
187
191
return Date::create (global_object (), datetime, milliseconds);
188
192
}
189
193
// A date/time in components, in local time.
190
- // FIXME: This doesn't construct an "Invalid Date" object if one of the parameters is NaN.
191
- auto arg_or = [this ](size_t i, i32 fallback) { return vm () .argument_count () > i ? vm () .argument (i).to_i32 (global_object ()) : fallback; };
192
- int year = vm () .argument (0 ).to_i32 (global_object ());
193
- int month_index = vm () .argument (1 ).to_i32 (global_object ());
194
+ // FIXME: This doesn't construct an "Invalid Date" object if one of the arguments is NaN.
195
+ auto arg_or = [this , &vm ](size_t i, i32 fallback) { return vm.argument_count () > i ? vm.argument (i).to_i32 (global_object ()) : fallback; };
196
+ int year = vm.argument (0 ).to_i32 (global_object ());
197
+ int month_index = vm.argument (1 ).to_i32 (global_object ());
194
198
int day = arg_or (2 , 1 );
195
199
int hours = arg_or (3 , 0 );
196
200
int minutes = arg_or (4 , 0 );
0 commit comments