jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

Fix runtime error Date object

Open batizdaniel opened this issue 4 years ago • 3 comments

This patch fixes #4704

JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz [email protected]

batizdaniel avatar Dec 23 '21 10:12 batizdaniel

I think the best approach would be to clamp the input year so that it's not abnormally large. The valid year range is [-271821, 275760], so clamping to a slightly larger range than that should be enough, making sure that invalid year values remain invalid.

It's not as easy. We can't clamp the input year, because there is no restriction for the arguments of the Date constructor, only the output Date object should be in the allowed interval. for example new Date(-271822, 16) is valid Date, but new Date(-271822, 15) is invalid.

ossy-szeged avatar Jan 18 '22 12:01 ossy-szeged

That's why I said clamping it to a slightly larger range. That will filter out abnormally large input values, that should be invalid regardless, then the rest will be handled by the conversion logic correctly without overflowing.

dbatyai avatar Jan 18 '22 13:01 dbatyai

https://262.ecma-international.org/12.0/#eqn-DaysFromYear

The latest spec clarifies that we should handle year as mathematical value (Arbitrary real numbers, used as the default numeric type) and the result should be Number (double): DayFromYear(y) = 𝔽(365 × (ℝ(y) - 1970) + floor((ℝ(y) - 1969) / 4) - floor((ℝ(y) - 1901) / 100) + floor((ℝ(y) - 1601) / 400))

ossy-szeged avatar Jan 18 '22 13:01 ossy-szeged