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