@@ -329,7 +329,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
329329 ecma_collection_t * lit_pool_p ) /**< list of known values */
330330{
331331 ecma_value_t * literal_p ;
332- uint32_t argument_end = 0 ;
332+ uint32_t argument_end ;
333333 uint32_t register_end ;
334334 uint32_t const_literal_end ;
335335 uint32_t literal_end ;
@@ -345,11 +345,7 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
345345 register_end = args_p -> register_end ;
346346 const_literal_end = args_p -> const_literal_end - register_end ;
347347 literal_end = args_p -> literal_end - register_end ;
348-
349- if (compiled_code_p -> status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED )
350- {
351- argument_end = args_p -> argument_end ;
352- }
348+ argument_end = args_p -> argument_end ;
353349 }
354350 else
355351 {
@@ -360,16 +356,15 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
360356 register_end = args_p -> register_end ;
361357 const_literal_end = args_p -> const_literal_end - register_end ;
362358 literal_end = args_p -> literal_end - register_end ;
363-
364- if (compiled_code_p -> status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED )
365- {
366- argument_end = args_p -> argument_end ;
367- }
359+ argument_end = args_p -> argument_end ;
368360 }
369361
370- for ( uint32_t i = 0 ; i < argument_end ; i ++ )
362+ if ( compiled_code_p -> status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED )
371363 {
372- ecma_save_literals_append_value (literal_p [i ], lit_pool_p );
364+ for (uint32_t i = 0 ; i < argument_end ; i ++ )
365+ {
366+ ecma_save_literals_append_value (literal_p [i ], lit_pool_p );
367+ }
373368 }
374369
375370 for (uint32_t i = 0 ; i < const_literal_end ; i ++ )
@@ -389,16 +384,13 @@ ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_
389384 }
390385 }
391386
392- if (argument_end != 0 )
393- {
394- uint8_t * byte_p = (uint8_t * ) compiled_code_p ;
395- byte_p += ((size_t ) compiled_code_p -> size ) << JMEM_ALIGNMENT_LOG ;
396- literal_p = ((ecma_value_t * ) byte_p ) - argument_end ;
387+ uint8_t * byte_p = ((uint8_t * ) compiled_code_p ) + (((size_t ) compiled_code_p -> size ) << JMEM_ALIGNMENT_LOG );
388+ literal_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t * ) compiled_code_p , byte_p );
397389
398- for ( uint32_t i = 0 ; i < argument_end ; i ++ )
399- {
400- ecma_save_literals_append_value (literal_p [ i ] , lit_pool_p );
401- }
390+ while ( literal_p < ( ecma_value_t * ) byte_p )
391+ {
392+ ecma_save_literals_append_value (* literal_p , lit_pool_p );
393+ literal_p ++ ;
402394 }
403395} /* ecma_save_literals_add_compiled_code */
404396
@@ -546,6 +538,51 @@ ecma_snapshot_get_literal (const uint8_t *literal_base_p, /**< literal start */
546538 return ecma_find_or_create_literal_string (literal_p + sizeof (uint16_t ), length );
547539} /* ecma_snapshot_get_literal */
548540
541+ /**
542+ * Compute the start of the serializable ecma-values of the bytecode
543+ * Related values:
544+ * - function argument names, if CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED is present
545+ * - function name, if CBC_CODE_FLAGS_CLASS_CONSTRUCTOR is not present and ES2015 profile is enabled
546+ * - resource name, if JERRY_RESOURCE_NAME is enabled
547+ *
548+ * @return pointer to the beginning of the serializable ecma-values
549+ */
550+ ecma_value_t *
551+ ecma_snapshot_resolve_serializable_values (ecma_compiled_code_t * compiled_code_p , /**< compiled code */
552+ uint8_t * bytecode_end_p ) /**< end of the bytecode */
553+ {
554+ ecma_value_t * base_p = (ecma_value_t * ) bytecode_end_p ;
555+
556+ if (compiled_code_p -> status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED )
557+ {
558+ uint32_t argument_end ;
559+ if (compiled_code_p -> status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS )
560+ {
561+ argument_end = ((cbc_uint16_arguments_t * ) compiled_code_p )-> argument_end ;
562+ }
563+ else
564+ {
565+ argument_end = ((cbc_uint8_arguments_t * ) compiled_code_p )-> argument_end ;
566+ }
567+
568+ base_p -= argument_end ;
569+ }
570+
571+ #if ENABLED (JERRY_ES2015 )
572+ /* function name */
573+ if (!(compiled_code_p -> status_flags & CBC_CODE_FLAGS_CLASS_CONSTRUCTOR ))
574+ {
575+ base_p -- ;
576+ }
577+ #endif /* ENABLED (JERRY_ES2015) */
578+
579+ #if ENABLED (JERRY_RESOURCE_NAME )
580+ /* resource name */
581+ base_p -- ;
582+ #endif /* ENABLED (JERRY_RESOURCE_NAME) */
583+
584+ return base_p ;
585+ } /* ecma_snapshot_resolve_serializable_values */
549586#endif /* ENABLED (JERRY_SNAPSHOT_EXEC) || ENABLED (JERRY_SNAPSHOT_SAVE) */
550587
551588/**
0 commit comments