avm1: If a NaN is provided to new Date(timestamp), fail immediately

This commit is contained in:
Nathan Adams 2020-08-26 04:47:47 +05:45 committed by Mike Welsh
parent 9dfc20e1ba
commit f50b29151c
1 changed files with 10 additions and 5 deletions

View File

@ -584,13 +584,18 @@ fn constructor<'gc>(
.millisecond_opt(args.get(6))? .millisecond_opt(args.get(6))?
.adjust_year(|year| if year < 100 { year + 1900 } else { year }) .adjust_year(|year| if year < 100 { year + 1900 } else { year })
.apply(this); .apply(this);
} else if let LocalResult::Single(time) = } else {
Utc.timestamp_millis_opt(timestamp.coerce_to_f64(activation)? as i64) let timestamp = timestamp.coerce_to_f64(activation)?;
{ if timestamp.is_finite() {
if let LocalResult::Single(time) = Utc.timestamp_millis_opt(timestamp as i64) {
this.set_date_time(activation.context.gc_context, Some(time)) this.set_date_time(activation.context.gc_context, Some(time))
} else { } else {
this.set_date_time(activation.context.gc_context, None); this.set_date_time(activation.context.gc_context, None);
} }
} else {
this.set_date_time(activation.context.gc_context, None);
}
}
} else { } else {
this.set_date_time( this.set_date_time(
activation.context.gc_context, activation.context.gc_context,