@@ -1005,7 +1005,10 @@ static ecma_value_t
10051005ecma_builtin_json_serialize_array (ecma_json_stringify_context_t * context_p , /**< context*/
10061006 ecma_object_t * obj_p ) /**< the array object*/
10071007{
1008- JERRY_ASSERT (ecma_get_object_type (obj_p ) == ECMA_OBJECT_TYPE_ARRAY );
1008+ ecma_value_t obj_value = ecma_make_object_value (obj_p );
1009+ ecma_value_t is_array = ecma_is_value_array (obj_value );
1010+
1011+ JERRY_ASSERT (ecma_is_value_true (is_array ));
10091012
10101013 /* 1. */
10111014 if (ecma_json_has_object_in_stack (context_p -> occurence_stack_last_p , obj_p ))
@@ -1027,7 +1030,35 @@ ecma_builtin_json_serialize_array (ecma_json_stringify_context_t *context_p, /**
10271030 const bool has_gap = !ecma_compare_ecma_string_to_magic_id (context_p -> gap_str_p , LIT_MAGIC_STRING__EMPTY );
10281031
10291032 /* 6. */
1030- uint32_t array_length = ((ecma_extended_object_t * ) obj_p )-> u .array .length ;
1033+ uint32_t array_length ;
1034+
1035+ #if ENABLED (JERRY_ES2015_BUILTIN_PROXY )
1036+ if (ECMA_OBJECT_IS_PROXY (obj_p ))
1037+ {
1038+ ecma_value_t length_value = ecma_op_object_get_by_magic_id (obj_p , LIT_MAGIC_STRING_LENGTH );
1039+
1040+ if (ECMA_IS_VALUE_ERROR (length_value ))
1041+ {
1042+ return length_value ;
1043+ }
1044+
1045+ ecma_number_t length_number ;
1046+
1047+ if (ECMA_IS_VALUE_ERROR (ecma_get_number (length_value , & length_number )))
1048+ {
1049+ ecma_free_value (length_value );
1050+ return ECMA_VALUE_ERROR ;
1051+ }
1052+
1053+ ecma_free_value (length_value );
1054+
1055+ array_length = ecma_number_to_uint32 (length_number );
1056+ }
1057+ else
1058+ #endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
1059+ {
1060+ array_length = ((ecma_extended_object_t * ) obj_p )-> u .array .length ;
1061+ }
10311062
10321063 ecma_stringbuilder_append_byte (& context_p -> result_builder , LIT_CHAR_LEFT_SQUARE );
10331064
@@ -1260,11 +1291,20 @@ ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p,
12601291 /* 11. */
12611292 if (ecma_is_value_object (value ) && !ecma_op_is_callable (value ))
12621293 {
1294+ ecma_value_t is_array = ecma_is_value_array (value );
1295+
1296+ #if ENABLED (JERRY_ES2015 )
1297+ if (ECMA_IS_VALUE_ERROR (is_array ))
1298+ {
1299+ return is_array ;
1300+ }
1301+ #endif /* ENABLED (JERRY_ES2015) */
1302+
12631303 ecma_object_t * obj_p = ecma_get_object_from_value (value );
12641304
12651305 ecma_value_t ret_value ;
12661306 /* 10.a */
1267- if (ecma_get_object_type ( obj_p ) == ECMA_OBJECT_TYPE_ARRAY )
1307+ if (ecma_is_value_true ( is_array ) )
12681308 {
12691309 ret_value = ecma_builtin_json_serialize_array (context_p , obj_p );
12701310 }
0 commit comments