From 1b05cc47ffa73cf855814f200698da26a740e50a Mon Sep 17 00:00:00 2001 From: Roland Takacs Date: Mon, 3 Aug 2015 10:09:31 +0200 Subject: [PATCH] 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 --- .../ecma-builtin-date-prototype.cpp | 5 ++--- tests/jerry/date-tostring.js | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp index ff74197f9..ef21d1ee1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp @@ -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 { diff --git a/tests/jerry/date-tostring.js b/tests/jerry/date-tostring.js index d459d70b4..6880c0d05 100644 --- a/tests/jerry/date-tostring.js +++ b/tests/jerry/date-tostring.js @@ -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);