Introduce the Termination Port API
* Moved the error codes to jerry-port.h and declared port function `jerry_port_fatal`. * Moved "exit or abort on fail" functionality to the newly added jerry-port-default-fatal.c. * This implied that a default port-specific API had to be introduced: functions `jerry_port_default_set_abort_on_fail` and `jerry_port_default_is_abort_on_fail` declared in jerry-port-default.h control the fatal exit behaviour. * For the sake of clarity, renamed jerry-port.c to jerry-port-default-io.c. * Adapted CMakeLists to deal with port implementations consisting of more then one source file and exposing headers. This also required the renaming of `EXTERNAL_PORT_FILE` cmake option to `EXTERNAL_PORT_DIR`. * Adapted main sources to use the default port header for the abort-on-fail functionality, as that is not part of the core jerry API anymore. * Added default port implementation to the static source code checker tools. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -148,11 +148,7 @@ project (JerryCore C ASM)
|
||||
${SOURCE_CORE_JRT})
|
||||
|
||||
# Jerry port
|
||||
if(USE_DEFAULT_PORT)
|
||||
file(GLOB SOURCE_PORT_FILES ${CMAKE_SOURCE_DIR}/targets/default/*.c)
|
||||
else()
|
||||
set(SOURCE_PORT_FILES ${SOURCE_PORT_IMPLEMENTATION})
|
||||
endif()
|
||||
file(GLOB SOURCE_PORT_FILES ${PORT_DIR}/*.c)
|
||||
|
||||
# All-in-one build
|
||||
if("${ENABLE_ALL_IN_ONE}" STREQUAL "ON")
|
||||
|
||||
@@ -29,7 +29,4 @@ jerry_dispatch_external_function (ecma_object_t *, ecma_external_pointer_t, ecma
|
||||
extern void
|
||||
jerry_dispatch_object_free_callback (ecma_external_pointer_t, ecma_external_pointer_t);
|
||||
|
||||
extern bool
|
||||
jerry_is_abort_on_fail (void);
|
||||
|
||||
#endif /* !JERRY_INTERNAL_H */
|
||||
|
||||
@@ -35,6 +35,42 @@ int jerry_port_logmsg (FILE *stream, const char *format, ...);
|
||||
int jerry_port_errormsg (const char *format, ...);
|
||||
int jerry_port_putchar (int c);
|
||||
|
||||
/*
|
||||
* Termination Port API
|
||||
*
|
||||
* Note:
|
||||
* It is questionable whether a library should be able to terminate an
|
||||
* application. However, as of now, we only have the concept of completion
|
||||
* code around jerry_parse and jerry_run. Most of the other API functions
|
||||
* have no way of signaling an error. So, we keep the termination approach
|
||||
* with this port function.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Error codes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ERR_OUT_OF_MEMORY = 10,
|
||||
ERR_SYSCALL = 11,
|
||||
ERR_REF_COUNT_LIMIT = 12,
|
||||
ERR_UNIMPLEMENTED_CASE = 118,
|
||||
ERR_FAILED_INTERNAL_ASSERTION = 120
|
||||
} jerry_fatal_code_t;
|
||||
|
||||
/**
|
||||
* Signal the port that jerry experienced a fatal failure from which it cannot
|
||||
* recover.
|
||||
*
|
||||
* @param code gives the cause of the error.
|
||||
*
|
||||
* Note:
|
||||
* Jerry expects the function not to return.
|
||||
*
|
||||
* Example: a libc-based port may implement this with exit() or abort(), or both.
|
||||
*/
|
||||
void jerry_port_fatal (jerry_fatal_code_t code);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1689,18 +1689,6 @@ jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p, /**< [out] Jerry's ma
|
||||
*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 */
|
||||
|
||||
/**
|
||||
* Parse script for specified context
|
||||
*
|
||||
|
||||
@@ -44,21 +44,8 @@ typedef enum
|
||||
JERRY_FLAG_PARSE_ONLY = (1u << 3), /**< parse only, prevents script execution (only for testing)
|
||||
* TODO: Remove. */
|
||||
JERRY_FLAG_ENABLE_LOG = (1u << 4), /**< enable logging */
|
||||
JERRY_FLAG_ABORT_ON_FAIL = (1u << 5), /**< abort instead of exit in case of failure */
|
||||
} jerry_flag_t;
|
||||
|
||||
/**
|
||||
* Error codes
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ERR_OUT_OF_MEMORY = 10,
|
||||
ERR_SYSCALL = 11,
|
||||
ERR_REF_COUNT_LIMIT = 12,
|
||||
ERR_UNIMPLEMENTED_CASE = 118,
|
||||
ERR_FAILED_INTERNAL_ASSERTION = 120
|
||||
} jerry_fatal_code_t;
|
||||
|
||||
/**
|
||||
* Jerry engine build date
|
||||
*/
|
||||
|
||||
@@ -65,16 +65,7 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
|
||||
}
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
if (code != 0
|
||||
&& code != ERR_OUT_OF_MEMORY
|
||||
&& jerry_is_abort_on_fail ())
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
else
|
||||
{
|
||||
exit (code);
|
||||
}
|
||||
jerry_port_fatal (code);
|
||||
|
||||
/* to make compiler happy for some RTOS: 'control reaches end of non-void function' */
|
||||
while (true)
|
||||
|
||||
Reference in New Issue
Block a user