From 9d423d9901c8dac8db3fbf6d1b23c261674fdebe Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Tue, 2 Jun 2015 23:07:10 +0200 Subject: [PATCH] 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 akiss@inf.u-szeged.hu --- jerry-core/jerry-internal.h | 3 +++ jerry-core/jerry.cpp | 12 ++++++++++++ jerry-core/jerry.h | 1 + jerry-core/jrt/jrt-fatals.cpp | 5 ++++- main-linux.cpp | 4 ++++ main-nuttx.cpp | 4 ++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/jerry-core/jerry-internal.h b/jerry-core/jerry-internal.h index 348e3b4c25..18146bc208 100644 --- a/jerry-core/jerry-internal.h +++ b/jerry-core/jerry-internal.h @@ -34,4 +34,7 @@ extern void jerry_dispatch_object_free_callback (ecma_external_pointer_t freecb_p, ecma_external_pointer_t native_p); +extern bool +jerry_is_abort_on_fail (void); + #endif /* !JERRY_INTERNAL_H */ diff --git a/jerry-core/jerry.cpp b/jerry-core/jerry.cpp index 326e62cfdb..411fac2aa8 100644 --- a/jerry-core/jerry.cpp +++ b/jerry-core/jerry.cpp @@ -1185,6 +1185,18 @@ jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p, /**< out: Jerry's max *out_stack_limit_p = CONFIG_MEM_STACK_LIMIT; } /* jerry_get_memory_limits */ +/** + * Check whether 'abort' should be called instead of 'exit' upon exiting with non-zero exit code. + * + * @return true - if 'abort on fail' flag is set, + * false - otherwise. + */ +bool +jerry_is_abort_on_fail (void) +{ + return ((jerry_flags & JERRY_FLAG_ABORT_ON_FAIL) != 0); +} /* jerry_is_abort_on_fail */ + /** * Register Jerry's fatal error callback */ diff --git a/jerry-core/jerry.h b/jerry-core/jerry.h index dbc9815aec..a2252a9c2f 100644 --- a/jerry-core/jerry.h +++ b/jerry-core/jerry.h @@ -40,6 +40,7 @@ typedef uint32_t jerry_flag_t; #define JERRY_FLAG_PARSE_ONLY (1u << 4) /**< parse only, prevents script execution (only for testing) * FIXME: Remove. */ #define JERRY_FLAG_ENABLE_LOG (1u << 5) /**< enable logging */ +#define JERRY_FLAG_ABORT_ON_FAIL (1u << 6) /**< abort instead of exit in case of failure */ /** * Error codes diff --git a/jerry-core/jrt/jrt-fatals.cpp b/jerry-core/jrt/jrt-fatals.cpp index d587f92f07..3ada6946b2 100644 --- a/jerry-core/jrt/jrt-fatals.cpp +++ b/jerry-core/jrt/jrt-fatals.cpp @@ -20,6 +20,9 @@ #include "jrt.h" #include "jrt-libc-includes.h" +#define JERRY_INTERNAL +#include "jerry-internal.h" + /* * Exit with specified status code. * @@ -62,7 +65,7 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */ } #endif /* !JERRY_NDEBUG */ - if (code == ERR_FAILED_INTERNAL_ASSERTION) + if (code != 0 && jerry_is_abort_on_fail ()) { abort (); } diff --git a/main-linux.cpp b/main-linux.cpp index 56648ad8b7..a7ac8bcd91 100644 --- a/main-linux.cpp +++ b/main-linux.cpp @@ -193,6 +193,10 @@ main (int argc, return JERRY_STANDALONE_EXIT_CODE_FAIL; } } + else if (!strcmp ("--abort-on-fail", argv[i])) + { + flags |= JERRY_FLAG_ABORT_ON_FAIL; + } else { file_names[files_counter++] = argv[i]; diff --git a/main-nuttx.cpp b/main-nuttx.cpp index bfc0661b1f..37aeb5a868 100644 --- a/main-nuttx.cpp +++ b/main-nuttx.cpp @@ -166,6 +166,10 @@ int jerry_main (int argc, char *argv[]) { flags |= JERRY_FLAG_SHOW_OPCODES; } + else if (!strcmp ("--abort-on-fail", argv[i])) + { + flags |= JERRY_FLAG_ABORT_ON_FAIL; + } else { file_names[files_counter++] = argv[i];