Refactor to{,UTC,ISO}String methods of the Date object.
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
This commit is contained in:
@@ -55,7 +55,27 @@
|
|||||||
static ecma_completion_value_t
|
static ecma_completion_value_t
|
||||||
ecma_builtin_date_prototype_to_string (ecma_value_t this_arg) /**< this argument */
|
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 */
|
} /* 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
|
static ecma_completion_value_t
|
||||||
ecma_builtin_date_prototype_to_utc_string (ecma_value_t this_arg) /**< this argument */
|
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 */
|
} /* 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
|
static ecma_completion_value_t
|
||||||
ecma_builtin_date_prototype_to_iso_string (ecma_value_t this_arg) /**< this argument */
|
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 */
|
} /* ecma_builtin_date_prototype_to_iso_string */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -917,7 +917,9 @@ ecma_date_insert_num_with_sep (ecma_string_t **str_p, /**< input/output string *
|
|||||||
*
|
*
|
||||||
* Used by:
|
* Used by:
|
||||||
* - The Date routine.
|
* - 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
|
* @return completion value
|
||||||
* Returned value must be freed with ecma_free_completion_value.
|
* Returned value must be freed with ecma_free_completion_value.
|
||||||
@@ -925,15 +927,6 @@ ecma_date_insert_num_with_sep (ecma_string_t **str_p, /**< input/output string *
|
|||||||
ecma_completion_value_t
|
ecma_completion_value_t
|
||||||
ecma_date_value_to_string (ecma_number_t datetime_num, /**<datetime */
|
ecma_date_value_to_string (ecma_number_t datetime_num, /**<datetime */
|
||||||
ecma_date_timezone_t timezone) /**< timezone */
|
ecma_date_timezone_t timezone) /**< timezone */
|
||||||
{
|
|
||||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
|
||||||
|
|
||||||
if (ecma_number_is_nan (datetime_num))
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
ecma_string_t *output_str_p;
|
ecma_string_t *output_str_p;
|
||||||
ecma_number_t milliseconds;
|
ecma_number_t milliseconds;
|
||||||
@@ -975,14 +968,11 @@ ecma_date_value_to_string (ecma_number_t datetime_num, /**<datetime */
|
|||||||
ecma_number_t year = ecma_date_year_from_time (datetime_num);
|
ecma_number_t year = ecma_date_year_from_time (datetime_num);
|
||||||
ecma_date_insert_num_with_sep (&output_str_p, year, LIT_MAGIC_STRING_MINUS_CHAR, 4);
|
ecma_date_insert_num_with_sep (&output_str_p, year, LIT_MAGIC_STRING_MINUS_CHAR, 4);
|
||||||
|
|
||||||
ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_str_p));
|
return ecma_make_normal_completion_value (ecma_make_string_value (output_str_p));
|
||||||
}
|
|
||||||
|
|
||||||
return ret_value;
|
|
||||||
} /* ecma_date_value_to_string */
|
} /* ecma_date_value_to_string */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common function to create a time zone specific string for objects.
|
* Common function to get the primitive value of the Date object.
|
||||||
*
|
*
|
||||||
* Used by:
|
* Used by:
|
||||||
* - The Date.prototype.toString routine.
|
* - The Date.prototype.toString routine.
|
||||||
@@ -993,8 +983,7 @@ ecma_date_value_to_string (ecma_number_t datetime_num, /**<datetime */
|
|||||||
* Returned value must be freed with ecma_free_completion_value.
|
* Returned value must be freed with ecma_free_completion_value.
|
||||||
*/
|
*/
|
||||||
ecma_completion_value_t
|
ecma_completion_value_t
|
||||||
ecma_date_object_to_string (ecma_value_t this_arg, /**< this argument */
|
ecma_date_get_primitive_value (ecma_value_t this_arg) /**< this argument */
|
||||||
ecma_date_timezone_t timezone) /**< timezone */
|
|
||||||
{
|
{
|
||||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||||
|
|
||||||
@@ -1008,13 +997,16 @@ ecma_date_object_to_string (ecma_value_t this_arg, /**< this argument */
|
|||||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||||
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
|
||||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
|
||||||
ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t,
|
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);
|
prim_value_prop_p->u.internal_property.value);
|
||||||
ret_value = ecma_date_value_to_string (*prim_value_num_p, timezone);
|
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (prim_value_num_p));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
} /* ecma_date_object_to_string */
|
} /* ecma_date_get_primitive_value */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ extern void ecma_date_insert_num_with_sep (ecma_string_t **str_p,
|
|||||||
uint32_t length);
|
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_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 */
|
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user