Implement IO port API
Related issue: #964 Implemented the IO API of Jerry ports. Removed log file from API level. The port implementation should define the destination of log messages. JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
@@ -162,7 +162,6 @@ typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_na
|
||||
*/
|
||||
#ifdef JERRY_ENABLE_LOG
|
||||
extern int jerry_debug_level;
|
||||
extern FILE *jerry_log_file;
|
||||
#endif /* JERRY_ENABLE_LOG */
|
||||
|
||||
/**
|
||||
|
||||
+48
-6
@@ -29,12 +29,6 @@ extern "C"
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Target port functions for console output
|
||||
*/
|
||||
int jerry_port_logmsg (FILE *stream, const char *format, ...);
|
||||
int jerry_port_errormsg (const char *format, ...);
|
||||
|
||||
/*
|
||||
* Termination Port API
|
||||
*
|
||||
@@ -71,6 +65,54 @@ typedef enum
|
||||
*/
|
||||
void jerry_port_fatal (jerry_fatal_code_t code);
|
||||
|
||||
/*
|
||||
* I/O Port API
|
||||
*/
|
||||
|
||||
/**
|
||||
* Print a string to the console. The function should implement a printf-like
|
||||
* interface, where the first argument specifies a format string on how to
|
||||
* stringify the rest of the parameter list.
|
||||
*
|
||||
* This function is only called with strings coming from the executed ECMAScript
|
||||
* wanting to print something as the result of its normal operation.
|
||||
*
|
||||
* It should be the port that decides what a "console" is.
|
||||
*
|
||||
* Example: a libc-based port may implement this with vprintf().
|
||||
*/
|
||||
void jerry_port_console (const char *format, ...);
|
||||
|
||||
/**
|
||||
* Jerry log levels. The levels are in severity order
|
||||
* where the most serious levels come first.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRY_LOG_LEVEL_ERROR, /**< the engine will terminate after the message is printed */
|
||||
JERRY_LOG_LEVEL_WARNING, /**< a request is aborted, but the engine continues its operation */
|
||||
JERRY_LOG_LEVEL_DEBUG, /**< debug messages from the engine, low volume */
|
||||
JERRY_LOG_LEVEL_TRACE /**< detailed info about engine internals, potentially high volume */
|
||||
} jerry_log_level_t;
|
||||
|
||||
/**
|
||||
* Display or log a debug/error message. The function should implement a printf-like
|
||||
* interface, where the first argument specifies the log level
|
||||
* and the second argument specifies a format string on how to stringify the rest
|
||||
* of the parameter list.
|
||||
*
|
||||
* This function is only called with messages coming from the jerry engine as
|
||||
* the result of some abnormal operation or describing its internal operations
|
||||
* (e.g., data structure dumps or tracing info).
|
||||
*
|
||||
* It should be the port that decides whether error and debug messages are logged to
|
||||
* the console, or saved to a database or to a file.
|
||||
*
|
||||
* Example: a libc-based port may implement this with vfprintf(stderr) or
|
||||
* vfprintf(logfile), or both, depending on log level.
|
||||
*/
|
||||
void jerry_port_log (jerry_log_level_t level, const char *format, ...);
|
||||
|
||||
/*
|
||||
* Date Port API
|
||||
*/
|
||||
|
||||
@@ -86,11 +86,6 @@ static const char *wrong_args_msg_p = "wrong type of argument";
|
||||
*/
|
||||
int jerry_debug_level = 0;
|
||||
|
||||
/**
|
||||
* File, used for logging
|
||||
*/
|
||||
FILE *jerry_log_file = NULL;
|
||||
|
||||
#endif /* JERRY_ENABLE_LOG */
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,9 +86,9 @@ extern void __noreturn jerry_unimplemented (const char *, const char *, const ch
|
||||
#define JERRY_LOG(lvl, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (lvl <= jerry_debug_level && jerry_log_file) \
|
||||
if (lvl <= jerry_debug_level) \
|
||||
{ \
|
||||
jerry_port_logmsg (jerry_log_file, __VA_ARGS__); \
|
||||
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, __VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
@@ -109,8 +109,8 @@ extern void __noreturn jerry_unimplemented (const char *, const char *, const ch
|
||||
#define JERRY_DDDLOG(...) JERRY_DLOG (__VA_ARGS__)
|
||||
#endif /* JERRY_ENABLE_LOG */
|
||||
|
||||
#define JERRY_ERROR_MSG(...) jerry_port_errormsg (__VA_ARGS__)
|
||||
#define JERRY_WARNING_MSG(...) JERRY_ERROR_MSG (__VA_ARGS__)
|
||||
#define JERRY_ERROR_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_ERROR, __VA_ARGS__)
|
||||
#define JERRY_WARNING_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_WARNING, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Mark for unreachable points and unimplemented cases
|
||||
|
||||
Reference in New Issue
Block a user