@@ -1971,6 +1971,59 @@ JERRY_STATIC_ASSERT (PARSER_SCANNING_SUCCESSFUL == PARSER_HAS_LATE_LIT_INIT,
19711971 parser_scanning_successful_should_share_the_bit_position_with_parser_has_late_lit_init );
19721972#endif /* !JERRY_NDEBUG */
19731973
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+
19742027/**
19752028 * Parse and compile EcmaScript source code
19762029 *
@@ -2108,22 +2161,6 @@ parser_parse_source (void *source_p, /**< source code */
21082161 context .user_value = context .options_p -> user_value ;
21092162 }
21102163
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-
21272164 context .last_context_p = NULL ;
21282165 context .last_statement .current_p = NULL ;
21292166 context .token .flags = 0 ;
@@ -2197,27 +2234,6 @@ parser_parse_source (void *source_p, /**< source code */
21972234 return NULL ;
21982235 }
21992236
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-
22212237 if (context .arguments_start_p == NULL )
22222238 {
22232239 context .source_p = context .source_start_p ;
@@ -2249,7 +2265,7 @@ parser_parse_source (void *source_p, /**< source code */
22492265
22502266 PARSER_TRY (context .try_buffer )
22512267 {
2252- context .script_p = parser_malloc (& context , script_size );
2268+ context .script_p = parser_malloc (& context , parser_script_size ( & context ) );
22532269
22542270 CBC_SCRIPT_SET_TYPE (context .script_p , context .user_value , CBC_SCRIPT_REF_ONE );
22552271
@@ -2263,7 +2279,7 @@ parser_parse_source (void *source_p, /**< source code */
22632279#endif /* JERRY_BUILTIN_REALMS */
22642280
22652281#if JERRY_SOURCE_NAME
2266- context .script_p -> source_name = source_name ;
2282+ context .script_p -> source_name = parser_source_name ( & context ) ;
22672283#endif /* JERRY_SOURCE_NAME */
22682284
22692285 ECMA_SET_INTERNAL_VALUE_POINTER (context .script_value , context .script_p );
@@ -2437,7 +2453,7 @@ parser_parse_source (void *source_p, /**< source code */
24372453 if (context .script_p != NULL )
24382454 {
24392455 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 ) );
24412457 }
24422458 }
24432459 PARSER_TRY_END
@@ -2512,6 +2528,7 @@ parser_parse_source (void *source_p, /**< source code */
25122528 ecma_value_t err_str_val = ecma_make_string_value (err_str_p );
25132529 ecma_value_t line_str_val = ecma_make_uint32_value (context .token .line );
25142530 ecma_value_t col_str_val = ecma_make_uint32_value (context .token .column );
2531+ ecma_value_t source_name = parser_source_name (& context );
25152532
25162533 ecma_raise_standard_error_with_format (JERRY_ERROR_SYNTAX ,
25172534 "% [%:%:%]" ,
@@ -2520,6 +2537,7 @@ parser_parse_source (void *source_p, /**< source code */
25202537 line_str_val ,
25212538 col_str_val );
25222539
2540+ ecma_free_value (source_name );
25232541 ecma_free_value (col_str_val );
25242542 ecma_free_value (line_str_val );
25252543 ecma_deref_ecma_string (err_str_p );
0 commit comments