33
33
34
34
#if JERRY_SNAPSHOT_SAVE || JERRY_SNAPSHOT_EXEC
35
35
36
+ /**
37
+ * Create an error object
38
+ *
39
+ * Note:
40
+ * - returned value must be freed with jerry_release_value, when it is no longer needed
41
+ * - the error flag is set for the returned value
42
+ *
43
+ * @return value of the constructed error object
44
+ */
45
+ static jerry_value_t
46
+ jerry_create_error_from_id (jerry_error_t error_type , /**< type of error */
47
+ ecma_error_id_t error_id ) /**< ecma_error id of value of 'message' property
48
+ * of constructed error object */
49
+ {
50
+ return jerry_create_error (error_type , (jerry_char_t * ) ecma_get_error_utf8 (error_id ));
51
+ } /* jerry_create_error_from_id */
52
+
36
53
/**
37
54
* Get snapshot configuration flags.
38
55
*
@@ -153,8 +170,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co
153
170
154
171
if (globals_p -> snapshot_buffer_write_offset > JERRY_SNAPSHOT_MAXIMUM_WRITE_OFFSET )
155
172
{
156
- globals_p -> snapshot_error =
157
- jerry_create_error (JERRY_ERROR_RANGE , (const jerry_char_t * ) ecma_error_maximum_snapshot_size );
173
+ globals_p -> snapshot_error = jerry_create_error_from_id (JERRY_ERROR_RANGE , ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE );
158
174
return 0 ;
159
175
}
160
176
@@ -168,8 +184,7 @@ snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< co
168
184
#if JERRY_ESNEXT
169
185
if (compiled_code_p -> status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS )
170
186
{
171
- globals_p -> snapshot_error =
172
- jerry_create_error (JERRY_ERROR_RANGE , (const jerry_char_t * ) ecma_error_tagged_template_literals );
187
+ globals_p -> snapshot_error = jerry_create_error_from_id (JERRY_ERROR_RANGE , ECMA_ERR_TAGGED_TEMPLATE_LITERALS );
173
188
return 0 ;
174
189
}
175
190
@@ -339,8 +354,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
339
354
340
355
if (globals_p -> snapshot_buffer_write_offset >= JERRY_SNAPSHOT_MAXIMUM_WRITE_OFFSET )
341
356
{
342
- globals_p -> snapshot_error =
343
- jerry_create_error (JERRY_ERROR_RANGE , (const jerry_char_t * ) ecma_error_maximum_snapshot_size );
357
+ globals_p -> snapshot_error = jerry_create_error_from_id (JERRY_ERROR_RANGE , ECMA_ERR_MAXIMUM_SNAPSHOT_SIZE );
344
358
return 0 ;
345
359
}
346
360
@@ -355,7 +369,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
355
369
{
356
370
/* Regular expression literals are not supported. */
357
371
globals_p -> snapshot_error =
358
- jerry_create_error (JERRY_ERROR_RANGE , ( const jerry_char_t * ) ecma_error_regular_expression_not_supported );
372
+ jerry_create_error_from_id (JERRY_ERROR_RANGE , ECMA_ERR_REGULAR_EXPRESSION_NOT_SUPPORTED );
359
373
return 0 ;
360
374
}
361
375
@@ -365,8 +379,7 @@ static_snapshot_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,
365
379
compiled_code_p ,
366
380
((size_t ) compiled_code_p -> size ) << JMEM_ALIGNMENT_LOG ))
367
381
{
368
- globals_p -> snapshot_error =
369
- jerry_create_error (JERRY_ERROR_RANGE , (const jerry_char_t * ) ecma_error_snapshot_buffer_small );
382
+ globals_p -> snapshot_error = jerry_create_error_from_id (JERRY_ERROR_RANGE , ECMA_ERR_SNAPSHOT_BUFFER_SMALL );
370
383
return 0 ;
371
384
}
372
385
@@ -753,7 +766,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func
753
766
754
767
if ((generate_snapshot_opts & ~allowed_options ) != 0 )
755
768
{
756
- return jerry_create_error (JERRY_ERROR_RANGE , ( const jerry_char_t * ) ecma_error_snapshot_flag_not_supported );
769
+ return jerry_create_error_from_id (JERRY_ERROR_RANGE , ECMA_ERR_SNAPSHOT_FLAG_NOT_SUPPORTED );
757
770
}
758
771
759
772
const ecma_compiled_code_t * bytecode_data_p = NULL ;
@@ -785,7 +798,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func
785
798
786
799
if (JERRY_UNLIKELY (bytecode_data_p == NULL ))
787
800
{
788
- return jerry_create_error (JERRY_ERROR_RANGE , (const jerry_char_t * ) ECMA_ERR_MSG ( "Unsupported compiled code" ) );
801
+ return jerry_create_error (JERRY_ERROR_RANGE , (const jerry_char_t * ) "Unsupported compiled code" );
789
802
}
790
803
791
804
snapshot_globals_t globals ;
@@ -835,7 +848,7 @@ jerry_generate_snapshot (jerry_value_t compiled_code, /**< parsed script or func
835
848
& literals_num ))
836
849
{
837
850
JERRY_ASSERT (lit_map_p == NULL );
838
- return jerry_create_error (JERRY_ERROR_COMMON , ( const jerry_char_t * ) ecma_error_cannot_allocate_memory_literals );
851
+ return jerry_create_error_from_id (JERRY_ERROR_COMMON , ECMA_ERR_CANNOT_ALLOCATE_MEMORY_LITERALS );
839
852
}
840
853
841
854
jerry_snapshot_set_offsets (buffer_p + (aligned_header_size / sizeof (uint32_t )),
@@ -889,17 +902,15 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
889
902
890
903
if ((exec_snapshot_opts & ~(allowed_opts )) != 0 )
891
904
{
892
- ecma_raise_range_error (ECMA_ERR_MSG ( "Unsupported snapshot exec flags are specified" ) );
905
+ ecma_raise_range_error (ECMA_ERR_UNSUPPORTED_SNAPSHOT_EXEC_FLAGS_ARE_SPECIFIED );
893
906
return ecma_create_error_reference_from_context ();
894
907
}
895
908
896
- const char * const invalid_version_error_p = "Invalid snapshot version or unsupported features present" ;
897
- const char * const invalid_format_error_p = "Invalid snapshot format" ;
898
909
const uint8_t * snapshot_data_p = (uint8_t * ) snapshot_p ;
899
910
900
911
if (snapshot_size <= sizeof (jerry_snapshot_header_t ))
901
912
{
902
- ecma_raise_type_error (invalid_format_error_p );
913
+ ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_FORMAT );
903
914
return ecma_create_error_reference_from_context ();
904
915
}
905
916
@@ -908,19 +919,19 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
908
919
if (header_p -> magic != JERRY_SNAPSHOT_MAGIC || header_p -> version != JERRY_SNAPSHOT_VERSION
909
920
|| !snapshot_check_global_flags (header_p -> global_flags ))
910
921
{
911
- ecma_raise_type_error (invalid_version_error_p );
922
+ ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES );
912
923
return ecma_create_error_reference_from_context ();
913
924
}
914
925
915
926
if (header_p -> lit_table_offset > snapshot_size )
916
927
{
917
- ecma_raise_type_error (invalid_version_error_p );
928
+ ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_VERSION_OR_FEATURES );
918
929
return ecma_create_error_reference_from_context ();
919
930
}
920
931
921
932
if (func_index >= header_p -> number_of_funcs )
922
933
{
923
- ecma_raise_range_error (ECMA_ERR_MSG ( "Function index is higher than maximum" ) );
934
+ ecma_raise_range_error (ECMA_ERR_FUNCTION_INDEX_IS_HIGHER_THAN_MAXIMUM );
924
935
return ecma_create_error_reference_from_context ();
925
936
}
926
937
@@ -933,13 +944,13 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
933
944
{
934
945
if (!(exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_ALLOW_STATIC ))
935
946
{
936
- ecma_raise_common_error (ECMA_ERR_MSG ( "Static snapshots are not enabled" ) );
947
+ ecma_raise_common_error (ECMA_ERR_STATIC_SNAPSHOTS_ARE_NOT_ENABLED );
937
948
return ecma_create_error_reference_from_context ();
938
949
}
939
950
940
951
if (exec_snapshot_opts & JERRY_SNAPSHOT_EXEC_COPY_DATA )
941
952
{
942
- ecma_raise_common_error (ECMA_ERR_MSG ( "Static snapshots cannot be copied into memory" ) );
953
+ ecma_raise_common_error (ECMA_ERR_STATIC_SNAPSHOTS_CANNOT_BE_COPIED_INTO_MEMORY );
943
954
return ecma_create_error_reference_from_context ();
944
955
}
945
956
}
@@ -995,7 +1006,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p, /**< snapshot */
995
1006
{
996
1007
JERRY_ASSERT (script_p -> refs_and_type >= CBC_SCRIPT_REF_ONE );
997
1008
jmem_heap_free_block (script_p , script_size );
998
- return ecma_raise_type_error (invalid_format_error_p );
1009
+ return ecma_raise_type_error (ECMA_ERR_INVALID_SNAPSHOT_FORMAT );
999
1010
}
1000
1011
1001
1012
script_p -> refs_and_type -= CBC_SCRIPT_REF_ONE ;
0 commit comments