@@ -1971,6 +1971,59 @@ JERRY_STATIC_ASSERT (PARSER_SCANNING_SUCCESSFUL == PARSER_HAS_LATE_LIT_INIT,
1971
1971
parser_scanning_successful_should_share_the_bit_position_with_parser_has_late_lit_init );
1972
1972
#endif /* !JERRY_NDEBUG */
1973
1973
1974
+ /**
1975
+ * Parser script size
1976
+ */
1977
+ static size_t
1978
+ parser_script_size (parser_context_t * context_p ) /**< context */
1979
+ {
1980
+ size_t script_size = sizeof (cbc_script_t );
1981
+
1982
+ if (context_p -> user_value != ECMA_VALUE_EMPTY )
1983
+ {
1984
+ script_size += sizeof (ecma_value_t );
1985
+ }
1986
+
1987
+ #if JERRY_FUNCTION_TO_STRING
1988
+ if (context_p -> argument_list != ECMA_VALUE_EMPTY )
1989
+ {
1990
+ script_size += sizeof (ecma_value_t );
1991
+ }
1992
+ #endif /* JERRY_FUNCTION_TO_STRING */
1993
+
1994
+ #if JERRY_MODULE_SYSTEM
1995
+ if (context_p -> global_status_flags & ECMA_PARSE_INTERNAL_HAS_IMPORT_META )
1996
+ {
1997
+ script_size += sizeof (ecma_value_t );
1998
+ }
1999
+ #endif /* JERRY_MODULE_SYSTEM */
2000
+ return script_size ;
2001
+ } /* parser_script_size */
2002
+
2003
+ #if JERRY_SOURCE_NAME
2004
+ /**
2005
+ * Parser resource name
2006
+ */
2007
+ static ecma_value_t
2008
+ parser_source_name (parser_context_t * context_p ) /**< context */
2009
+ {
2010
+ if (context_p -> options_p != NULL && (context_p -> options_p -> options & JERRY_PARSE_HAS_SOURCE_NAME ))
2011
+ {
2012
+ JERRY_ASSERT (ecma_is_value_string (context_p -> options_p -> source_name ));
2013
+
2014
+ ecma_ref_ecma_string (ecma_get_string_from_value (context_p -> options_p -> source_name ));
2015
+ return context_p -> options_p -> source_name ;
2016
+ }
2017
+
2018
+ if (context_p -> global_status_flags & ECMA_PARSE_EVAL )
2019
+ {
2020
+ return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_EVAL );
2021
+ }
2022
+
2023
+ return ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON );
2024
+ } /* parser_source_name */
2025
+ #endif /* JERRY_SOURCE_NAME */
2026
+
1974
2027
/**
1975
2028
* Parse and compile EcmaScript source code
1976
2029
*
@@ -2108,22 +2161,6 @@ parser_parse_source (void *source_p, /**< source code */
2108
2161
context .user_value = context .options_p -> user_value ;
2109
2162
}
2110
2163
2111
- #if JERRY_SOURCE_NAME
2112
- ecma_value_t source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_ANON );
2113
-
2114
- if (context .options_p != NULL && (context .options_p -> options & JERRY_PARSE_HAS_SOURCE_NAME ))
2115
- {
2116
- JERRY_ASSERT (ecma_is_value_string (context .options_p -> source_name ));
2117
-
2118
- ecma_ref_ecma_string (ecma_get_string_from_value (context .options_p -> source_name ));
2119
- source_name = context .options_p -> source_name ;
2120
- }
2121
- else if (context .global_status_flags & ECMA_PARSE_EVAL )
2122
- {
2123
- source_name = ecma_make_magic_string_value (LIT_MAGIC_STRING_SOURCE_NAME_EVAL );
2124
- }
2125
- #endif /* JERRY_SOURCE_NAME */
2126
-
2127
2164
context .last_context_p = NULL ;
2128
2165
context .last_statement .current_p = NULL ;
2129
2166
context .token .flags = 0 ;
@@ -2197,27 +2234,6 @@ parser_parse_source (void *source_p, /**< source code */
2197
2234
return NULL ;
2198
2235
}
2199
2236
2200
- size_t script_size = sizeof (cbc_script_t );
2201
-
2202
- if (context .user_value != ECMA_VALUE_EMPTY )
2203
- {
2204
- script_size += sizeof (ecma_value_t );
2205
- }
2206
-
2207
- #if JERRY_FUNCTION_TO_STRING
2208
- if (context .argument_list != ECMA_VALUE_EMPTY )
2209
- {
2210
- script_size += sizeof (ecma_value_t );
2211
- }
2212
- #endif /* JERRY_FUNCTION_TO_STRING */
2213
-
2214
- #if JERRY_MODULE_SYSTEM
2215
- if (context .global_status_flags & ECMA_PARSE_INTERNAL_HAS_IMPORT_META )
2216
- {
2217
- script_size += sizeof (ecma_value_t );
2218
- }
2219
- #endif /* JERRY_MODULE_SYSTEM */
2220
-
2221
2237
if (context .arguments_start_p == NULL )
2222
2238
{
2223
2239
context .source_p = context .source_start_p ;
@@ -2249,7 +2265,7 @@ parser_parse_source (void *source_p, /**< source code */
2249
2265
2250
2266
PARSER_TRY (context .try_buffer )
2251
2267
{
2252
- context .script_p = parser_malloc (& context , script_size );
2268
+ context .script_p = parser_malloc (& context , parser_script_size ( & context ) );
2253
2269
2254
2270
CBC_SCRIPT_SET_TYPE (context .script_p , context .user_value , CBC_SCRIPT_REF_ONE );
2255
2271
@@ -2263,7 +2279,7 @@ parser_parse_source (void *source_p, /**< source code */
2263
2279
#endif /* JERRY_BUILTIN_REALMS */
2264
2280
2265
2281
#if JERRY_SOURCE_NAME
2266
- context .script_p -> source_name = source_name ;
2282
+ context .script_p -> source_name = parser_source_name ( & context ) ;
2267
2283
#endif /* JERRY_SOURCE_NAME */
2268
2284
2269
2285
ECMA_SET_INTERNAL_VALUE_POINTER (context .script_value , context .script_p );
@@ -2437,7 +2453,7 @@ parser_parse_source (void *source_p, /**< source code */
2437
2453
if (context .script_p != NULL )
2438
2454
{
2439
2455
JERRY_ASSERT (context .script_p -> refs_and_type >= CBC_SCRIPT_REF_ONE );
2440
- jmem_heap_free_block (context .script_p , script_size );
2456
+ jmem_heap_free_block (context .script_p , parser_script_size ( & context ) );
2441
2457
}
2442
2458
}
2443
2459
PARSER_TRY_END
@@ -2512,6 +2528,7 @@ parser_parse_source (void *source_p, /**< source code */
2512
2528
ecma_value_t err_str_val = ecma_make_string_value (err_str_p );
2513
2529
ecma_value_t line_str_val = ecma_make_uint32_value (context .token .line );
2514
2530
ecma_value_t col_str_val = ecma_make_uint32_value (context .token .column );
2531
+ ecma_value_t source_name = parser_source_name (& context );
2515
2532
2516
2533
ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX ,
2517
2534
"% [%:%:%]" ,
@@ -2520,6 +2537,7 @@ parser_parse_source (void *source_p, /**< source code */
2520
2537
line_str_val ,
2521
2538
col_str_val );
2522
2539
2540
+ ecma_free_value (source_name );
2523
2541
ecma_free_value (col_str_val );
2524
2542
ecma_free_value (line_str_val );
2525
2543
ecma_deref_ecma_string (err_str_p );
0 commit comments