@@ -917,22 +917,22 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
917
917
{
918
918
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
919
919
920
- stringify_context_t context_p ;
920
+ stringify_context_t context ;
921
921
922
922
/* 1. */
923
- context_p .occurence_stack .block_start_p = NULL ;
924
- context_p .occurence_stack .block_end_p = NULL ;
925
- context_p .occurence_stack .current_p = NULL ;
923
+ context .occurence_stack .block_start_p = NULL ;
924
+ context .occurence_stack .block_end_p = NULL ;
925
+ context .occurence_stack .current_p = NULL ;
926
926
927
927
/* 2. */
928
- context_p .indent_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
928
+ context .indent_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
929
929
930
930
/* 3. */
931
- context_p .property_list .block_start_p = NULL ;
932
- context_p .property_list .block_end_p = NULL ;
933
- context_p .property_list .current_p = NULL ;
931
+ context .property_list .block_start_p = NULL ;
932
+ context .property_list .block_end_p = NULL ;
933
+ context .property_list .current_p = NULL ;
934
934
935
- context_p .replacer_function_p = NULL ;
935
+ context .replacer_function_p = NULL ;
936
936
937
937
/* 4. */
938
938
if (ecma_is_value_object (arg2))
@@ -942,7 +942,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
942
942
/* 4.a */
943
943
if (ecma_op_is_callable (arg2))
944
944
{
945
- context_p .replacer_function_p = obj_p;
945
+ context .replacer_function_p = obj_p;
946
946
}
947
947
/* 4.b */
948
948
else if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_ARRAY_UL)
@@ -1013,9 +1013,9 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1013
1013
{
1014
1014
ecma_string_t *item_str_p = ecma_get_string_from_value (item);
1015
1015
1016
- if (!list_has_ecma_string_element (&context_p .property_list , item_str_p))
1016
+ if (!list_has_ecma_string_element (&context .property_list , item_str_p))
1017
1017
{
1018
- list_append (&context_p .property_list , item_str_p);
1018
+ list_append (&context .property_list , item_str_p);
1019
1019
}
1020
1020
else
1021
1021
{
@@ -1085,7 +1085,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1085
1085
/* 6.b */
1086
1086
if (space < 1 )
1087
1087
{
1088
- context_p .gap_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
1088
+ context .gap_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
1089
1089
}
1090
1090
else
1091
1091
{
@@ -1096,7 +1096,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1096
1096
space_buff[i] = LIT_CHAR_SP;
1097
1097
}
1098
1098
1099
- context_p .gap_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) space_buff, (lit_utf8_size_t ) space);
1099
+ context .gap_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) space_buff, (lit_utf8_size_t ) space);
1100
1100
1101
1101
MEM_FINALIZE_LOCAL_ARRAY (space_buff);
1102
1102
}
@@ -1111,38 +1111,17 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1111
1111
1112
1112
if (num_of_chars < 10 )
1113
1113
{
1114
- context_p .gap_str_p = ecma_copy_or_ref_ecma_string (space_str_p);
1114
+ context .gap_str_p = ecma_copy_or_ref_ecma_string (space_str_p);
1115
1115
}
1116
1116
else
1117
1117
{
1118
- ecma_length_t string_len = ecma_string_get_length (space_str_p);
1119
-
1120
- MEM_DEFINE_LOCAL_ARRAY (zt_string_buff, string_len, lit_utf8_byte_t );
1121
-
1122
- size_t string_buf_size = (size_t ) (string_len) * sizeof (lit_utf8_byte_t );
1123
- ssize_t bytes_copied = ecma_string_to_utf8_string (space_str_p,
1124
- zt_string_buff,
1125
- (ssize_t ) string_buf_size);
1126
- JERRY_ASSERT (bytes_copied > 0 );
1127
-
1128
- /* Buffer for the first 10 characters. */
1129
- MEM_DEFINE_LOCAL_ARRAY (space_buff, 10 , lit_utf8_byte_t );
1130
-
1131
- for (uint32_t i = 0 ; i < 10 ; i++)
1132
- {
1133
- space_buff[i] = zt_string_buff[i];
1134
- }
1135
-
1136
- context_p.gap_str_p = ecma_new_ecma_string_from_utf8 ((lit_utf8_byte_t *) space_buff, 10 );
1137
-
1138
- MEM_FINALIZE_LOCAL_ARRAY (space_buff);
1139
- MEM_FINALIZE_LOCAL_ARRAY (zt_string_buff);
1118
+ context.gap_str_p = ecma_string_substr (space_str_p, 0 , 10 );
1140
1119
}
1141
1120
}
1142
1121
/* 8. */
1143
1122
else
1144
1123
{
1145
- context_p .gap_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
1124
+ context .gap_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
1146
1125
}
1147
1126
1148
1127
ecma_free_value (space, true );
@@ -1162,7 +1141,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1162
1141
1163
1142
/* 11. */
1164
1143
ECMA_TRY_CATCH (str_val,
1165
- ecma_builtin_json_str (empty_str_p, obj_wrapper_p, &context_p ),
1144
+ ecma_builtin_json_str (empty_str_p, obj_wrapper_p, &context ),
1166
1145
ret_value);
1167
1146
1168
1147
ret_value = ecma_make_normal_completion_value (ecma_copy_value (str_val, true ));
@@ -1172,11 +1151,11 @@ ecma_builtin_json_stringify (ecma_value_t this_arg __attr_unused___, /**< 'this'
1172
1151
ecma_deref_object (obj_wrapper_p);
1173
1152
ecma_deref_ecma_string (empty_str_p);
1174
1153
1175
- ecma_deref_ecma_string (context_p .indent_str_p );
1176
- ecma_deref_ecma_string (context_p .gap_str_p );
1154
+ ecma_deref_ecma_string (context .indent_str_p );
1155
+ ecma_deref_ecma_string (context .gap_str_p );
1177
1156
1178
- free_list_with_ecma_string_content (&context_p .property_list );
1179
- free_list (&context_p .occurence_stack );
1157
+ free_list_with_ecma_string_content (&context .property_list );
1158
+ free_list (&context .occurence_stack );
1180
1159
1181
1160
return ret_value;
1182
1161
} /* ecma_builtin_json_stringify */
@@ -1198,23 +1177,24 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1198
1177
ecma_string_t *product_str_p = ecma_copy_or_ref_ecma_string (quote_str_p);
1199
1178
ecma_string_t *tmp_str_p;
1200
1179
1201
- ecma_length_t string_len = ecma_string_get_length (string_p);
1180
+ ecma_length_t string_size = ecma_string_get_size (string_p);
1202
1181
1203
- MEM_DEFINE_LOCAL_ARRAY (zt_string_buff, string_len , lit_utf8_byte_t );
1182
+ MEM_DEFINE_LOCAL_ARRAY (string_buff, string_size , lit_utf8_byte_t );
1204
1183
1205
- size_t string_buf_size = (size_t ) (string_len) * sizeof (lit_utf8_byte_t );
1206
1184
ssize_t bytes_copied = ecma_string_to_utf8_string (string_p,
1207
- zt_string_buff,
1208
- (ssize_t ) string_buf_size);
1209
- JERRY_ASSERT (bytes_copied > 0 || !string_len);
1185
+ string_buff,
1186
+ (ssize_t ) string_size);
1210
1187
1211
- /* 2. */
1212
- for (ecma_length_t i = 0 ; i < string_len; i++)
1188
+ JERRY_ASSERT (bytes_copied > 0 || !string_size);
1189
+
1190
+ lit_utf8_iterator_t iter = lit_utf8_iterator_create (string_buff, string_size);
1191
+
1192
+ while (!lit_utf8_iterator_is_eos (&iter))
1213
1193
{
1214
- lit_utf8_byte_t c = zt_string_buff[i] ;
1194
+ ecma_char_t current_char = lit_utf8_iterator_read_next (&iter) ;
1215
1195
1216
1196
/* 2.a */
1217
- if (c == LIT_CHAR_BACKSLASH || c == LIT_CHAR_DOUBLE_QUOTE)
1197
+ if (current_char == LIT_CHAR_BACKSLASH || current_char == LIT_CHAR_DOUBLE_QUOTE)
1218
1198
{
1219
1199
ecma_string_t *backslash_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_BACKSLASH_CHAR);
1220
1200
@@ -1225,16 +1205,19 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1225
1205
product_str_p = tmp_str_p;
1226
1206
1227
1207
/* 2.a.ii */
1228
- ecma_string_t *c_str_p = ecma_new_ecma_string_from_utf8 (&c, 1 );
1208
+ ecma_string_t *current_char_str_p = ecma_new_ecma_string_from_code_unit (current_char );
1229
1209
1230
- tmp_str_p = ecma_concat_ecma_strings (product_str_p, c_str_p );
1210
+ tmp_str_p = ecma_concat_ecma_strings (product_str_p, current_char_str_p );
1231
1211
ecma_deref_ecma_string (product_str_p);
1232
- ecma_deref_ecma_string (c_str_p );
1212
+ ecma_deref_ecma_string (current_char_str_p );
1233
1213
product_str_p = tmp_str_p;
1234
1214
}
1235
1215
/* 2.b */
1236
- else if (c == LIT_CHAR_BS || c == LIT_CHAR_FF || c == LIT_CHAR_LF
1237
- || c == LIT_CHAR_CR || c == LIT_CHAR_TAB)
1216
+ else if (current_char == LIT_CHAR_BS
1217
+ || current_char == LIT_CHAR_FF
1218
+ || current_char == LIT_CHAR_LF
1219
+ || current_char == LIT_CHAR_CR
1220
+ || current_char == LIT_CHAR_TAB)
1238
1221
{
1239
1222
ecma_string_t *backslash_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_BACKSLASH_CHAR);
1240
1223
@@ -1247,7 +1230,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1247
1230
/* 2.b.ii */
1248
1231
lit_utf8_byte_t abbrev = LIT_CHAR_SP;
1249
1232
1250
- switch (c )
1233
+ switch (current_char )
1251
1234
{
1252
1235
case LIT_CHAR_BS:
1253
1236
{
@@ -1285,7 +1268,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1285
1268
product_str_p = tmp_str_p;
1286
1269
}
1287
1270
/* 2.c */
1288
- else if (c < LIT_CHAR_SP)
1271
+ else if (current_char < LIT_CHAR_SP)
1289
1272
{
1290
1273
ecma_string_t *backslash_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_BACKSLASH_CHAR);
1291
1274
@@ -1305,7 +1288,7 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1305
1288
product_str_p = tmp_str_p;
1306
1289
1307
1290
/* 2.c.iii */
1308
- ecma_string_t *hex_str_p = ecma_builtin_helper_json_create_hex_digit_ecma_string (c );
1291
+ ecma_string_t *hex_str_p = ecma_builtin_helper_json_create_hex_digit_ecma_string (( uint8_t ) current_char );
1309
1292
1310
1293
/* 2.c.iv */
1311
1294
tmp_str_p = ecma_concat_ecma_strings (product_str_p, hex_str_p);
@@ -1316,16 +1299,16 @@ ecma_builtin_json_quote (ecma_string_t *string_p) /**< string that should be quo
1316
1299
/* 2.d */
1317
1300
else
1318
1301
{
1319
- ecma_string_t *c_str_p = ecma_new_ecma_string_from_utf8 (&c, 1 );
1302
+ ecma_string_t *current_char_str_p = ecma_new_ecma_string_from_code_unit (current_char );
1320
1303
1321
- tmp_str_p = ecma_concat_ecma_strings (product_str_p, c_str_p );
1304
+ tmp_str_p = ecma_concat_ecma_strings (product_str_p, current_char_str_p );
1322
1305
ecma_deref_ecma_string (product_str_p);
1323
- ecma_deref_ecma_string (c_str_p );
1306
+ ecma_deref_ecma_string (current_char_str_p );
1324
1307
product_str_p = tmp_str_p;
1325
1308
}
1326
1309
}
1327
1310
1328
- MEM_FINALIZE_LOCAL_ARRAY (zt_string_buff );
1311
+ MEM_FINALIZE_LOCAL_ARRAY (string_buff );
1329
1312
1330
1313
/* 3. */
1331
1314
tmp_str_p = ecma_concat_ecma_strings (product_str_p, quote_str_p);
0 commit comments