Skip to content

Commit 9d423d9

Browse files
committed
Make exit behaviour of jerry_fatal flag-dependent
* Added new flag `JERRY_FLAG_ABORT_ON_FAIL`. * Added new internal api function `jerry_is_abort_on_fail` to check the status of the flag. * Changed `jerry_fatal` bail-out function to call `abort` when the flag is set and exit code is non-zero (i.e., not only for assertion failures). * Added `--abort-on-fail` command line option to linux and nuttx apps to set the flag. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 4c10a6d commit 9d423d9

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

jerry-core/jerry-internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ extern void
3434
jerry_dispatch_object_free_callback (ecma_external_pointer_t freecb_p,
3535
ecma_external_pointer_t native_p);
3636

37+
extern bool
38+
jerry_is_abort_on_fail (void);
39+
3740
#endif /* !JERRY_INTERNAL_H */

jerry-core/jerry.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,18 @@ jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p, /**< out: Jerry's max
11851185
*out_stack_limit_p = CONFIG_MEM_STACK_LIMIT;
11861186
} /* jerry_get_memory_limits */
11871187

1188+
/**
1189+
* Check whether 'abort' should be called instead of 'exit' upon exiting with non-zero exit code.
1190+
*
1191+
* @return true - if 'abort on fail' flag is set,
1192+
* false - otherwise.
1193+
*/
1194+
bool
1195+
jerry_is_abort_on_fail (void)
1196+
{
1197+
return ((jerry_flags & JERRY_FLAG_ABORT_ON_FAIL) != 0);
1198+
} /* jerry_is_abort_on_fail */
1199+
11881200
/**
11891201
* Register Jerry's fatal error callback
11901202
*/

jerry-core/jerry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef uint32_t jerry_flag_t;
4040
#define JERRY_FLAG_PARSE_ONLY (1u << 4) /**< parse only, prevents script execution (only for testing)
4141
* FIXME: Remove. */
4242
#define JERRY_FLAG_ENABLE_LOG (1u << 5) /**< enable logging */
43+
#define JERRY_FLAG_ABORT_ON_FAIL (1u << 6) /**< abort instead of exit in case of failure */
4344

4445
/**
4546
* Error codes

jerry-core/jrt/jrt-fatals.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "jrt.h"
2121
#include "jrt-libc-includes.h"
2222

23+
#define JERRY_INTERNAL
24+
#include "jerry-internal.h"
25+
2326
/*
2427
* Exit with specified status code.
2528
*
@@ -62,7 +65,7 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
6265
}
6366
#endif /* !JERRY_NDEBUG */
6467

65-
if (code == ERR_FAILED_INTERNAL_ASSERTION)
68+
if (code != 0 && jerry_is_abort_on_fail ())
6669
{
6770
abort ();
6871
}

main-linux.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ main (int argc,
193193
return JERRY_STANDALONE_EXIT_CODE_FAIL;
194194
}
195195
}
196+
else if (!strcmp ("--abort-on-fail", argv[i]))
197+
{
198+
flags |= JERRY_FLAG_ABORT_ON_FAIL;
199+
}
196200
else
197201
{
198202
file_names[files_counter++] = argv[i];

main-nuttx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ int jerry_main (int argc, char *argv[])
166166
{
167167
flags |= JERRY_FLAG_SHOW_OPCODES;
168168
}
169+
else if (!strcmp ("--abort-on-fail", argv[i]))
170+
{
171+
flags |= JERRY_FLAG_ABORT_ON_FAIL;
172+
}
169173
else
170174
{
171175
file_names[files_counter++] = argv[i];

0 commit comments

Comments
 (0)