Fix invalid processing of keyword literals.
This commit is contained in:
@@ -166,9 +166,8 @@ adjust_string_ptrs (literal lit, size_t diff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static literal
|
static literal
|
||||||
add_current_token_to_string_cache (void)
|
add_string_to_string_cache (const ecma_char_t* str, ecma_length_t length)
|
||||||
{
|
{
|
||||||
const ecma_length_t length = (ecma_length_t) (buffer - token_start);
|
|
||||||
if (strings_cache_used_size + length * sizeof (ecma_char_t) >= strings_cache_size)
|
if (strings_cache_used_size + length * sizeof (ecma_char_t) >= strings_cache_size)
|
||||||
{
|
{
|
||||||
strings_cache_size = mem_heap_recommend_allocation_size (strings_cache_used_size
|
strings_cache_size = mem_heap_recommend_allocation_size (strings_cache_used_size
|
||||||
@@ -183,13 +182,19 @@ add_current_token_to_string_cache (void)
|
|||||||
}
|
}
|
||||||
strings_cache = temp;
|
strings_cache = temp;
|
||||||
}
|
}
|
||||||
strncpy ((char *) (strings_cache + strings_cache_used_size), token_start, length);
|
strncpy ((char *) (strings_cache + strings_cache_used_size), (const char*) str, length);
|
||||||
(strings_cache + strings_cache_used_size)[length] = '\0';
|
(strings_cache + strings_cache_used_size)[length] = '\0';
|
||||||
const literal res = create_literal_from_zt (strings_cache + strings_cache_used_size, length);
|
const literal res = create_literal_from_zt (strings_cache + strings_cache_used_size, length);
|
||||||
strings_cache_used_size = (size_t) (((size_t) length + 1) * sizeof (ecma_char_t) + strings_cache_used_size);
|
strings_cache_used_size = (size_t) (((size_t) length + 1) * sizeof (ecma_char_t) + strings_cache_used_size);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static literal
|
||||||
|
add_current_token_to_string_cache (void)
|
||||||
|
{
|
||||||
|
return add_string_to_string_cache ((ecma_char_t*) token_start, (ecma_length_t) (buffer - token_start));
|
||||||
|
}
|
||||||
|
|
||||||
static token
|
static token
|
||||||
convert_current_token_to_token (token_type tt)
|
convert_current_token_to_token (token_type tt)
|
||||||
{
|
{
|
||||||
@@ -535,7 +540,7 @@ lexer_get_strings_cache (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lexer_add_literal_if_not_present (literal lit)
|
lexer_add_keyword_or_numeric_literal_if_not_present (literal lit)
|
||||||
{
|
{
|
||||||
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++)
|
for (literal_index_t i = 0; i < STACK_SIZE (literals); i++)
|
||||||
{
|
{
|
||||||
@@ -544,6 +549,12 @@ lexer_add_literal_if_not_present (literal lit)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lit.type == LIT_STR)
|
||||||
|
{
|
||||||
|
lit = add_string_to_string_cache (lit.data.lp.str, lit.data.lp.length);
|
||||||
|
}
|
||||||
|
|
||||||
STACK_PUSH (literals, lit);
|
STACK_PUSH (literals, lit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ token lexer_prev_token (void);
|
|||||||
|
|
||||||
const literal *lexer_get_literals (void);
|
const literal *lexer_get_literals (void);
|
||||||
const ecma_char_t *lexer_get_strings_cache (void);
|
const ecma_char_t *lexer_get_strings_cache (void);
|
||||||
void lexer_add_literal_if_not_present (literal);
|
void lexer_add_keyword_or_numeric_literal_if_not_present (literal);
|
||||||
literal_index_t lexer_get_literals_count (void);
|
literal_index_t lexer_get_literals_count (void);
|
||||||
literal lexer_get_literal_by_id (literal_index_t);
|
literal lexer_get_literal_by_id (literal_index_t);
|
||||||
literal_index_t lexer_lookup_literal_uid (literal lit);
|
literal_index_t lexer_lookup_literal_uid (literal lit);
|
||||||
|
|||||||
@@ -226,14 +226,14 @@ parse_property_name (void)
|
|||||||
case TOK_SMALL_INT:
|
case TOK_SMALL_INT:
|
||||||
{
|
{
|
||||||
const literal lit = create_literal_from_num ((ecma_number_t) token_data ());
|
const literal lit = create_literal_from_num ((ecma_number_t) token_data ());
|
||||||
lexer_add_literal_if_not_present (lit);
|
lexer_add_keyword_or_numeric_literal_if_not_present (lit);
|
||||||
const literal_index_t lit_id = lexer_lookup_literal_uid (lit);
|
const literal_index_t lit_id = lexer_lookup_literal_uid (lit);
|
||||||
return literal_operand (lit_id);
|
return literal_operand (lit_id);
|
||||||
}
|
}
|
||||||
case TOK_KEYWORD:
|
case TOK_KEYWORD:
|
||||||
{
|
{
|
||||||
const literal lit = create_literal_from_str_compute_len (lexer_keyword_to_string ((keyword) token_data ()));
|
const literal lit = create_literal_from_str_compute_len (lexer_keyword_to_string ((keyword) token_data ()));
|
||||||
lexer_add_literal_if_not_present (lit);
|
lexer_add_keyword_or_numeric_literal_if_not_present (lit);
|
||||||
const literal_index_t lit_id = lexer_lookup_literal_uid (lit);
|
const literal_index_t lit_id = lexer_lookup_literal_uid (lit);
|
||||||
return literal_operand (lit_id);
|
return literal_operand (lit_id);
|
||||||
}
|
}
|
||||||
@@ -2486,7 +2486,8 @@ skip_braces (void)
|
|||||||
skip_newlines ();
|
skip_newlines ();
|
||||||
if (token_is (TOK_COLON))
|
if (token_is (TOK_COLON))
|
||||||
{
|
{
|
||||||
lexer_add_literal_if_not_present (create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
|
lexer_add_keyword_or_numeric_literal_if_not_present (
|
||||||
|
create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2505,7 +2506,8 @@ skip_braces (void)
|
|||||||
skip_newlines ();
|
skip_newlines ();
|
||||||
if (token_is (TOK_OPEN_PAREN))
|
if (token_is (TOK_OPEN_PAREN))
|
||||||
{
|
{
|
||||||
lexer_add_literal_if_not_present (create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
|
lexer_add_keyword_or_numeric_literal_if_not_present (
|
||||||
|
create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user