Skip to content

Make exit behaviour of jerry_fatal flag-dependent #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jerry-core/jerry-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
12 changes: 12 additions & 0 deletions jerry-core/jerry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions jerry-core/jerry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion jerry-core/jrt/jrt-fatals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "jrt.h"
#include "jrt-libc-includes.h"

#define JERRY_INTERNAL
#include "jerry-internal.h"

/*
* Exit with specified status code.
*
Expand Down Expand Up @@ -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 ();
}
Expand Down
4 changes: 4 additions & 0 deletions main-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions main-nuttx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down