Skip to content

Commit 2381078

Browse files
author
kisbg
authored
Add constant error messages (#4640)
added two new file ecma-errors.h and ecma-erros.c it contains the most used errors messages. JerryScript-DCO-1.0-Signed-off-by: bence gabor kis [email protected]
1 parent d85020f commit 2381078

26 files changed

+415
-229
lines changed

jerry-core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ set(SOURCE_CORE_FILES
132132
debugger/debugger.c
133133
ecma/base/ecma-alloc.c
134134
ecma/base/ecma-gc.c
135+
ecma/base/ecma-errors.c
135136
ecma/base/ecma-helpers-collection.c
136137
ecma/base/ecma-helpers-conversion.c
137138
ecma/base/ecma-helpers-errol.c
@@ -327,6 +328,7 @@ if(ENABLE_AMALGAM)
327328
api/jerry-snapshot.h
328329
debugger/debugger.h
329330
ecma/base/ecma-alloc.h
331+
ecma/base/ecma-errors.h
330332
ecma/base/ecma-gc.h
331333
ecma/base/ecma-globals.h
332334
ecma/base/ecma-helpers.h

jerry-core/api/jerry-snapshot.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include "ecma-conversion.h"
17+
#include "ecma-errors.h"
1718
#include "ecma-exceptions.h"
1819
#include "ecma-function-object.h"
1920
#include "ecma-helpers.h"
@@ -155,8 +156,8 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
155156

156157
if (globals_p->snapshot_buffer_write_offset > JERRY_SNAPSHOT_MAXIMUM_WRITE_OFFSET)
157158
{
158-
const char * const error_message_p = "Maximum snapshot size reached";
159-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
159+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
160+
(const jerry_char_t *) ecma_error_maximum_snapshot_size);
160161
return 0;
161162
}
162163

@@ -170,8 +171,8 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
170171
#if JERRY_ESNEXT
171172
if (compiled_code_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS)
172173
{
173-
const char * const error_message_p = "Unsupported feature: tagged template literals";
174-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
174+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
175+
(const jerry_char_t *) ecma_error_tagged_template_literals);
175176
return 0;
176177
}
177178

@@ -187,7 +188,8 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
187188
/* Regular expression. */
188189
if (globals_p->snapshot_buffer_write_offset + sizeof (ecma_compiled_code_t) > snapshot_buffer_size)
189190
{
190-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, error_buffer_too_small_p);
191+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
192+
(const jerry_char_t *) error_buffer_too_small_p);
191193
return 0;
192194
}
193195

@@ -208,7 +210,8 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
208210
buffer_p,
209211
buffer_size))
210212
{
211-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, error_buffer_too_small_p);
213+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
214+
(const jerry_char_t *) error_buffer_too_small_p);
212215
/* cannot return inside ECMA_FINALIZE_UTF8_STRING */
213216
}
214217

@@ -243,7 +246,7 @@ snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< compiled
243246
compiled_code_p,
244247
((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG))
245248
{
246-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, error_buffer_too_small_p);
249+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_buffer_too_small_p);
247250
return 0;
248251
}
249252

@@ -340,8 +343,8 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
340343

341344
if (globals_p->snapshot_buffer_write_offset >= JERRY_SNAPSHOT_MAXIMUM_WRITE_OFFSET)
342345
{
343-
const char * const error_message_p = "Maximum snapshot size reached";
344-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
346+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
347+
(const jerry_char_t *) ecma_error_maximum_snapshot_size);
345348
return 0;
346349
}
347350

@@ -355,8 +358,8 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
355358
if (!CBC_IS_FUNCTION (compiled_code_p->status_flags))
356359
{
357360
/* Regular expression literals are not supported. */
358-
const char * const error_message_p = "Regular expression literals are not supported";
359-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
361+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
362+
(const jerry_char_t *) ecma_error_regular_expression_not_supported);
360363
return 0;
361364
}
362365

@@ -366,8 +369,8 @@ static_snapshot_add_compiled_code (ecma_compiled_code_t *compiled_code_p, /**< c
366369
compiled_code_p,
367370
((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG))
368371
{
369-
const char * const error_message_p = "Snapshot buffer too small";
370-
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
372+
globals_p->snapshot_error = jerry_create_error (JERRY_ERROR_RANGE,
373+
(const jerry_char_t *) ecma_error_snapshot_buffer_small);
371374
return 0;
372375
}
373376

@@ -775,8 +778,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *source_p, /**< script sou
775778
if ((generate_snapshot_opts & ~allowed_options) != 0
776779
|| (options_p != NULL && (options_p->options & ~allowed_parse_options) != 0))
777780
{
778-
const char * const error_message_p = "Unsupported generate snapshot flags specified";
779-
return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) error_message_p);
781+
return jerry_create_error (JERRY_ERROR_RANGE, (const jerry_char_t *) ecma_error_snapshot_flag_not_supported);
780782
}
781783

782784
snapshot_globals_t globals;
@@ -847,9 +849,8 @@ jerry_generate_snapshot_with_args (const jerry_char_t *source_p, /**< script sou
847849
&literals_num))
848850
{
849851
JERRY_ASSERT (lit_map_p == NULL);
850-
const char * const error_message_p = "Cannot allocate memory for literals";
851852
ecma_bytecode_deref (bytecode_data_p);
852-
return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) error_message_p);
853+
return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) ecma_error_cannot_allocate_memory_literals);
853854
}
854855

855856
jerry_snapshot_set_offsets (buffer_p + (aligned_header_size / sizeof (uint32_t)),

0 commit comments

Comments
 (0)