Fix the JSON stringify context abort in case of error
This patch fixes and fixes as well.
Also add a shortcut to access the length of the array in `ecma_builtin_json_array`.
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik
@@ -1654,14 +1654,8 @@ ecma_builtin_json_object (ecma_object_t *obj_p, /**< the object*/
ecma_free_values_collection (property_keys_p, 0);
}
- if (!ecma_is_value_empty (ret_value))
+ if (ecma_is_value_empty (ret_value))
{
- ecma_free_values_collection (partial_p, 0);
- ecma_deref_ecma_string (stepback_p);
- ecma_deref_ecma_string (context_p->indent_str_p);
- return ret_value;
- }
-
/* 9. */
if (partial_p->item_count == 0)
{
@@ -1690,6 +1684,7 @@ ecma_builtin_json_object (ecma_object_t *obj_p, /**< the object*/
context_p);
}
}
+ }
ecma_free_values_collection (partial_p, 0);
@@ -1717,6 +1712,8 @@ static ecma_value_t
ecma_builtin_json_array (ecma_object_t *obj_p, /**< the array object*/
ecma_json_stringify_context_t *context_p) /**< context*/
{
+ JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_ARRAY);
+
/* 1. */
if (ecma_json_has_object_in_stack (context_p->occurence_stack_last_p, obj_p))
{
@@ -1742,18 +1739,10 @@ ecma_builtin_json_array (ecma_object_t *obj_p, /**< the array object*/
ecma_collection_header_t *partial_p = ecma_new_values_collection ();
/* 6. */
- ECMA_TRY_CATCH (array_length,
- ecma_op_object_get_by_magic_id (obj_p, LIT_MAGIC_STRING_LENGTH),
- ret_value);
-
- ECMA_OP_TO_NUMBER_TRY_CATCH (array_length_num,
- array_length,
- ret_value);
+ uint32_t array_length = ((ecma_extended_object_t *) obj_p)->u.array.length;
/* 7. - 8. */
- for (uint32_t index = 0;
- index < ecma_number_to_uint32 (array_length_num) && ecma_is_value_empty (ret_value);
- index++)
+ for (uint32_t index = 0; index < array_length && ecma_is_value_empty (ret_value); index++)
{
/* 8.a */
@@ -1810,9 +1799,6 @@ ecma_builtin_json_array (ecma_object_t *obj_p, /**< the array object*/
}
}
- ECMA_OP_TO_NUMBER_FINALIZE (array_length_num);
- ECMA_FINALIZE (array_length);
-
ecma_free_values_collection (partial_p, 0);
/* 11. */
