Add throwing of missing range error to Date.prototype.toISOString()

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
This commit is contained in:
Roland Takacs
2015-08-03 10:09:31 +02:00
parent 6082c32d45
commit 1b05cc47ff
2 changed files with 22 additions and 4 deletions
@@ -1164,10 +1164,9 @@ ecma_builtin_date_prototype_to_iso_string (ecma_value_t this_arg) /**< this argu
ecma_number_t *prim_num_p = ecma_get_number_from_value (prim_value);
if (ecma_number_is_nan (*prim_num_p))
if (ecma_number_is_nan (*prim_num_p) || ecma_number_is_infinity (*prim_num_p))
{
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INVALID_DATE_UL);
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (magic_str_p));
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_RANGE));
}
else
{
+20 -1
View File
@@ -65,10 +65,29 @@ catch (e)
assert (e.message === "Incompatible type");
}
assert (new Date (NaN).toISOString () == "Invalid Date");
assert (new Date ("2015-07-16").toISOString () == "2015-07-16T00:00:00.000Z");
assert (new Date ("2015-07-16T11:29:05.023").toISOString () == "2015-07-16T11:29:05.023Z");
try
{
new Date (NaN).toISOString ();
assert (false);
}
catch (e)
{
assert (e instanceof RangeError);
}
try
{
new Date (Number.POSITIVE_INFINITY).toISOString ();
assert (false);
}
catch (e)
{
assert (e instanceof RangeError);
}
try
{
Date.prototype.toISOString.call(-1);