fdbbd0e8af
This commit changes the concept of JerryScript port implementations
from a simple directory of C source files (which get injected among
the sources of `jerry-core`) into a proper static library (which
may be linked to an application together with `jerry-core`). As a
consequence, this commit introduces a new library to the
JerryScript component architecture: the sources of the default port
implementation form `jerry-port-default`.
Changes in more detail:
- The sources in `targets/default` are moved to `jerry-port/default`
and are turned into a proper static library.
- Actually, the default port implementation has two library
variants, one that implements the bare minimum only
(`jerry-port-default-minimal`) and one that has some extra
functionalities specific to this implementation (the "full"
`jerry-port-default`).
- The new libraries have an interface header in
`jerry-port/default/include`, which extends the common
`jerryscript-port.h` API with functions specific to these
libraries.
- All non-standard port functions have now the
`jerry_port_default_` prefix (this affects `jobqueue_init` and
`jobqueue_run`).
- The jobqueue implementation functions became config macro
independent: it is now the responsibility of the linker to pick
the needed objects from the library, and omit those (e.g.,
jobqueue-related code) that are not referenced.
- Build of the libraries can be controlled with the new
`JERRY_PORT_DEFAULT` cmake option.
- The cmake option `PORT_DIR` is dropped, and `PORT_DIR/*.c` is not
appended to `jerry-core` sources.
- Instead, the `jerry` tool of `jerry-main` links to
`jerry-port-default`, while `jerry-minimal` links to
`jerry-port-default-minimal`.
- `tests/unit-core` tests are also linked to
`jerry-port-default-minimal`.
- Tools adapted.
- `build.py` has `--jerry-port-default` instead of `--port-dir`.
- `check-*.sh` have paths updated (`jerry-port/default` instead
of `targets/default`).
- Miscellaneous.
- Dropped `#ifndef`s from `jerryscript-port.h`. It is a public
header of the `jerry-core` library, which means that it must
not contain configuration-dependent parts (once the library is
built with some config macros and the archive and the headers
are installed, there is no way for the header to tell what
those config macrose were).
- Added documentation comments to the JobQueue Port API (in
`jerryscript-port.h`) and to several default port
implementation functions (in `jerry-port/default`).
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
176 lines
5.1 KiB
C
176 lines
5.1 KiB
C
/* 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);
|
|
|
|
/*
|
|
* JobQueue Port API
|
|
*/
|
|
|
|
/**
|
|
* Jerry job handler function type
|
|
*/
|
|
typedef uint32_t (*jerry_job_handler_t) (void *);
|
|
|
|
/**
|
|
* Enqueue a job described by a pair of function and data pointers. The port is
|
|
* expected to call the handler function with the given data at some (later)
|
|
* point of time.
|
|
*
|
|
* @param handler the pointer of the handler function associated with the job.
|
|
* @param job_p the data pointer to be passed to handler when called.
|
|
*
|
|
* Note:
|
|
* This port function is only called by the implementation of the Promise
|
|
* builtin (mandated by the ES2015 standard). If the engine is built with
|
|
* Promise disabled (e.g., with ES5.1 profile), then the port does not have
|
|
* to implement this function.
|
|
*/
|
|
void jerry_port_jobqueue_enqueue (jerry_job_handler_t handler, void *job_p);
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
#endif /* !JERRYSCRIPT_PORT_H */
|