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 a02416b88..ff74197f9 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.cpp @@ -55,7 +55,27 @@ static ecma_completion_value_t ecma_builtin_date_prototype_to_string (ecma_value_t this_arg) /**< this argument */ { - return ecma_date_object_to_string (this_arg, ECMA_DATE_LOCAL); + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); + + ECMA_TRY_CATCH (prim_value, + ecma_date_get_primitive_value (this_arg), + ret_value); + + ecma_number_t *prim_num_p = ecma_get_number_from_value (prim_value); + + if (ecma_number_is_nan (*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)); + } + else + { + ret_value = ecma_date_value_to_string (*prim_num_p, ECMA_DATE_LOCAL); + } + + ECMA_FINALIZE (prim_value); + + return ret_value; } /* ecma_builtin_date_prototype_to_string */ /** @@ -1101,7 +1121,27 @@ ecma_builtin_date_prototype_set_utc_full_year (ecma_value_t this_arg, /**< this static ecma_completion_value_t ecma_builtin_date_prototype_to_utc_string (ecma_value_t this_arg) /**< this argument */ { - return ecma_date_object_to_string (this_arg, ECMA_DATE_UTC); + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); + + ECMA_TRY_CATCH (prim_value, + ecma_date_get_primitive_value (this_arg), + ret_value); + + ecma_number_t *prim_num_p = ecma_get_number_from_value (prim_value); + + if (ecma_number_is_nan (*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)); + } + else + { + ret_value = ecma_date_value_to_string (*prim_num_p, ECMA_DATE_UTC); + } + + ECMA_FINALIZE (prim_value); + + return ret_value; } /* ecma_builtin_date_prototype_to_utc_string */ /** @@ -1116,7 +1156,27 @@ ecma_builtin_date_prototype_to_utc_string (ecma_value_t this_arg) /**< this argu static ecma_completion_value_t ecma_builtin_date_prototype_to_iso_string (ecma_value_t this_arg) /**< this argument */ { - return ecma_date_object_to_string (this_arg, ECMA_DATE_UTC); + ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); + + ECMA_TRY_CATCH (prim_value, + ecma_date_get_primitive_value (this_arg), + ret_value); + + ecma_number_t *prim_num_p = ecma_get_number_from_value (prim_value); + + if (ecma_number_is_nan (*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)); + } + else + { + ret_value = ecma_date_value_to_string (*prim_num_p, ECMA_DATE_UTC); + } + + ECMA_FINALIZE (prim_value); + + return ret_value; } /* ecma_builtin_date_prototype_to_iso_string */ /** diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp index 2a542b802..38c47b3a1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.cpp @@ -917,7 +917,9 @@ ecma_date_insert_num_with_sep (ecma_string_t **str_p, /**< input/output string * * * Used by: * - The Date routine. - * - The ecma_date_object_to_string helper routine. + * - The Date.prototype.toString routine. + * - The Date.prototype.toISOString routine. + * - The Date.prototype.toUTCString routine. * * @return completion value * Returned value must be freed with ecma_free_completion_value. @@ -926,63 +928,51 @@ ecma_completion_value_t ecma_date_value_to_string (ecma_number_t datetime_num, /**u.internal_property.value); - ret_value = ecma_date_value_to_string (*prim_value_num_p, timezone); + JERRY_ASSERT (prim_value_prop_p != NULL); + + ecma_number_t *prim_value_num_p = ecma_alloc_number (); + *prim_value_num_p = *ECMA_GET_NON_NULL_POINTER (ecma_number_t, + prim_value_prop_p->u.internal_property.value); + ret_value = ecma_make_normal_completion_value (ecma_make_number_value (prim_value_num_p)); } return ret_value; -} /* ecma_date_object_to_string */ +} /* ecma_date_get_primitive_value */ /** * @} diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h index 6d4c9d244..f0103af64 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.h @@ -122,7 +122,7 @@ extern void ecma_date_insert_num_with_sep (ecma_string_t **str_p, uint32_t length); extern ecma_completion_value_t ecma_date_value_to_string (ecma_number_t datetime_num, ecma_date_timezone_t timezone); -extern ecma_completion_value_t ecma_date_object_to_string (ecma_value_t this_arg, ecma_date_timezone_t timezone); +extern ecma_completion_value_t ecma_date_get_primitive_value (ecma_value_t this_arg); #endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN */