Skip to content

Commit abc2b55

Browse files
ruben-ayrapetyanegavrin
authored andcommitted
Fix dump of arguments / eval usage hint in preparse_scope.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent 005eb04 commit abc2b55

File tree

2 files changed

+123
-109
lines changed

2 files changed

+123
-109
lines changed

jerry-core/parser/js/parser.cpp

Lines changed: 119 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,9 +2925,9 @@ preparse_scope (bool is_global)
29252925

29262926
opcode_counter_t scope_code_flags_oc = dump_scope_code_flags_for_rewrite ();
29272927

2928+
bool is_use_strict = false;
29282929
bool is_ref_arguments_identifier = false;
29292930
bool is_ref_eval_identifier = false;
2930-
bool is_use_strict = false;
29312931

29322932
/*
29332933
* Check Directive Prologue for Use Strict directive (see ECMA-262 5.1 section 14.1)
@@ -2937,7 +2937,6 @@ preparse_scope (bool is_global)
29372937
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "use strict")
29382938
&& lexer_is_no_escape_sequences_in_token_string (tok))
29392939
{
2940-
scopes_tree_set_strict_mode (STACK_TOP (scopes), true);
29412940
is_use_strict = true;
29422941
break;
29432942
}
@@ -2950,21 +2949,8 @@ preparse_scope (bool is_global)
29502949
}
29512950
}
29522951

2953-
lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes)));
2954-
2955-
dump_reg_var_decl_for_rewrite ();
2956-
2957-
bool is_in_var_declaration_list = false;
2958-
2959-
size_t nesting_level = 0;
2960-
while (nesting_level > 0 || !token_is (end_tt))
2952+
while (!token_is (end_tt))
29612953
{
2962-
/*
2963-
* FIXME:
2964-
* Remove preparse_scope; move variable declaration search to main pass of parser.
2965-
* When byte-code and scope storages would be introduced, move variable declarations
2966-
* from byte-code to scope descriptor.
2967-
*/
29682954
if (token_is (TOK_NAME))
29692955
{
29702956
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), "arguments"))
@@ -2975,107 +2961,17 @@ preparse_scope (bool is_global)
29752961
{
29762962
is_ref_eval_identifier = true;
29772963
}
2978-
2979-
if (is_in_var_declaration_list)
2980-
{
2981-
if (!var_declared (token_data_as_lit_cp ()))
2982-
{
2983-
jsp_early_error_check_for_eval_and_arguments_in_strict_mode (literal_operand (token_data_as_lit_cp ()),
2984-
is_strict_mode (),
2985-
tok.loc);
2986-
dump_variable_declaration (token_data_as_lit_cp ());
2987-
}
2988-
}
2989-
2990-
skip_newlines ();
29912964
}
2992-
else if (is_in_var_declaration_list)
2993-
{
2994-
if (token_is (TOK_EQ))
2995-
{
2996-
skip_newlines ();
29972965

2998-
while (!token_is (end_tt)
2999-
&& !token_is (TOK_COMMA)
3000-
&& !token_is (TOK_SEMICOLON))
3001-
{
3002-
if (is_keyword (KW_FUNCTION))
3003-
{
3004-
skip_function ();
3005-
}
3006-
else if (token_is (TOK_OPEN_BRACE))
3007-
{
3008-
jsp_skip_braces (TOK_OPEN_BRACE);
3009-
}
3010-
else if (token_is (TOK_OPEN_SQUARE))
3011-
{
3012-
jsp_skip_braces (TOK_OPEN_SQUARE);
3013-
}
3014-
else if (token_is (TOK_OPEN_PAREN))
3015-
{
3016-
jsp_skip_braces (TOK_OPEN_PAREN);
3017-
}
3018-
else if (token_is (TOK_KEYWORD))
3019-
{
3020-
if (is_keyword (KW_VAR))
3021-
{
3022-
is_in_var_declaration_list = false;
3023-
}
3024-
break;
3025-
}
3026-
else if (token_is (TOK_CLOSE_BRACE))
3027-
{
3028-
/* the '}' would be handled during next iteration, reducing nesting level counter */
3029-
is_in_var_declaration_list = false;
3030-
3031-
break;
3032-
}
3033-
3034-
skip_token ();
3035-
}
3036-
}
3037-
else if (token_is (TOK_COMMA))
3038-
{
3039-
skip_newlines ();
3040-
}
3041-
else
3042-
{
3043-
is_in_var_declaration_list = false;
3044-
3045-
skip_newlines ();
3046-
}
3047-
}
3048-
else
3049-
{
3050-
if (token_is (TOK_OPEN_BRACE))
3051-
{
3052-
nesting_level++;
3053-
}
3054-
else if (token_is (TOK_CLOSE_BRACE))
3055-
{
3056-
nesting_level--;
3057-
}
3058-
else if (token_is (TOK_OPEN_SQUARE))
3059-
{
3060-
jsp_skip_braces (TOK_OPEN_SQUARE);
3061-
}
3062-
else if (is_keyword (KW_VAR))
3063-
{
3064-
is_in_var_declaration_list = true;
3065-
}
3066-
else if (is_keyword (KW_FUNCTION))
3067-
{
3068-
skip_function ();
3069-
}
3070-
3071-
skip_newlines ();
3072-
}
2966+
skip_newlines ();
30732967
}
30742968

30752969
opcode_scope_code_flags_t scope_flags = OPCODE_SCOPE_CODE_FLAGS__EMPTY;
30762970

30772971
if (is_use_strict)
30782972
{
2973+
scopes_tree_set_strict_mode (STACK_TOP (scopes), true);
2974+
30792975
scope_flags = (opcode_scope_code_flags_t) (scope_flags | OPCODE_SCOPE_CODE_FLAGS_STRICT);
30802976
}
30812977

@@ -3091,12 +2987,126 @@ preparse_scope (bool is_global)
30912987

30922988
rewrite_scope_code_flags (scope_code_flags_oc, scope_flags);
30932989

2990+
lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes)));
2991+
2992+
dump_reg_var_decl_for_rewrite ();
2993+
30942994
if (lit_utf8_iterator_pos_cmp (start_loc, tok.loc) != 0)
30952995
{
30962996
lexer_seek (start_loc);
2997+
skip_newlines ();
2998+
2999+
bool is_in_var_declaration_list = false;
3000+
3001+
size_t nesting_level = 0;
3002+
while (nesting_level > 0 || !token_is (end_tt))
3003+
{
3004+
/*
3005+
* FIXME:
3006+
* Remove preparse_scope; move variable declaration search to main pass of parser.
3007+
* When byte-code and scope storages would be introduced, move variable declarations
3008+
* from byte-code to scope descriptor.
3009+
*/
3010+
if (token_is (TOK_NAME))
3011+
{
3012+
if (is_in_var_declaration_list)
3013+
{
3014+
if (!var_declared (token_data_as_lit_cp ()))
3015+
{
3016+
jsp_early_error_check_for_eval_and_arguments_in_strict_mode (literal_operand (token_data_as_lit_cp ()),
3017+
is_strict_mode (),
3018+
tok.loc);
3019+
dump_variable_declaration (token_data_as_lit_cp ());
3020+
}
3021+
}
3022+
3023+
skip_newlines ();
3024+
}
3025+
else if (is_in_var_declaration_list)
3026+
{
3027+
if (token_is (TOK_EQ))
3028+
{
3029+
skip_newlines ();
3030+
3031+
while (!token_is (end_tt)
3032+
&& !token_is (TOK_COMMA)
3033+
&& !token_is (TOK_SEMICOLON))
3034+
{
3035+
if (is_keyword (KW_FUNCTION))
3036+
{
3037+
skip_function ();
3038+
}
3039+
else if (token_is (TOK_OPEN_BRACE))
3040+
{
3041+
jsp_skip_braces (TOK_OPEN_BRACE);
3042+
}
3043+
else if (token_is (TOK_OPEN_SQUARE))
3044+
{
3045+
jsp_skip_braces (TOK_OPEN_SQUARE);
3046+
}
3047+
else if (token_is (TOK_OPEN_PAREN))
3048+
{
3049+
jsp_skip_braces (TOK_OPEN_PAREN);
3050+
}
3051+
else if (token_is (TOK_KEYWORD))
3052+
{
3053+
break;
3054+
}
3055+
else if (token_is (TOK_CLOSE_BRACE))
3056+
{
3057+
/* the '}' would be handled during next iteration, reducing nesting level counter */
3058+
is_in_var_declaration_list = false;
3059+
3060+
break;
3061+
}
3062+
3063+
skip_token ();
3064+
}
3065+
}
3066+
else if (token_is (TOK_COMMA))
3067+
{
3068+
skip_newlines ();
3069+
}
3070+
else
3071+
{
3072+
is_in_var_declaration_list = false;
3073+
3074+
skip_newlines ();
3075+
}
3076+
}
3077+
else
3078+
{
3079+
if (token_is (TOK_OPEN_BRACE))
3080+
{
3081+
nesting_level++;
3082+
}
3083+
else if (token_is (TOK_CLOSE_BRACE))
3084+
{
3085+
nesting_level--;
3086+
}
3087+
else if (token_is (TOK_OPEN_SQUARE))
3088+
{
3089+
jsp_skip_braces (TOK_OPEN_SQUARE);
3090+
}
3091+
else if (is_keyword (KW_VAR))
3092+
{
3093+
is_in_var_declaration_list = true;
3094+
}
3095+
else if (is_keyword (KW_FUNCTION))
3096+
{
3097+
skip_function ();
3098+
}
3099+
3100+
skip_newlines ();
3101+
}
3102+
}
3103+
3104+
lexer_seek (start_loc);
30973105
}
30983106
else
30993107
{
3108+
JERRY_ASSERT (token_is (end_tt));
3109+
31003110
lexer_save_token (tok);
31013111
}
31023112
}

tests/jerry/arguments.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,7 @@ fn_expr = function (a, b, c)
125125
}
126126

127127
fn_expr (1);
128+
129+
(function () {
130+
var a = [arguments];
131+
})();

0 commit comments

Comments
 (0)