Use stringbuilder in vm_get_backtrace (#3566)

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2020-02-20 13:01:04 +01:00
committed by GitHub
parent f8da3d5e9d
commit b0a575b049
3 changed files with 9 additions and 11 deletions
-3
View File
@@ -25,9 +25,6 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_ASTERIX_CHAR, "*")
|| ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COMMA_CHAR, ",")
#endif
#if ENABLED (JERRY_LINE_INFO)
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_COLON_CHAR, ":")
#endif
#if ENABLED (JERRY_BUILTIN_MATH)
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_E_U, "E")
#endif
-1
View File
@@ -26,7 +26,6 @@ LIT_MAGIC_STRING__EMPTY = ""
LIT_MAGIC_STRING_ASTERIX_CHAR = "*"
LIT_MAGIC_STRING_SPACE_CHAR = " "
LIT_MAGIC_STRING_COMMA_CHAR = ","
LIT_MAGIC_STRING_COLON_CHAR = ":"
LIT_MAGIC_STRING_E_U = "E"
LIT_MAGIC_STRING_LEFT_SQUARE_CHAR = "["
LIT_MAGIC_STRING_RIGHT_SQUARE_CHAR = "]"
+9 -7
View File
@@ -16,6 +16,7 @@
#include "ecma-array-object.h"
#include "ecma-helpers.h"
#include "jcontext.h"
#include "lit-char-helpers.h"
#include "vm.h"
/**
@@ -82,24 +83,25 @@ vm_get_backtrace (uint32_t max_depth) /**< maximum backtrace depth, 0 = unlimite
}
ecma_string_t *str_p = ecma_get_string_from_value (context_p->resource_name);
ecma_stringbuilder_t builder = ecma_stringbuilder_create ();
if (ecma_string_is_empty (str_p))
{
const lit_utf8_byte_t unknown_str[] = "<unknown>:";
str_p = ecma_new_ecma_string_from_utf8 (unknown_str, sizeof (unknown_str) - 1);
ecma_stringbuilder_append_raw (&builder, (const lit_utf8_byte_t *)"<unknown>:", 10);
}
else
{
ecma_ref_ecma_string (str_p);
str_p = ecma_append_magic_string_to_string (str_p, LIT_MAGIC_STRING_COLON_CHAR);
ecma_stringbuilder_append (&builder, str_p);
ecma_stringbuilder_append_byte (&builder, LIT_CHAR_COLON);
}
ecma_string_t *line_str_p = ecma_new_ecma_string_from_uint32 (context_p->current_line);
str_p = ecma_concat_ecma_strings (str_p, line_str_p);
ecma_stringbuilder_append (&builder, line_str_p);
ecma_deref_ecma_string (line_str_p);
ecma_fast_array_set_property (array_p, index, ecma_make_string_value (str_p));
ecma_deref_ecma_string (str_p);
ecma_string_t *builder_str_p = ecma_stringbuilder_finalize (&builder);
ecma_fast_array_set_property (array_p, index, ecma_make_string_value (builder_str_p));
ecma_deref_ecma_string (builder_str_p);
context_p = context_p->prev_context_p;
index++;