1717#include " ecma-alloc.h"
1818#include " ecma-builtin-helpers.h"
1919#include " ecma-exceptions.h"
20+ #include " ecma-function-object.h"
2021#include " ecma-globals.h"
2122#include " ecma-helpers.h"
2223#include " ecma-objects.h"
@@ -1097,7 +1098,7 @@ ecma_builtin_date_prototype_to_utc_string (ecma_value_t this_arg) /**< this argu
10971098 * Returned value must be freed with ecma_free_completion_value.
10981099 */
10991100static ecma_completion_value_t
1100- ecma_builtin_date_prototype_to_iso_string (ecma_value_t this_arg) /* *< this argument */
1101+ ecma_builtin_date_prototype_to_iso_string (ecma_value_t this_arg __attr_unused___ ) /* *< this argument */
11011102{
11021103 return ecma_date_to_string (this_arg, ECMA_DATE_UTC);
11031104} /* ecma_builtin_date_prototype_to_iso_string */
@@ -1113,9 +1114,69 @@ ecma_builtin_date_prototype_to_iso_string (ecma_value_t this_arg) /**< this argu
11131114 */
11141115static ecma_completion_value_t
11151116ecma_builtin_date_prototype_to_json (ecma_value_t this_arg, /* *< this argument */
1116- ecma_value_t arg) /* *< key */
1117+ ecma_value_t arg __attr_unused___ ) /* *< key */
11171118{
1118- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg, arg);
1119+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
1120+
1121+ /* 1. */
1122+ ECMA_TRY_CATCH (obj,
1123+ ecma_op_to_object (this_arg),
1124+ ret_value);
1125+
1126+ /* 2. */
1127+ ECMA_TRY_CATCH (tv,
1128+ ecma_op_to_primitive (obj, ECMA_PREFERRED_TYPE_NUMBER),
1129+ ret_value);
1130+
1131+ /* 3. */
1132+ if (ecma_is_value_number (tv))
1133+ {
1134+ ecma_number_t num_value_p = *ecma_get_number_from_value (tv);
1135+
1136+ if (ecma_number_is_nan (num_value_p) || ecma_number_is_infinity (num_value_p))
1137+ {
1138+ ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_NULL);
1139+ }
1140+ }
1141+
1142+ if (ecma_is_completion_value_empty (ret_value))
1143+ {
1144+ ecma_string_t *to_iso_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_TO_ISO_STRING_UL);
1145+ ecma_object_t *value_obj_p = ecma_get_object_from_value (obj);
1146+
1147+ /* 4. */
1148+ ECMA_TRY_CATCH (toISO,
1149+ ecma_op_object_get (value_obj_p, to_iso_str_p),
1150+ ret_value);
1151+
1152+ /* 5. */
1153+ if (!ecma_op_is_callable (toISO))
1154+ {
1155+ ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
1156+ }
1157+ /* 6. */
1158+ else
1159+ {
1160+ ecma_object_t *toISO_obj_p = ecma_get_object_from_value (toISO);
1161+
1162+ ECMA_TRY_CATCH (func_ret_val,
1163+ ecma_op_function_call (toISO_obj_p, this_arg, NULL , 0 ),
1164+ ret_value);
1165+
1166+ ret_value = ecma_copy_value (func_ret_val, true );
1167+
1168+ ECMA_FINALIZE (func_ret_val);
1169+ }
1170+
1171+ ECMA_FINALIZE (toISO);
1172+
1173+ ecma_deref_ecma_string (to_iso_str_p);
1174+ }
1175+
1176+ ECMA_FINALIZE (tv)
1177+ ECMA_FINALIZE (obj)
1178+
1179+ return ret_value;
11191180} /* ecma_builtin_date_prototype_to_json */
11201181
11211182/* *
0 commit comments