Skip to content
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
4 changes: 2 additions & 2 deletions docs/03.API-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ The following example function will output a JavaScript value:
#include <string.h>

#include "jerryscript.h"
#include "jerry-port.h"
#include "jerryscript-port.h"

static void
print_value (const jerry_value_t value)
Expand Down Expand Up @@ -247,7 +247,7 @@ Shell operation can be described with the following loop:
#include <string.h>

#include "jerryscript.h"
#include "jerry-port.h"
#include "jerryscript-port.h"

static void print_value (const jerry_value_t);

Expand Down
6 changes: 3 additions & 3 deletions docs/05.PORT-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ This section describes a basic port implementation which was created for Unix ba

```c
#include <stdlib.h>
#include "jerry-port.h"
#include "jerryscript-port.h"

/**
* Default implementation of jerry_port_fatal.
Expand All @@ -131,7 +131,7 @@ void jerry_port_fatal (jerry_fatal_code_t code)

```c
#include <stdarg.h>
#include "jerry-port.h"
#include "jerryscript-port.h"

/**
* Provide console message implementation for the engine.
Expand Down Expand Up @@ -168,7 +168,7 @@ jerry_port_log (jerry_log_level_t level, /**< log level */

```c
#include <sys/time.h>
#include "jerry-port.h"
#include "jerryscript-port.h"

/**
* Default implementation of jerry_port_get_time_zone.
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ foreach(EXT_LIB ${EXTERNAL_LINK_LIBS})
endforeach()

install(TARGETS ${JERRY_CORE_NAME} DESTINATION lib)
install(FILES jerry-api.h jerryscript.h jerry-port.h DESTINATION include)
install(FILES jerryscript.h jerryscript-port.h jerry-api.h jerry-port.h DESTINATION include)
2 changes: 1 addition & 1 deletion jerry-core/debugger/jerry-debugger-ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "jcontext.h"
#include "jerry-debugger.h"
#include "jerry-port.h"
#include "jerryscript-port.h"

/**
* Debugger socket communication port.
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/debugger/jerry-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "ecma-objects.h"
#include "jcontext.h"
#include "jerry-debugger.h"
#include "jerry-port.h"
#include "jerryscript-port.h"

/**
* Type cast the debugger send buffer into a specific type.
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/ecma/operations/ecma-jobqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "ecma-jobqueue.h"
#include "ecma-objects.h"
#include "ecma-promise-object.h"
#include "jerry-port.h"
#include "jerryscript-port.h"

#ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN

Expand Down
141 changes: 2 additions & 139 deletions jerry-core/jerry-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,145 +16,8 @@
#ifndef JERRY_PORT_H
#define JERRY_PORT_H

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#pragma message ("using jerry-port.h directly is deprecated, please use jerryscript-port.h")

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#include "jerryscript-port.h"

/** \addtogroup jerry_port Jerry engine port
* @{
*/

/*
* 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_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);

/*
* 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, ...) __attribute__ ((format (printf, 1, 2)));

/**
* 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, ...) __attribute__ ((format (printf, 2, 3)));

/*
* Date Port API
*/

/**
* Jerry time zone structure
*/
typedef struct
{
int offset; /**< minutes from west */
int daylight_saving_time; /**< daylight saving time (1 - DST applies, 0 - not on DST) */
} jerry_time_zone_t;

/**
* Get timezone and daylight saving data
*
* @return true - if success
* false - otherwise
*/
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p);

/**
* Get system time
*
* @return milliseconds since Unix epoch
*/
double jerry_port_get_current_time (void);

#ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN

#define JERRY_PORT_ENABLE_JOBQUEUE

typedef uint32_t (*jerry_job_handler_t) (void *);

void jerry_port_jobqueue_enqueue (jerry_job_handler_t handler, void *job_p);

#endif /* !CONFIG_DISABLE_ES2015_PROMISE_BUILTIN */

/**
* @}
*/

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !JERRY_PORT_H */
160 changes: 160 additions & 0 deletions jerry-core/jerryscript-port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef JERRYSCRIPT_PORT_H
#define JERRYSCRIPT_PORT_H

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

/** \addtogroup jerry_port Jerry engine port
* @{
*/

/*
* 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_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);

/*
* 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, ...) __attribute__ ((format (printf, 1, 2)));

/**
* 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, ...) __attribute__ ((format (printf, 2, 3)));

/*
* Date Port API
*/

/**
* Jerry time zone structure
*/
typedef struct
{
int offset; /**< minutes from west */
int daylight_saving_time; /**< daylight saving time (1 - DST applies, 0 - not on DST) */
} jerry_time_zone_t;

/**
* Get timezone and daylight saving data
*
* @return true - if success
* false - otherwise
*/
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p);

/**
* Get system time
*
* @return milliseconds since Unix epoch
*/
double jerry_port_get_current_time (void);

#ifndef CONFIG_DISABLE_ES2015_PROMISE_BUILTIN

#define JERRY_PORT_ENABLE_JOBQUEUE

typedef uint32_t (*jerry_job_handler_t) (void *);

void jerry_port_jobqueue_enqueue (jerry_job_handler_t handler, void *job_p);

#endif /* !CONFIG_DISABLE_ES2015_PROMISE_BUILTIN */

/**
* @}
*/

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !JERRYSCRIPT_PORT_H */
2 changes: 1 addition & 1 deletion jerry-core/jrt/jrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string.h>

#include "jerryscript.h"
#include "jerry-port.h"
#include "jerryscript-port.h"
#include "jrt-types.h"

/*
Expand Down
Loading