@@ -2925,9 +2925,9 @@ preparse_scope (bool is_global)
2925
2925
2926
2926
opcode_counter_t scope_code_flags_oc = dump_scope_code_flags_for_rewrite ();
2927
2927
2928
+ bool is_use_strict = false ;
2928
2929
bool is_ref_arguments_identifier = false ;
2929
2930
bool is_ref_eval_identifier = false ;
2930
- bool is_use_strict = false ;
2931
2931
2932
2932
/*
2933
2933
* Check Directive Prologue for Use Strict directive (see ECMA-262 5.1 section 14.1)
@@ -2937,7 +2937,6 @@ preparse_scope (bool is_global)
2937
2937
if (lit_literal_equal_type_cstr (lit_get_literal_by_cp (token_data_as_lit_cp ()), " use strict" )
2938
2938
&& lexer_is_no_escape_sequences_in_token_string (tok))
2939
2939
{
2940
- scopes_tree_set_strict_mode (STACK_TOP (scopes), true );
2941
2940
is_use_strict = true ;
2942
2941
break ;
2943
2942
}
@@ -2950,21 +2949,8 @@ preparse_scope (bool is_global)
2950
2949
}
2951
2950
}
2952
2951
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))
2961
2953
{
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
- */
2968
2954
if (token_is (TOK_NAME))
2969
2955
{
2970
2956
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)
2975
2961
{
2976
2962
is_ref_eval_identifier = true ;
2977
2963
}
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 ();
2991
2964
}
2992
- else if (is_in_var_declaration_list)
2993
- {
2994
- if (token_is (TOK_EQ))
2995
- {
2996
- skip_newlines ();
2997
2965
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 ();
3073
2967
}
3074
2968
3075
2969
opcode_scope_code_flags_t scope_flags = OPCODE_SCOPE_CODE_FLAGS__EMPTY;
3076
2970
3077
2971
if (is_use_strict)
3078
2972
{
2973
+ scopes_tree_set_strict_mode (STACK_TOP (scopes), true );
2974
+
3079
2975
scope_flags = (opcode_scope_code_flags_t ) (scope_flags | OPCODE_SCOPE_CODE_FLAGS_STRICT);
3080
2976
}
3081
2977
@@ -3091,12 +2987,126 @@ preparse_scope (bool is_global)
3091
2987
3092
2988
rewrite_scope_code_flags (scope_code_flags_oc, scope_flags);
3093
2989
2990
+ lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes)));
2991
+
2992
+ dump_reg_var_decl_for_rewrite ();
2993
+
3094
2994
if (lit_utf8_iterator_pos_cmp (start_loc, tok.loc ) != 0 )
3095
2995
{
3096
2996
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);
3097
3105
}
3098
3106
else
3099
3107
{
3108
+ JERRY_ASSERT (token_is (end_tt));
3109
+
3100
3110
lexer_save_token (tok);
3101
3111
}
3102
3112
}
0 commit comments