Replace vera++ with clang-format (#4518)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
@@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "arg-internal.h"
|
||||
#include "jerryscript-ext/arg.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
/**
|
||||
* Pop the current JS argument from the iterator.
|
||||
@@ -62,8 +63,7 @@ jerryx_arg_js_iterator_restore (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< th
|
||||
jerry_value_t
|
||||
jerryx_arg_js_iterator_peek (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */
|
||||
{
|
||||
return (js_arg_iter_p->js_arg_idx < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p
|
||||
: jerry_create_undefined ());
|
||||
return (js_arg_iter_p->js_arg_idx < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p : jerry_create_undefined ());
|
||||
} /* jerryx_arg_js_iterator_peek */
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "jerryscript-ext/arg.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "jerryscript-ext/arg.h"
|
||||
|
||||
/**
|
||||
* The common function to deal with optional arguments.
|
||||
* The core transform function is provided by argument `func`.
|
||||
@@ -55,8 +56,7 @@ jerryx_arg_transform_number_strict_common (jerryx_arg_js_iterator_t *js_arg_iter
|
||||
|
||||
if (!jerry_value_is_number (js_arg))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It is not a number.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a number.");
|
||||
}
|
||||
|
||||
*number_p = jerry_get_number_value (js_arg);
|
||||
@@ -83,8 +83,7 @@ jerryx_arg_transform_number_common (jerryx_arg_js_iterator_t *js_arg_iter_p, /**
|
||||
{
|
||||
jerry_release_value (to_number);
|
||||
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It can not be converted to a number.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It can not be converted to a number.");
|
||||
}
|
||||
|
||||
*number_p = jerry_get_number_value (to_number);
|
||||
@@ -134,16 +133,14 @@ jerryx_arg_helper_process_double (double *d, /**< [in, out] the number to be pro
|
||||
{
|
||||
if (*d != *d) /* isnan (*d) triggers conversion warning on clang<9 */
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "The number is NaN.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "The number is NaN.");
|
||||
}
|
||||
|
||||
if (option.clamp == JERRYX_ARG_NO_CLAMP)
|
||||
{
|
||||
if (*d > max || *d < min)
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "The number is out of range.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "The number is out of range.");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -171,32 +168,32 @@ jerryx_arg_helper_process_double (double *d, /**< [in, out] the number to be pro
|
||||
/**
|
||||
* Use the macro to define thr transform functions for int type.
|
||||
*/
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_FOR_INT_TEMPLATE(type, suffix, min, max) \
|
||||
jerry_value_t jerryx_arg_transform_ ## type ## suffix (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p) \
|
||||
{ \
|
||||
double tmp = 0.0; \
|
||||
jerry_value_t rv = jerryx_arg_transform_number ## suffix ## _common (js_arg_iter_p, &tmp); \
|
||||
if (jerry_value_is_error (rv)) \
|
||||
{ \
|
||||
return rv; \
|
||||
} \
|
||||
jerry_release_value (rv); \
|
||||
union \
|
||||
{ \
|
||||
jerryx_arg_int_option_t int_option; \
|
||||
uintptr_t extra_info; \
|
||||
} u = { .extra_info = c_arg_p->extra_info }; \
|
||||
rv = jerryx_arg_helper_process_double (&tmp, min, max, u.int_option); \
|
||||
if (jerry_value_is_error (rv)) \
|
||||
{ \
|
||||
return rv; \
|
||||
} \
|
||||
*(type ## _t *) c_arg_p->dest = (type ## _t) tmp; \
|
||||
return rv; \
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_FOR_INT_TEMPLATE(type, suffix, min, max) \
|
||||
jerry_value_t jerryx_arg_transform_##type##suffix (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p) \
|
||||
{ \
|
||||
double tmp = 0.0; \
|
||||
jerry_value_t rv = jerryx_arg_transform_number##suffix##_common (js_arg_iter_p, &tmp); \
|
||||
if (jerry_value_is_error (rv)) \
|
||||
{ \
|
||||
return rv; \
|
||||
} \
|
||||
jerry_release_value (rv); \
|
||||
union \
|
||||
{ \
|
||||
jerryx_arg_int_option_t int_option; \
|
||||
uintptr_t extra_info; \
|
||||
} u = { .extra_info = c_arg_p->extra_info }; \
|
||||
rv = jerryx_arg_helper_process_double (&tmp, min, max, u.int_option); \
|
||||
if (jerry_value_is_error (rv)) \
|
||||
{ \
|
||||
return rv; \
|
||||
} \
|
||||
*(type##_t *) c_arg_p->dest = (type##_t) tmp; \
|
||||
return rv; \
|
||||
}
|
||||
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_FOR_INT(type, min, max) \
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_FOR_INT(type, min, max) \
|
||||
JERRYX_ARG_TRANSFORM_FUNC_FOR_INT_TEMPLATE (type, _strict, min, max) \
|
||||
JERRYX_ARG_TRANSFORM_FUNC_FOR_INT_TEMPLATE (type, , min, max)
|
||||
|
||||
@@ -223,8 +220,7 @@ jerryx_arg_transform_boolean_strict (jerryx_arg_js_iterator_t *js_arg_iter_p, /*
|
||||
|
||||
if (!jerry_value_is_boolean (js_arg))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It is not a boolean.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a boolean.");
|
||||
}
|
||||
|
||||
bool *dest = c_arg_p->dest;
|
||||
@@ -272,23 +268,18 @@ jerryx_arg_string_to_buffer_common_routine (jerry_value_t js_arg, /**< JS arg */
|
||||
|
||||
if (!is_utf8)
|
||||
{
|
||||
size = jerry_string_to_char_buffer (js_arg,
|
||||
target_p,
|
||||
target_buf_size);
|
||||
size = jerry_string_to_char_buffer (js_arg, target_p, target_buf_size);
|
||||
len = jerry_get_string_length (js_arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
size = jerry_string_to_utf8_char_buffer (js_arg,
|
||||
target_p,
|
||||
target_buf_size);
|
||||
size = jerry_string_to_utf8_char_buffer (js_arg, target_p, target_buf_size);
|
||||
len = jerry_get_utf8_string_length (js_arg);
|
||||
}
|
||||
|
||||
if ((size == target_buf_size) || (size == 0 && len != 0))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "Buffer size is not large enough.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "Buffer size is not large enough.");
|
||||
}
|
||||
|
||||
target_p[size] = '\0';
|
||||
@@ -311,8 +302,7 @@ jerryx_arg_transform_string_strict_common (jerryx_arg_js_iterator_t *js_arg_iter
|
||||
|
||||
if (!jerry_value_is_string (js_arg))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It is not a string.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a string.");
|
||||
}
|
||||
|
||||
return jerryx_arg_string_to_buffer_common_routine (js_arg, c_arg_p, is_utf8);
|
||||
@@ -337,8 +327,7 @@ jerryx_arg_transform_string_common (jerryx_arg_js_iterator_t *js_arg_iter_p, /**
|
||||
{
|
||||
jerry_release_value (to_string);
|
||||
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It can not be converted to a string.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It can not be converted to a string.");
|
||||
}
|
||||
|
||||
jerry_value_t ret = jerryx_arg_string_to_buffer_common_routine (to_string, c_arg_p, is_utf8);
|
||||
@@ -425,8 +414,7 @@ jerryx_arg_transform_function (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< ava
|
||||
|
||||
if (!jerry_value_is_function (js_arg))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It is not a function.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not a function.");
|
||||
}
|
||||
|
||||
jerry_value_t *func_p = c_arg_p->dest;
|
||||
@@ -450,8 +438,7 @@ jerryx_arg_transform_native_pointer (jerryx_arg_js_iterator_t *js_arg_iter_p, /*
|
||||
|
||||
if (!jerry_value_is_object (js_arg))
|
||||
{
|
||||
return jerry_create_error (JERRY_ERROR_TYPE,
|
||||
(jerry_char_t *) "It is not an object.");
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "It is not an object.");
|
||||
}
|
||||
|
||||
const jerry_object_native_info_t *expected_info_p;
|
||||
@@ -503,20 +490,17 @@ jerryx_arg_transform_array_items (jerryx_arg_js_iterator_t *js_arg_iter_p, /**<
|
||||
|
||||
const jerryx_arg_array_items_t *array_items_p = (const jerryx_arg_array_items_t *) c_arg_p->extra_info;
|
||||
|
||||
return jerryx_arg_transform_array (js_arg,
|
||||
array_items_p->c_arg_p,
|
||||
array_items_p->c_arg_cnt);
|
||||
return jerryx_arg_transform_array (js_arg, array_items_p->c_arg_p, array_items_p->c_arg_cnt);
|
||||
} /* jerryx_arg_transform_array_items */
|
||||
|
||||
/**
|
||||
* Define transformer for optional argument.
|
||||
*/
|
||||
#define JERRYX_ARG_TRANSFORM_OPTIONAL(type) \
|
||||
jerry_value_t \
|
||||
jerryx_arg_transform_ ## type ## _optional (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p) \
|
||||
{ \
|
||||
return jerryx_arg_transform_optional (js_arg_iter_p, c_arg_p, jerryx_arg_transform_ ## type); \
|
||||
#define JERRYX_ARG_TRANSFORM_OPTIONAL(type) \
|
||||
jerry_value_t jerryx_arg_transform_##type##_optional (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p) \
|
||||
{ \
|
||||
return jerryx_arg_transform_optional (js_arg_iter_p, c_arg_p, jerryx_arg_transform_##type); \
|
||||
}
|
||||
|
||||
JERRYX_ARG_TRANSFORM_OPTIONAL (number)
|
||||
|
||||
+5
-13
@@ -14,7 +14,9 @@
|
||||
*/
|
||||
|
||||
#include "jerryscript-ext/arg.h"
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "arg-internal.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
@@ -35,12 +37,7 @@ jerryx_arg_transform_args (const jerry_value_t *js_arg_p, /**< points to the arr
|
||||
{
|
||||
jerry_value_t ret = jerry_create_undefined ();
|
||||
|
||||
jerryx_arg_js_iterator_t iterator =
|
||||
{
|
||||
.js_arg_p = js_arg_p,
|
||||
.js_arg_cnt = js_arg_cnt,
|
||||
.js_arg_idx = 0
|
||||
};
|
||||
jerryx_arg_js_iterator_t iterator = { .js_arg_p = js_arg_p, .js_arg_cnt = js_arg_cnt, .js_arg_idx = 0 };
|
||||
|
||||
for (; c_arg_cnt != 0 && !jerry_value_is_error (ret); c_arg_cnt--, c_arg_p++)
|
||||
{
|
||||
@@ -72,12 +69,7 @@ jerryx_arg_transform_this_and_args (const jerry_value_t this_val, /**< the this_
|
||||
return jerry_create_undefined ();
|
||||
}
|
||||
|
||||
jerryx_arg_js_iterator_t iterator =
|
||||
{
|
||||
.js_arg_p = &this_val,
|
||||
.js_arg_cnt = 1,
|
||||
.js_arg_idx = 0
|
||||
};
|
||||
jerryx_arg_js_iterator_t iterator = { .js_arg_p = &this_val, .js_arg_cnt = 1, .js_arg_idx = 0 };
|
||||
|
||||
jerry_value_t ret = c_arg_p->func (&iterator, c_arg_p);
|
||||
|
||||
@@ -99,7 +91,7 @@ jerryx_arg_transform_this_and_args (const jerry_value_t this_val, /**< the this_
|
||||
* jerry error: a validator failed.
|
||||
*/
|
||||
jerry_value_t
|
||||
jerryx_arg_transform_object_properties (const jerry_value_t obj_val,/**< the JS object */
|
||||
jerryx_arg_transform_object_properties (const jerry_value_t obj_val, /**< the JS object */
|
||||
const jerry_char_t **name_p, /**< property name list of the JS object */
|
||||
const jerry_length_t name_cnt, /**< count of the name list */
|
||||
const jerryx_arg_t *c_arg_p, /**< points to the array of transformation steps */
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
/*
|
||||
* Make sure unused parameters, variables, or expressions trigger no compiler warning.
|
||||
@@ -35,39 +35,43 @@
|
||||
* __LINE__ may be the same for asserts in a header
|
||||
* and in an implementation file.
|
||||
*/
|
||||
#define JERRYX_STATIC_ASSERT_GLUE_(a, b, c) a ## b ## _ ## c
|
||||
#define JERRYX_STATIC_ASSERT_GLUE(a, b, c) JERRYX_STATIC_ASSERT_GLUE_ (a, b, c)
|
||||
#define JERRYX_STATIC_ASSERT(x, msg) \
|
||||
enum { JERRYX_STATIC_ASSERT_GLUE (static_assertion_failed_, __LINE__, msg) = 1 / (!!(x)) }
|
||||
#define JERRYX_STATIC_ASSERT_GLUE_(a, b, c) a##b##_##c
|
||||
#define JERRYX_STATIC_ASSERT_GLUE(a, b, c) JERRYX_STATIC_ASSERT_GLUE_ (a, b, c)
|
||||
#define JERRYX_STATIC_ASSERT(x, msg) \
|
||||
enum \
|
||||
{ \
|
||||
JERRYX_STATIC_ASSERT_GLUE (static_assertion_failed_, __LINE__, msg) = 1 / (!!(x)) \
|
||||
}
|
||||
|
||||
#ifndef JERRY_NDEBUG
|
||||
void JERRY_ATTR_NORETURN
|
||||
jerry_assert_fail (const char *assertion, const char *file, const char *function, const uint32_t line);
|
||||
void JERRY_ATTR_NORETURN
|
||||
jerry_unreachable (const char *file, const char *function, const uint32_t line);
|
||||
void JERRY_ATTR_NORETURN jerry_assert_fail (const char *assertion,
|
||||
const char *file,
|
||||
const char *function,
|
||||
const uint32_t line);
|
||||
void JERRY_ATTR_NORETURN jerry_unreachable (const char *file, const char *function, const uint32_t line);
|
||||
|
||||
#define JERRYX_ASSERT(x) \
|
||||
do \
|
||||
{ \
|
||||
if (JERRY_UNLIKELY (!(x))) \
|
||||
{ \
|
||||
#define JERRYX_ASSERT(x) \
|
||||
do \
|
||||
{ \
|
||||
if (JERRY_UNLIKELY (!(x))) \
|
||||
{ \
|
||||
jerry_assert_fail (#x, __FILE__, __func__, __LINE__); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define JERRYX_UNREACHABLE() \
|
||||
do \
|
||||
{ \
|
||||
#define JERRYX_UNREACHABLE() \
|
||||
do \
|
||||
{ \
|
||||
jerry_unreachable (__FILE__, __func__, __LINE__); \
|
||||
} while (0)
|
||||
#else /* JERRY_NDEBUG */
|
||||
#define JERRYX_ASSERT(x) \
|
||||
do \
|
||||
{ \
|
||||
if (false) \
|
||||
{ \
|
||||
do \
|
||||
{ \
|
||||
if (false) \
|
||||
{ \
|
||||
JERRYX_UNUSED (x); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __GNUC__
|
||||
@@ -75,7 +79,7 @@ jerry_unreachable (const char *file, const char *function, const uint32_t line);
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define JERRYX_UNREACHABLE() _assume (0)
|
||||
#define JERRYX_UNREACHABLE() _assume (0)
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#ifndef JERRYX_UNREACHABLE
|
||||
@@ -87,9 +91,9 @@ jerry_unreachable (const char *file, const char *function, const uint32_t line);
|
||||
/*
|
||||
* Logging
|
||||
*/
|
||||
#define JERRYX_ERROR_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_ERROR, __VA_ARGS__)
|
||||
#define JERRYX_ERROR_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_ERROR, __VA_ARGS__)
|
||||
#define JERRYX_WARNING_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_WARNING, __VA_ARGS__)
|
||||
#define JERRYX_DEBUG_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
||||
#define JERRYX_TRACE_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_TRACE, __VA_ARGS__)
|
||||
#define JERRYX_DEBUG_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_DEBUG, __VA_ARGS__)
|
||||
#define JERRYX_TRACE_MSG(...) jerry_port_log (JERRY_LOG_LEVEL_TRACE, __VA_ARGS__)
|
||||
|
||||
#endif /* !JEXT_COMMON_H */
|
||||
|
||||
@@ -23,7 +23,7 @@ void
|
||||
jerryx_debugger_after_connect (bool success) /**< tells whether the connection
|
||||
* has been successfully established */
|
||||
{
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
if (success)
|
||||
{
|
||||
jerry_debugger_transport_start ();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "jerryscript-ext/debugger.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
|
||||
/* A simplified transmission layer. */
|
||||
|
||||
|
||||
@@ -14,16 +14,17 @@
|
||||
*/
|
||||
|
||||
#include "jerryscript-debugger-transport.h"
|
||||
|
||||
#include "jerryscript-ext/debugger.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
#if (defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)) && !defined _WIN32
|
||||
#if (defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)) && !defined _WIN32
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Max size of configuration string */
|
||||
#define CONFIG_SIZE (255)
|
||||
@@ -208,7 +209,7 @@ jerryx_debugger_serial_configure_attributes (int fd, jerryx_debugger_transport_s
|
||||
options.c_lflag = 0;
|
||||
|
||||
/* Read returns when at least one byte of data is available. */
|
||||
options.c_cc[VMIN] = 1; // read block
|
||||
options.c_cc[VMIN] = 1; // read block
|
||||
options.c_cc[VTIME] = 5; // 0.5 seconds read timeout
|
||||
|
||||
/* Set the parameters associated with the file descriptor */
|
||||
@@ -279,8 +280,7 @@ jerryx_debugger_serial_send (jerry_debugger_transport_header_t *header_p, /**< s
|
||||
|
||||
message_p += sent_bytes;
|
||||
message_length -= (size_t) sent_bytes;
|
||||
}
|
||||
while (message_length > 0);
|
||||
} while (message_length > 0);
|
||||
|
||||
return true;
|
||||
} /* jerryx_debugger_serial_send */
|
||||
|
||||
@@ -41,9 +41,10 @@
|
||||
*/
|
||||
|
||||
#include "debugger-sha1.h"
|
||||
|
||||
#include "jext-common.h"
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
|
||||
/**
|
||||
* SHA-1 context structure.
|
||||
@@ -57,21 +58,19 @@ typedef struct
|
||||
|
||||
/* 32-bit integer manipulation macros (big endian). */
|
||||
|
||||
#define JERRYX_SHA1_GET_UINT32_BE(n, b, i) \
|
||||
{ \
|
||||
(n) = (((uint32_t) (b)[(i) + 0]) << 24) \
|
||||
| (((uint32_t) (b)[(i) + 1]) << 16) \
|
||||
| (((uint32_t) (b)[(i) + 2]) << 8) \
|
||||
| ((uint32_t) (b)[(i) + 3]); \
|
||||
}
|
||||
#define JERRYX_SHA1_GET_UINT32_BE(n, b, i) \
|
||||
{ \
|
||||
(n) = (((uint32_t) (b)[(i) + 0]) << 24) | (((uint32_t) (b)[(i) + 1]) << 16) | (((uint32_t) (b)[(i) + 2]) << 8) \
|
||||
| ((uint32_t) (b)[(i) + 3]); \
|
||||
}
|
||||
|
||||
#define JERRYX_SHA1_PUT_UINT32_BE(n, b, i) \
|
||||
{ \
|
||||
(b)[(i) + 0] = (uint8_t) ((n) >> 24); \
|
||||
(b)[(i) + 1] = (uint8_t) ((n) >> 16); \
|
||||
(b)[(i) + 2] = (uint8_t) ((n) >> 8); \
|
||||
(b)[(i) + 3] = (uint8_t) ((n)); \
|
||||
}
|
||||
{ \
|
||||
(b)[(i) + 0] = (uint8_t) ((n) >> 24); \
|
||||
(b)[(i) + 1] = (uint8_t) ((n) >> 16); \
|
||||
(b)[(i) + 2] = (uint8_t) ((n) >> 8); \
|
||||
(b)[(i) + 3] = (uint8_t) ((n)); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize SHA-1 context.
|
||||
@@ -91,11 +90,12 @@ jerryx_sha1_init (jerryx_sha1_context *sha1_context_p) /**< SHA-1 context */
|
||||
sha1_context_p->state[4] = 0xC3D2E1F0;
|
||||
} /* jerryx_sha1_init */
|
||||
|
||||
#define JERRYX_SHA1_P(a, b, c, d, e, x) \
|
||||
do { \
|
||||
e += JERRYX_SHA1_SHIFT (a, 5) + JERRYX_SHA1_F (b, c, d) + K + x; \
|
||||
b = JERRYX_SHA1_SHIFT (b, 30); \
|
||||
} while (0)
|
||||
#define JERRYX_SHA1_P(a, b, c, d, e, x) \
|
||||
do \
|
||||
{ \
|
||||
e += JERRYX_SHA1_SHIFT (a, 5) + JERRYX_SHA1_F (b, c, d) + K + x; \
|
||||
b = JERRYX_SHA1_SHIFT (b, 30); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Update SHA-1 internal buffer status.
|
||||
@@ -125,11 +125,9 @@ jerryx_sha1_process (jerryx_sha1_context *sha1_context_p, /**< SHA-1 context */
|
||||
|
||||
#define JERRYX_SHA1_SHIFT(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define JERRYX_SHA1_R(t) \
|
||||
( \
|
||||
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ W[(t - 14) & 0x0F] ^ W[t & 0x0F], \
|
||||
W[t & 0x0F] = JERRYX_SHA1_SHIFT (temp, 1) \
|
||||
)
|
||||
#define JERRYX_SHA1_R(t) \
|
||||
(temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ W[(t - 14) & 0x0F] ^ W[t & 0x0F], \
|
||||
W[t & 0x0F] = JERRYX_SHA1_SHIFT (temp, 1))
|
||||
|
||||
A = sha1_context_p->state[0];
|
||||
B = sha1_context_p->state[1];
|
||||
|
||||
@@ -18,12 +18,14 @@
|
||||
|
||||
#include "jerryscript-debugger-transport.h"
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
|
||||
/* JerryScript debugger protocol is a simplified version of RFC-6455 (WebSockets). */
|
||||
|
||||
void jerryx_debugger_compute_sha1 (const uint8_t *input1, size_t input1_len,
|
||||
const uint8_t *input2, size_t input2_len,
|
||||
void jerryx_debugger_compute_sha1 (const uint8_t *input1,
|
||||
size_t input1_len,
|
||||
const uint8_t *input2,
|
||||
size_t input2_len,
|
||||
uint8_t output[20]);
|
||||
|
||||
#endif /* defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1) */
|
||||
|
||||
@@ -14,15 +14,17 @@
|
||||
*/
|
||||
|
||||
#include "jerryscript-debugger-transport.h"
|
||||
|
||||
#include "jerryscript-ext/debugger.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <BaseTsd.h>
|
||||
|
||||
#include <WS2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
|
||||
@@ -43,13 +45,14 @@ typedef SOCKET jerryx_socket_t;
|
||||
typedef char jerryx_socket_void_t;
|
||||
typedef int jerryx_socket_size_t;
|
||||
#else /* !_WIN32 */
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/* On *nix the EWOULDBLOCK errno value can be returned for non-blocking operations */
|
||||
#define JERRYX_EWOULDBLOCK EWOULDBLOCK
|
||||
#define JERRYX_EWOULDBLOCK EWOULDBLOCK
|
||||
|
||||
/* On *nix the invalid socket has a value of -1 */
|
||||
#define JERRYX_SOCKET_INVALID (-1)
|
||||
@@ -181,10 +184,7 @@ jerryx_debugger_tcp_send (jerry_debugger_transport_header_t *header_p, /**< tcp
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
jerryx_socket_ssize_t sent_bytes = send (tcp_p->tcp_socket,
|
||||
(jerryx_socket_void_t *) message_p,
|
||||
remaining_bytes,
|
||||
0);
|
||||
jerryx_socket_ssize_t sent_bytes = send (tcp_p->tcp_socket, (jerryx_socket_void_t *) message_p, remaining_bytes, 0);
|
||||
|
||||
if (sent_bytes < 0)
|
||||
{
|
||||
@@ -202,8 +202,7 @@ jerryx_debugger_tcp_send (jerry_debugger_transport_header_t *header_p, /**< tcp
|
||||
|
||||
message_p += sent_bytes;
|
||||
remaining_bytes -= (jerryx_socket_size_t) sent_bytes;
|
||||
}
|
||||
while (remaining_bytes > 0);
|
||||
} while (remaining_bytes > 0);
|
||||
|
||||
return true;
|
||||
} /* jerryx_debugger_tcp_send */
|
||||
@@ -217,10 +216,10 @@ jerryx_debugger_tcp_receive (jerry_debugger_transport_header_t *header_p, /**< t
|
||||
{
|
||||
jerryx_debugger_transport_tcp_t *tcp_p = (jerryx_debugger_transport_tcp_t *) header_p;
|
||||
|
||||
jerryx_socket_void_t *buffer_p = (jerryx_socket_void_t *) (receive_context_p->buffer_p
|
||||
+ receive_context_p->received_length);
|
||||
jerryx_socket_size_t buffer_size = (jerryx_socket_size_t) (JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE
|
||||
- receive_context_p->received_length);
|
||||
jerryx_socket_void_t *buffer_p =
|
||||
(jerryx_socket_void_t *) (receive_context_p->buffer_p + receive_context_p->received_length);
|
||||
jerryx_socket_size_t buffer_size =
|
||||
(jerryx_socket_size_t) (JERRY_DEBUGGER_TRANSPORT_MAX_BUFFER_SIZE - receive_context_p->received_length);
|
||||
|
||||
jerryx_socket_ssize_t length = recv (tcp_p->tcp_socket, buffer_p, buffer_size, 0);
|
||||
|
||||
@@ -271,10 +270,8 @@ jerryx_debugger_tcp_configure_socket (jerryx_socket_t server_socket, /** < socke
|
||||
|
||||
const int opt_value = 1;
|
||||
|
||||
if (setsockopt (server_socket,
|
||||
SOL_SOCKET, SO_REUSEADDR,
|
||||
(const jerryx_socket_void_t *) &opt_value,
|
||||
sizeof (int)) != 0)
|
||||
if (setsockopt (server_socket, SOL_SOCKET, SO_REUSEADDR, (const jerryx_socket_void_t *) &opt_value, sizeof (int))
|
||||
!= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "jerryscript-ext/debugger.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
|
||||
/* JerryScript debugger protocol is a simplified version of RFC-6455 (WebSockets). */
|
||||
|
||||
@@ -114,8 +114,8 @@ jerryx_to_base64_character (uint8_t value) /**< 6-bit value */
|
||||
*/
|
||||
static void
|
||||
jerryx_to_base64 (const uint8_t *source_p, /**< source data */
|
||||
uint8_t *destination_p, /**< destination buffer */
|
||||
size_t length) /**< length of source, must be divisible by 3 */
|
||||
uint8_t *destination_p, /**< destination buffer */
|
||||
size_t length) /**< length of source, must be divisible by 3 */
|
||||
{
|
||||
while (length >= 3)
|
||||
{
|
||||
@@ -181,8 +181,7 @@ jerryx_process_handshake (uint8_t *request_buffer_p) /**< temporary buffer */
|
||||
request_end_p += (size_t) context.message_length;
|
||||
*request_end_p = 0;
|
||||
|
||||
if (request_end_p > request_buffer_p + 4
|
||||
&& memcmp (request_end_p - 4, "\r\n\r\n", 4) == 0)
|
||||
if (request_end_p > request_buffer_p + 4 && memcmp (request_end_p - 4, "\r\n\r\n", 4) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -192,8 +191,7 @@ jerryx_process_handshake (uint8_t *request_buffer_p) /**< temporary buffer */
|
||||
const char get_text[] = "GET /jerry-debugger";
|
||||
size_t text_len = sizeof (get_text) - 1;
|
||||
|
||||
if ((size_t) (request_end_p - request_buffer_p) < text_len
|
||||
|| memcmp (request_buffer_p, get_text, text_len) != 0)
|
||||
if ((size_t) (request_end_p - request_buffer_p) < text_len || memcmp (request_buffer_p, get_text, text_len) != 0)
|
||||
{
|
||||
JERRYX_ERROR_MSG ("Invalid handshake format.\n");
|
||||
return false;
|
||||
@@ -212,9 +210,7 @@ jerryx_process_handshake (uint8_t *request_buffer_p) /**< temporary buffer */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (websocket_key_p[0] == 'S'
|
||||
&& websocket_key_p[-1] == '\n'
|
||||
&& websocket_key_p[-2] == '\r'
|
||||
if (websocket_key_p[0] == 'S' && websocket_key_p[-1] == '\n' && websocket_key_p[-2] == '\r'
|
||||
&& memcmp (websocket_key_p, key_text, text_len) == 0)
|
||||
{
|
||||
websocket_key_p += text_len;
|
||||
@@ -244,10 +240,10 @@ jerryx_process_handshake (uint8_t *request_buffer_p) /**< temporary buffer */
|
||||
const size_t sha1_length = 20;
|
||||
|
||||
jerryx_debugger_compute_sha1 (websocket_key_p,
|
||||
(size_t) (websocket_key_end_p - websocket_key_p),
|
||||
(const uint8_t *) "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
||||
36,
|
||||
request_buffer_p);
|
||||
(size_t) (websocket_key_end_p - websocket_key_p),
|
||||
(const uint8_t *) "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
||||
36,
|
||||
request_buffer_p);
|
||||
|
||||
/* The SHA-1 key is 20 bytes long but jerryx_to_base64 expects
|
||||
* a length divisible by 3 so an extra 0 is appended at the end. */
|
||||
@@ -258,7 +254,7 @@ jerryx_process_handshake (uint8_t *request_buffer_p) /**< temporary buffer */
|
||||
/* Last value must be replaced by equal sign. */
|
||||
|
||||
const uint8_t response_prefix[] =
|
||||
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ";
|
||||
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ";
|
||||
|
||||
if (!jerry_debugger_transport_send (response_prefix, sizeof (response_prefix) - 1)
|
||||
|| !jerry_debugger_transport_send (request_buffer_p + sha1_length + 1, 27))
|
||||
|
||||
@@ -14,23 +14,21 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "handle-scope-internal.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
static jerryx_handle_scope_t jerryx_handle_scope_root =
|
||||
{
|
||||
static jerryx_handle_scope_t jerryx_handle_scope_root = {
|
||||
.prelist_handle_count = 0,
|
||||
.handle_ptr = NULL,
|
||||
};
|
||||
static jerryx_handle_scope_t *jerryx_handle_scope_current = &jerryx_handle_scope_root;
|
||||
static jerryx_handle_scope_pool_t jerryx_handle_scope_pool =
|
||||
{
|
||||
static jerryx_handle_scope_pool_t jerryx_handle_scope_pool = {
|
||||
.count = 0,
|
||||
.start = NULL,
|
||||
};
|
||||
|
||||
#define JERRYX_HANDLE_SCOPE_POOL_PRELIST_LAST \
|
||||
jerryx_handle_scope_pool.prelist + JERRYX_SCOPE_PRELIST_SIZE - 1
|
||||
#define JERRYX_HANDLE_SCOPE_POOL_PRELIST_LAST jerryx_handle_scope_pool.prelist + JERRYX_SCOPE_PRELIST_SIZE - 1
|
||||
|
||||
#define JERRYX_HANDLE_SCOPE_PRELIST_IDX(scope) (scope - jerryx_handle_scope_pool.prelist)
|
||||
|
||||
@@ -61,8 +59,8 @@ static bool
|
||||
jerryx_handle_scope_is_in_prelist (jerryx_handle_scope_t *scope)
|
||||
{
|
||||
return (jerryx_handle_scope_pool.prelist <= scope)
|
||||
&& (scope <= (jerryx_handle_scope_pool.prelist + JERRYX_SCOPE_PRELIST_SIZE - 1));
|
||||
} /** jerryx_handle_scope_is_in_prelist */
|
||||
&& (scope <= (jerryx_handle_scope_pool.prelist + JERRYX_SCOPE_PRELIST_SIZE - 1));
|
||||
} /* jerryx_handle_scope_is_in_prelist */
|
||||
|
||||
/**
|
||||
* Get the parent of given handle scope.
|
||||
@@ -95,7 +93,7 @@ jerryx_handle_scope_get_parent (jerryx_handle_scope_t *scope)
|
||||
return &jerryx_handle_scope_root;
|
||||
}
|
||||
return jerryx_handle_scope_pool.prelist + JERRYX_HANDLE_SCOPE_PRELIST_IDX (scope) - 1;
|
||||
} /** jerryx_handle_scope_get_parent */
|
||||
} /* jerryx_handle_scope_get_parent */
|
||||
|
||||
/**
|
||||
* Get the child of given handle scope.
|
||||
@@ -136,7 +134,7 @@ jerryx_handle_scope_get_child (jerryx_handle_scope_t *scope)
|
||||
return NULL;
|
||||
}
|
||||
return jerryx_handle_scope_pool.prelist + idx + 1;
|
||||
} /** jerryx_handle_scope_get_child */
|
||||
} /* jerryx_handle_scope_get_child */
|
||||
|
||||
/**
|
||||
* Claims a handle scope either from prelist or allocating a new memory block,
|
||||
@@ -184,7 +182,7 @@ jerryx_handle_scope_alloc (void)
|
||||
jerryx_handle_scope_current = scope;
|
||||
++jerryx_handle_scope_pool.count;
|
||||
return (jerryx_handle_scope_t *) scope;
|
||||
} /** jerryx_handle_scope_alloc */
|
||||
} /* jerryx_handle_scope_alloc */
|
||||
|
||||
/**
|
||||
* Deannounce a previously claimed handle scope, return it to pool
|
||||
@@ -223,4 +221,4 @@ jerryx_handle_scope_free (jerryx_handle_scope_t *scope)
|
||||
/**
|
||||
* Nothing to do with scopes in prelist
|
||||
*/
|
||||
} /** jerryx_handle_scope_free */
|
||||
} /* jerryx_handle_scope_free */
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
#ifndef JERRYX_HANDLE_SCOPE_INTERNAL_H
|
||||
#define JERRYX_HANDLE_SCOPE_INTERNAL_H
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "jerryscript-ext/handle-scope.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
/** MARK: - handle-scope-allocator.c */
|
||||
typedef struct jerryx_handle_scope_pool_s jerryx_handle_scope_pool_t;
|
||||
@@ -38,37 +36,28 @@ struct jerryx_handle_scope_pool_s
|
||||
jerryx_handle_scope_dynamic_t *start; /**< start address of dynamically allocated handle scope list */
|
||||
};
|
||||
|
||||
jerryx_handle_scope_t *
|
||||
jerryx_handle_scope_get_parent (jerryx_handle_scope_t *scope);
|
||||
jerryx_handle_scope_t *jerryx_handle_scope_get_parent (jerryx_handle_scope_t *scope);
|
||||
|
||||
jerryx_handle_scope_t *
|
||||
jerryx_handle_scope_get_child (jerryx_handle_scope_t *scope);
|
||||
jerryx_handle_scope_t *jerryx_handle_scope_get_child (jerryx_handle_scope_t *scope);
|
||||
|
||||
jerryx_handle_scope_t *
|
||||
jerryx_handle_scope_alloc (void);
|
||||
jerryx_handle_scope_t *jerryx_handle_scope_alloc (void);
|
||||
|
||||
void
|
||||
jerryx_handle_scope_free (jerryx_handle_scope_t *scope);
|
||||
void jerryx_handle_scope_free (jerryx_handle_scope_t *scope);
|
||||
/** MARK: - END handle-scope-allocator.c */
|
||||
|
||||
/** MARK: - handle-scope.c */
|
||||
void
|
||||
jerryx_handle_scope_release_handles (jerryx_handle_scope scope);
|
||||
void jerryx_handle_scope_release_handles (jerryx_handle_scope scope);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t idx);
|
||||
jerry_value_t jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t idx);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope scope);
|
||||
jerry_value_t jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope scope);
|
||||
|
||||
jerryx_handle_scope_status
|
||||
jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
|
||||
jerry_value_t escapee,
|
||||
jerry_value_t *result,
|
||||
bool should_promote);
|
||||
jerryx_handle_scope_status jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
|
||||
jerry_value_t escapee,
|
||||
jerry_value_t *result,
|
||||
bool should_promote);
|
||||
/** MARK: - END handle-scope.c */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_END
|
||||
|
||||
#endif /* !JERRYX_HANDLE_SCOPE_INTERNAL_H */
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "handle-scope-internal.h"
|
||||
#include "jext-common.h"
|
||||
|
||||
@@ -30,7 +31,7 @@ jerryx_open_handle_scope (jerryx_handle_scope *result)
|
||||
{
|
||||
*result = jerryx_handle_scope_alloc ();
|
||||
return jerryx_handle_scope_ok;
|
||||
} /** jerryx_open_handle_scope */
|
||||
} /* jerryx_open_handle_scope */
|
||||
|
||||
/**
|
||||
* Release all jerry values attached to given scope
|
||||
@@ -60,7 +61,7 @@ jerryx_handle_scope_release_handles (jerryx_handle_scope scope)
|
||||
jerry_release_value (scope->handle_prelist[idx]);
|
||||
}
|
||||
scope->prelist_handle_count = 0;
|
||||
} /** jerryx_handle_scope_release_handles */
|
||||
} /* jerryx_handle_scope_release_handles */
|
||||
|
||||
/**
|
||||
* Close the scope and its child scopes and release all jerry values that
|
||||
@@ -83,11 +84,10 @@ jerryx_close_handle_scope (jerryx_handle_scope scope)
|
||||
jerryx_handle_scope child = jerryx_handle_scope_get_child (a_scope);
|
||||
jerryx_handle_scope_free (a_scope);
|
||||
a_scope = child;
|
||||
}
|
||||
while (a_scope != NULL);
|
||||
} while (a_scope != NULL);
|
||||
|
||||
return jerryx_handle_scope_ok;
|
||||
} /** jerryx_close_handle_scope */
|
||||
} /* jerryx_close_handle_scope */
|
||||
|
||||
/**
|
||||
* Opens a new handle scope from which one object can be promoted to the outer scope
|
||||
@@ -100,7 +100,7 @@ jerryx_handle_scope_status
|
||||
jerryx_open_escapable_handle_scope (jerryx_handle_scope *result)
|
||||
{
|
||||
return jerryx_open_handle_scope (result);
|
||||
} /** jerryx_open_escapable_handle_scope */
|
||||
} /* jerryx_open_escapable_handle_scope */
|
||||
|
||||
/**
|
||||
* Close the scope and its child scopes and release all jerry values that
|
||||
@@ -114,7 +114,7 @@ jerryx_handle_scope_status
|
||||
jerryx_close_escapable_handle_scope (jerryx_handle_scope scope)
|
||||
{
|
||||
return jerryx_close_handle_scope (scope);
|
||||
} /** jerryx_close_escapable_handle_scope */
|
||||
} /* jerryx_close_escapable_handle_scope */
|
||||
|
||||
/**
|
||||
* Internal helper.
|
||||
@@ -143,7 +143,7 @@ jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t
|
||||
scope->handle_prelist[idx] = scope->handle_prelist[scope->prelist_handle_count - 1];
|
||||
}
|
||||
return jval;
|
||||
} /** jerryx_hand_scope_escape_handle_from_prelist */
|
||||
} /* jerryx_hand_scope_escape_handle_from_prelist */
|
||||
|
||||
/**
|
||||
* Internal helper.
|
||||
@@ -261,7 +261,7 @@ jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
|
||||
scope->escaped = true;
|
||||
}
|
||||
return jerryx_handle_scope_ok;
|
||||
} /** jerryx_escape_handle_internal */
|
||||
} /* jerryx_escape_handle_internal */
|
||||
|
||||
/**
|
||||
* Promotes the handle to the JavaScript object so that it is valid for the lifetime of
|
||||
@@ -274,12 +274,10 @@ jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
|
||||
* @return status code, jerryx_handle_scope_ok if success.
|
||||
*/
|
||||
jerryx_handle_scope_status
|
||||
jerryx_escape_handle (jerryx_escapable_handle_scope scope,
|
||||
jerry_value_t escapee,
|
||||
jerry_value_t *result)
|
||||
jerryx_escape_handle (jerryx_escapable_handle_scope scope, jerry_value_t escapee, jerry_value_t *result)
|
||||
{
|
||||
return jerryx_escape_handle_internal (scope, escapee, result, true);
|
||||
} /** jerryx_escape_handle */
|
||||
} /* jerryx_escape_handle */
|
||||
|
||||
/**
|
||||
* Escape a handle from scope yet do not promote it to the outer scope.
|
||||
@@ -291,12 +289,10 @@ jerryx_escape_handle (jerryx_escapable_handle_scope scope,
|
||||
* @return status code, jerryx_handle_scope_ok if success.
|
||||
*/
|
||||
jerryx_handle_scope_status
|
||||
jerryx_remove_handle (jerryx_escapable_handle_scope scope,
|
||||
jerry_value_t escapee,
|
||||
jerry_value_t *result)
|
||||
jerryx_remove_handle (jerryx_escapable_handle_scope scope, jerry_value_t escapee, jerry_value_t *result)
|
||||
{
|
||||
return jerryx_escape_handle_internal (scope, escapee, result, false);
|
||||
} /** jerryx_remove_handle */
|
||||
} /* jerryx_remove_handle */
|
||||
|
||||
/**
|
||||
* Try to reuse given handle if possible while adding to the scope.
|
||||
@@ -321,7 +317,7 @@ jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope
|
||||
handle->sibling = scope->handle_ptr;
|
||||
scope->handle_ptr = handle;
|
||||
return handle->jval;
|
||||
} /** jerryx_handle_scope_add_handle_to */
|
||||
} /* jerryx_handle_scope_add_handle_to */
|
||||
|
||||
/**
|
||||
* Add given jerry value to the scope.
|
||||
@@ -349,7 +345,7 @@ jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope)
|
||||
scope->handle_ptr = handle;
|
||||
|
||||
return jval;
|
||||
} /** jerryx_create_handle_in_scope */
|
||||
} /* jerryx_create_handle_in_scope */
|
||||
|
||||
/**
|
||||
* Add given jerry value to current top scope.
|
||||
@@ -361,4 +357,4 @@ jerry_value_t
|
||||
jerryx_create_handle (jerry_value_t jval)
|
||||
{
|
||||
return jerryx_create_handle_in_scope (jval, jerryx_handle_scope_get_current ());
|
||||
} /** jerryx_create_handle */
|
||||
} /* jerryx_create_handle */
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript-ext/handler.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "jerryscript-ext/handler.h"
|
||||
|
||||
/**
|
||||
* Hard assert for scripts. The routine calls jerry_port_fatal on assertion failure.
|
||||
@@ -35,8 +36,7 @@ jerryx_handler_assert_fatal (const jerry_call_info_t *call_info_p, /**< call inf
|
||||
{
|
||||
(void) call_info_p; /* unused */
|
||||
|
||||
if (args_cnt == 1
|
||||
&& jerry_value_is_true (args_p[0]))
|
||||
if (args_cnt == 1 && jerry_value_is_true (args_p[0]))
|
||||
{
|
||||
return jerry_create_boolean (true);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ jerryx_handler_assert_fatal (const jerry_call_info_t *call_info_p, /**< call inf
|
||||
* on some systems it can be printed. To avoid differences in the uint32_t typdef
|
||||
* The "PRIu32" macro is used to correctly add the formatter.
|
||||
*/
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, " %"PRIu32": ", idx);
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, " %" PRIu32 ": ", idx);
|
||||
do
|
||||
{
|
||||
jerry_size_t copied_bytes = jerry_substring_to_utf8_char_buffer (property,
|
||||
@@ -77,8 +77,7 @@ jerryx_handler_assert_fatal (const jerry_call_info_t *call_info_p, /**< call inf
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "%s", string_buffer);
|
||||
|
||||
current_size += copied_bytes;
|
||||
}
|
||||
while (total_size != current_size);
|
||||
} while (total_size != current_size);
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "\n");
|
||||
|
||||
jerry_release_value (property);
|
||||
@@ -103,8 +102,7 @@ jerryx_handler_assert_throw (const jerry_call_info_t *call_info_p, /**< call inf
|
||||
{
|
||||
(void) call_info_p; /* unused */
|
||||
|
||||
if (args_cnt == 1
|
||||
&& jerry_value_is_true (args_p[0]))
|
||||
if (args_cnt == 1 && jerry_value_is_true (args_p[0]))
|
||||
{
|
||||
return jerry_create_boolean (true);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ jerryx_handler_gc (const jerry_call_info_t *call_info_p, /**< call information *
|
||||
{
|
||||
(void) call_info_p; /* unused */
|
||||
|
||||
jerry_gc_mode_t mode = ((args_cnt > 0 && jerry_value_to_boolean (args_p[0])) ? JERRY_GC_PRESSURE_HIGH
|
||||
: JERRY_GC_PRESSURE_LOW);
|
||||
jerry_gc_mode_t mode =
|
||||
((args_cnt > 0 && jerry_value_to_boolean (args_p[0])) ? JERRY_GC_PRESSURE_HIGH : JERRY_GC_PRESSURE_LOW);
|
||||
|
||||
jerry_gc (mode);
|
||||
return jerry_create_undefined ();
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript-ext/handler.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-debugger.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
#include "jerryscript-ext/handler.h"
|
||||
|
||||
/**
|
||||
* Provide a 'print' implementation for scripts.
|
||||
@@ -43,7 +44,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
||||
{
|
||||
(void) call_info_p; /* unused */
|
||||
|
||||
const char * const null_str = "\\u0000";
|
||||
const char *const null_str = "\\u0000";
|
||||
|
||||
jerry_value_t ret_val = jerry_create_undefined ();
|
||||
|
||||
@@ -73,11 +74,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
||||
|
||||
do
|
||||
{
|
||||
jerry_size_t substr_size = jerry_substring_to_utf8_char_buffer (str_val,
|
||||
substr_pos,
|
||||
length,
|
||||
substr_buf,
|
||||
256 - 1);
|
||||
jerry_size_t substr_size = jerry_substring_to_utf8_char_buffer (str_val, substr_pos, length, substr_buf, 256 - 1);
|
||||
|
||||
jerry_char_t *buf_end_p = substr_buf + substr_size;
|
||||
|
||||
@@ -111,8 +108,7 @@ jerryx_handler_print (const jerry_call_info_t *call_info_p, /**< call informatio
|
||||
jerry_port_print_char (null_str[null_index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (substr_pos < length);
|
||||
} while (substr_pos < length);
|
||||
|
||||
jerry_release_value (str_val);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ jerryx_register_result
|
||||
jerryx_set_properties (const jerry_value_t target_object, /**< target object */
|
||||
const jerryx_property_entry entries[]) /**< array of method entries */
|
||||
{
|
||||
#define JERRYX_SET_PROPERTIES_RESULT(VALUE, IDX) ((jerryx_register_result) { VALUE, IDX })
|
||||
#define JERRYX_SET_PROPERTIES_RESULT(VALUE, IDX) ((jerryx_register_result){ VALUE, IDX })
|
||||
uint32_t idx = 0;
|
||||
|
||||
if (entries == NULL)
|
||||
|
||||
@@ -19,12 +19,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
/**
|
||||
* The forward declaration of jerryx_arg_t.
|
||||
@@ -88,9 +86,8 @@ jerry_value_t jerryx_arg_transform_object_properties (const jerry_value_t obj_va
|
||||
const jerry_length_t name_cnt,
|
||||
const jerryx_arg_t *c_arg_p,
|
||||
jerry_length_t c_arg_cnt);
|
||||
jerry_value_t jerryx_arg_transform_array (const jerry_value_t array_val,
|
||||
const jerryx_arg_t *c_arg_p,
|
||||
jerry_length_t c_arg_cnt);
|
||||
jerry_value_t
|
||||
jerryx_arg_transform_array (const jerry_value_t array_val, const jerryx_arg_t *c_arg_p, jerry_length_t c_arg_cnt);
|
||||
|
||||
/**
|
||||
* Indicates whether an argument is allowed to be coerced into the expected JS type.
|
||||
@@ -135,19 +132,18 @@ typedef enum
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
JERRYX_ARG_CLAMP,/**< clamp the number when it is out of range */
|
||||
JERRYX_ARG_CLAMP, /**< clamp the number when it is out of range */
|
||||
JERRYX_ARG_NO_CLAMP /**< throw a range error */
|
||||
} jerryx_arg_clamp_t;
|
||||
|
||||
/* Inline functions for initializing jerryx_arg_t */
|
||||
|
||||
#define JERRYX_ARG_INTEGER(type) \
|
||||
static inline jerryx_arg_t \
|
||||
jerryx_arg_ ## type (type ## _t *dest, \
|
||||
jerryx_arg_round_t round_flag, \
|
||||
jerryx_arg_clamp_t clamp_flag, \
|
||||
jerryx_arg_coerce_t coerce_flag, \
|
||||
jerryx_arg_optional_t opt_flag);
|
||||
#define JERRYX_ARG_INTEGER(type) \
|
||||
static inline jerryx_arg_t jerryx_arg_##type (type##_t *dest, \
|
||||
jerryx_arg_round_t round_flag, \
|
||||
jerryx_arg_clamp_t clamp_flag, \
|
||||
jerryx_arg_coerce_t coerce_flag, \
|
||||
jerryx_arg_optional_t opt_flag);
|
||||
|
||||
JERRYX_ARG_INTEGER (uint8)
|
||||
JERRYX_ARG_INTEGER (int8)
|
||||
@@ -166,23 +162,19 @@ static inline jerryx_arg_t
|
||||
jerryx_arg_string (char *dest, uint32_t size, jerryx_arg_coerce_t coerce_flag, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_utf8_string (char *dest, uint32_t size, jerryx_arg_coerce_t coerce_flag, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_function (jerry_value_t *dest, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t jerryx_arg_function (jerry_value_t *dest, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_native_pointer (void **dest, const jerry_object_native_info_t *info_p, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_ignore (void);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_custom (void *dest, uintptr_t extra_info, jerryx_arg_transform_func_t func);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props_p, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_array (const jerryx_arg_array_items_t *array_items_p, jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t jerryx_arg_ignore (void);
|
||||
static inline jerryx_arg_t jerryx_arg_custom (void *dest, uintptr_t extra_info, jerryx_arg_transform_func_t func);
|
||||
static inline jerryx_arg_t jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props_p,
|
||||
jerryx_arg_optional_t opt_flag);
|
||||
static inline jerryx_arg_t jerryx_arg_array (const jerryx_arg_array_items_t *array_items_p,
|
||||
jerryx_arg_optional_t opt_flag);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_arg_transform_optional (jerryx_arg_js_iterator_t *js_arg_iter_p,
|
||||
const jerryx_arg_t *c_arg_p,
|
||||
jerryx_arg_transform_func_t func);
|
||||
jerry_value_t jerryx_arg_transform_optional (jerryx_arg_js_iterator_t *js_arg_iter_p,
|
||||
const jerryx_arg_t *c_arg_p,
|
||||
jerryx_arg_transform_func_t func);
|
||||
|
||||
/* Helper functions for transform functions. */
|
||||
jerry_value_t jerryx_arg_js_iterator_pop (jerryx_arg_js_iterator_t *js_arg_iter_p);
|
||||
@@ -192,7 +184,6 @@ jerry_length_t jerryx_arg_js_iterator_index (jerryx_arg_js_iterator_t *js_arg_it
|
||||
|
||||
#include "arg.impl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_END
|
||||
|
||||
#endif /* !JERRYX_ARG_H */
|
||||
|
||||
@@ -18,15 +18,14 @@
|
||||
|
||||
/* transform functions for each type. */
|
||||
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL(type) \
|
||||
jerry_value_t jerryx_arg_transform_ ## type (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p); \
|
||||
jerry_value_t jerryx_arg_transform_ ## type ## _optional (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p);
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL(type) \
|
||||
jerry_value_t jerryx_arg_transform_##type (jerryx_arg_js_iterator_t *js_arg_iter_p, const jerryx_arg_t *c_arg_p); \
|
||||
jerry_value_t jerryx_arg_transform_##type##_optional (jerryx_arg_js_iterator_t *js_arg_iter_p, \
|
||||
const jerryx_arg_t *c_arg_p);
|
||||
|
||||
#define JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT(type) \
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (type) \
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (type ## _strict)
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (type) \
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (type##_strict)
|
||||
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (uint8)
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT (int8)
|
||||
@@ -44,8 +43,7 @@ JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (native_pointer)
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (object_props)
|
||||
JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL (array_items)
|
||||
|
||||
jerry_value_t jerryx_arg_transform_ignore (jerryx_arg_js_iterator_t *js_arg_iter_p,
|
||||
const jerryx_arg_t *c_arg_p);
|
||||
jerry_value_t jerryx_arg_transform_ignore (jerryx_arg_js_iterator_t *js_arg_iter_p, const jerryx_arg_t *c_arg_p);
|
||||
|
||||
#undef JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL
|
||||
#undef JERRYX_ARG_TRANSFORM_FUNC_WITH_OPTIONAL_AND_STRICT
|
||||
@@ -63,48 +61,42 @@ typedef struct
|
||||
/**
|
||||
* The macro used to generate jerryx_arg_xxx for int type.
|
||||
*/
|
||||
#define JERRYX_ARG_INT(type) \
|
||||
static inline jerryx_arg_t \
|
||||
jerryx_arg_ ## type (type ## _t *dest, \
|
||||
jerryx_arg_round_t round_flag, \
|
||||
jerryx_arg_clamp_t clamp_flag, \
|
||||
jerryx_arg_coerce_t coerce_flag, \
|
||||
jerryx_arg_optional_t opt_flag) \
|
||||
{ \
|
||||
jerryx_arg_transform_func_t func; \
|
||||
if (coerce_flag == JERRYX_ARG_NO_COERCE) \
|
||||
{ \
|
||||
if (opt_flag == JERRYX_ARG_OPTIONAL) \
|
||||
{ \
|
||||
func = jerryx_arg_transform_ ## type ## _strict_optional; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
func = jerryx_arg_transform_ ## type ## _strict; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if (opt_flag == JERRYX_ARG_OPTIONAL) \
|
||||
{ \
|
||||
func = jerryx_arg_transform_ ## type ## _optional; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
func = jerryx_arg_transform_ ## type; \
|
||||
} \
|
||||
} \
|
||||
union \
|
||||
{ \
|
||||
jerryx_arg_int_option_t int_option; \
|
||||
uintptr_t extra_info; \
|
||||
#define JERRYX_ARG_INT(type) \
|
||||
static inline jerryx_arg_t jerryx_arg_##type (type##_t *dest, \
|
||||
jerryx_arg_round_t round_flag, \
|
||||
jerryx_arg_clamp_t clamp_flag, \
|
||||
jerryx_arg_coerce_t coerce_flag, \
|
||||
jerryx_arg_optional_t opt_flag) \
|
||||
{ \
|
||||
jerryx_arg_transform_func_t func; \
|
||||
if (coerce_flag == JERRYX_ARG_NO_COERCE) \
|
||||
{ \
|
||||
if (opt_flag == JERRYX_ARG_OPTIONAL) \
|
||||
{ \
|
||||
func = jerryx_arg_transform_##type##_strict_optional; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
func = jerryx_arg_transform_##type##_strict; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if (opt_flag == JERRYX_ARG_OPTIONAL) \
|
||||
{ \
|
||||
func = jerryx_arg_transform_##type##_optional; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
func = jerryx_arg_transform_##type; \
|
||||
} \
|
||||
} \
|
||||
union \
|
||||
{ \
|
||||
jerryx_arg_int_option_t int_option; \
|
||||
uintptr_t extra_info; \
|
||||
} u = { .int_option = { .round = (uint8_t) round_flag, .clamp = (uint8_t) clamp_flag } }; \
|
||||
return (jerryx_arg_t) \
|
||||
{ \
|
||||
.func = func, \
|
||||
.dest = (void *) dest, \
|
||||
.extra_info = u.extra_info \
|
||||
}; \
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest, .extra_info = u.extra_info }; \
|
||||
}
|
||||
|
||||
JERRYX_ARG_INT (uint8)
|
||||
@@ -152,11 +144,7 @@ jerryx_arg_number (double *dest, /**< pointer to the double where the result sho
|
||||
}
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = (void *) dest
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest };
|
||||
} /* jerryx_arg_number */
|
||||
|
||||
/**
|
||||
@@ -195,11 +183,7 @@ jerryx_arg_boolean (bool *dest, /**< points to the native bool */
|
||||
}
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = (void *) dest
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest };
|
||||
} /* jerryx_arg_boolean */
|
||||
|
||||
/**
|
||||
@@ -239,12 +223,7 @@ jerryx_arg_string (char *dest, /**< pointer to the native char array where the r
|
||||
}
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = (void *) dest,
|
||||
.extra_info = (uintptr_t) size
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest, .extra_info = (uintptr_t) size };
|
||||
} /* jerryx_arg_string */
|
||||
|
||||
/**
|
||||
@@ -284,12 +263,7 @@ jerryx_arg_utf8_string (char *dest, /**< [out] pointer to the native char array
|
||||
}
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = (void *) dest,
|
||||
.extra_info = (uintptr_t) size
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest, .extra_info = (uintptr_t) size };
|
||||
} /* jerryx_arg_utf8_string */
|
||||
|
||||
/**
|
||||
@@ -313,11 +287,7 @@ jerryx_arg_function (jerry_value_t *dest, /**< pointer to the jerry_value_t wher
|
||||
func = jerryx_arg_transform_function;
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = (void *) dest
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest };
|
||||
} /* jerryx_arg_function */
|
||||
|
||||
/**
|
||||
@@ -344,12 +314,7 @@ jerryx_arg_native_pointer (void **dest, /**< pointer to where the resulting nati
|
||||
func = jerryx_arg_transform_native_pointer;
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = (void *) dest,
|
||||
.extra_info = (uintptr_t) info_p
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = (void *) dest, .extra_info = (uintptr_t) info_p };
|
||||
} /* jerryx_arg_native_pointer */
|
||||
|
||||
/**
|
||||
@@ -360,10 +325,7 @@ jerryx_arg_native_pointer (void **dest, /**< pointer to where the resulting nati
|
||||
static inline jerryx_arg_t
|
||||
jerryx_arg_ignore (void)
|
||||
{
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = jerryx_arg_transform_ignore
|
||||
};
|
||||
return (jerryx_arg_t){ .func = jerryx_arg_transform_ignore };
|
||||
} /* jerryx_arg_ignore */
|
||||
|
||||
/**
|
||||
@@ -376,12 +338,7 @@ jerryx_arg_custom (void *dest, /**< pointer to the native argument where the res
|
||||
uintptr_t extra_info, /**< the extra parameter, specific to the transform function */
|
||||
jerryx_arg_transform_func_t func) /**< the custom transform function */
|
||||
{
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = dest,
|
||||
.extra_info = extra_info
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = dest, .extra_info = extra_info };
|
||||
} /* jerryx_arg_custom */
|
||||
|
||||
/**
|
||||
@@ -404,12 +361,7 @@ jerryx_arg_object_properties (const jerryx_arg_object_props_t *object_props, /**
|
||||
func = jerryx_arg_transform_object_props;
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = NULL,
|
||||
.extra_info = (uintptr_t) object_props
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = NULL, .extra_info = (uintptr_t) object_props };
|
||||
} /* jerryx_arg_object_properties */
|
||||
|
||||
/**
|
||||
@@ -432,12 +384,7 @@ jerryx_arg_array (const jerryx_arg_array_items_t *array_items_p, /**< pointer to
|
||||
func = jerryx_arg_transform_array_items;
|
||||
}
|
||||
|
||||
return (jerryx_arg_t)
|
||||
{
|
||||
.func = func,
|
||||
.dest = NULL,
|
||||
.extra_info = (uintptr_t) array_items_p
|
||||
};
|
||||
return (jerryx_arg_t){ .func = func, .dest = NULL, .extra_info = (uintptr_t) array_items_p };
|
||||
} /* jerryx_arg_array */
|
||||
|
||||
#endif /* !JERRYX_ARG_IMPL_H */
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
#ifndef JERRYX_AUTORELEASE_H
|
||||
#define JERRYX_AUTORELEASE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
#include "autorelease.impl.h"
|
||||
|
||||
@@ -48,7 +45,6 @@ extern "C"
|
||||
*/
|
||||
#define JERRYX_AR_VALUE_T __JERRYX_AR_VALUE_T_IMPL
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_END
|
||||
|
||||
#endif /* !JERRYX_AUTORELEASE_H */
|
||||
|
||||
@@ -31,7 +31,7 @@ jerryx_autorelease_cleanup (const jerry_value_t *value) /**< jerry value */
|
||||
jerry_release_value (*value);
|
||||
} /* jerryx_autorelease_cleanup */
|
||||
|
||||
#define __JERRYX_AR_VALUE_T_IMPL const jerry_value_t __attribute__ ((__cleanup__(jerryx_autorelease_cleanup)))
|
||||
#define __JERRYX_AR_VALUE_T_IMPL const jerry_value_t __attribute__ ((__cleanup__ (jerryx_autorelease_cleanup)))
|
||||
#else /* !__GNUC__ */
|
||||
/* TODO: for other compilers */
|
||||
#error "No autorelease implementation for your compiler!"
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
#ifndef JERRYX_DEBUGGER_H
|
||||
#define JERRYX_DEBUGGER_H
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-debugger-transport.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
void jerryx_debugger_after_connect (bool success);
|
||||
|
||||
@@ -38,7 +35,6 @@ bool jerryx_debugger_serial_create (const char *config);
|
||||
bool jerryx_debugger_ws_create (void);
|
||||
bool jerryx_debugger_rp_create (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_END
|
||||
|
||||
#endif /* !JERRYX_HANDLER_H */
|
||||
|
||||
@@ -18,18 +18,15 @@
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
#ifndef JERRYX_HANDLE_PRELIST_SIZE
|
||||
#define JERRYX_HANDLE_PRELIST_SIZE 20
|
||||
#endif
|
||||
#endif /* !defined(JERRYX_HANDLE_PRELIST_SIZE) */
|
||||
|
||||
#ifndef JERRYX_SCOPE_PRELIST_SIZE
|
||||
#define JERRYX_SCOPE_PRELIST_SIZE 20
|
||||
#endif
|
||||
#endif /* !defined(JERRYX_SCOPE_PRELIST_SIZE) */
|
||||
|
||||
typedef struct jerryx_handle_t jerryx_handle_t;
|
||||
/**
|
||||
@@ -82,47 +79,34 @@ typedef enum
|
||||
jerryx_handle_scope_mismatch,
|
||||
} jerryx_handle_scope_status;
|
||||
|
||||
jerryx_handle_scope_status
|
||||
jerryx_open_handle_scope (jerryx_handle_scope *result);
|
||||
jerryx_handle_scope_status jerryx_open_handle_scope (jerryx_handle_scope *result);
|
||||
|
||||
jerryx_handle_scope_status jerryx_close_handle_scope (jerryx_handle_scope scope);
|
||||
|
||||
jerryx_handle_scope_status jerryx_open_escapable_handle_scope (jerryx_handle_scope *result);
|
||||
|
||||
jerryx_handle_scope_status jerryx_close_escapable_handle_scope (jerryx_handle_scope scope);
|
||||
|
||||
jerryx_handle_scope_status
|
||||
jerryx_close_handle_scope (jerryx_handle_scope scope);
|
||||
|
||||
jerryx_handle_scope_status
|
||||
jerryx_open_escapable_handle_scope (jerryx_handle_scope *result);
|
||||
|
||||
jerryx_handle_scope_status
|
||||
jerryx_close_escapable_handle_scope (jerryx_handle_scope scope);
|
||||
|
||||
jerryx_handle_scope_status
|
||||
jerryx_escape_handle (jerryx_escapable_handle_scope scope,
|
||||
jerry_value_t escapee,
|
||||
jerry_value_t *result);
|
||||
jerryx_escape_handle (jerryx_escapable_handle_scope scope, jerry_value_t escapee, jerry_value_t *result);
|
||||
|
||||
/**
|
||||
* Completely escape a handle from handle scope,
|
||||
* leave life time management totally up to user.
|
||||
*/
|
||||
jerryx_handle_scope_status
|
||||
jerryx_remove_handle (jerryx_escapable_handle_scope scope,
|
||||
jerry_value_t escapee,
|
||||
jerry_value_t *result);
|
||||
jerryx_remove_handle (jerryx_escapable_handle_scope scope, jerry_value_t escapee, jerry_value_t *result);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_create_handle (jerry_value_t jval);
|
||||
jerry_value_t jerryx_create_handle (jerry_value_t jval);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope);
|
||||
jerry_value_t jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope);
|
||||
|
||||
/** MARK: - handle-scope-allocator.c */
|
||||
jerryx_handle_scope_t *
|
||||
jerryx_handle_scope_get_current (void);
|
||||
jerryx_handle_scope_t *jerryx_handle_scope_get_current (void);
|
||||
|
||||
jerryx_handle_scope_t *
|
||||
jerryx_handle_scope_get_root (void);
|
||||
jerryx_handle_scope_t *jerryx_handle_scope_get_root (void);
|
||||
/** MARK: - END handle-scope-allocator.c */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_END
|
||||
|
||||
#endif /* !JERRYX_HANDLE_SCOPE_H */
|
||||
|
||||
@@ -18,34 +18,35 @@
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
/*
|
||||
* Handler registration helper
|
||||
*/
|
||||
|
||||
jerry_value_t jerryx_handler_register_global (const jerry_char_t *name_p,
|
||||
jerry_external_handler_t handler_p);
|
||||
jerry_value_t jerryx_handler_register_global (const jerry_char_t *name_p, jerry_external_handler_t handler_p);
|
||||
|
||||
/*
|
||||
* Common external function handlers
|
||||
*/
|
||||
|
||||
jerry_value_t jerryx_handler_assert_fatal (const jerry_call_info_t *call_info_p,
|
||||
const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
const jerry_value_t args_p[],
|
||||
const jerry_length_t args_cnt);
|
||||
jerry_value_t jerryx_handler_assert_throw (const jerry_call_info_t *call_info_p,
|
||||
const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
const jerry_value_t args_p[],
|
||||
const jerry_length_t args_cnt);
|
||||
jerry_value_t jerryx_handler_assert (const jerry_call_info_t *call_info_p,
|
||||
const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
jerry_value_t jerryx_handler_gc (const jerry_call_info_t *call_info_p,
|
||||
const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
const jerry_value_t args_p[],
|
||||
const jerry_length_t args_cnt);
|
||||
jerry_value_t
|
||||
jerryx_handler_gc (const jerry_call_info_t *call_info_p, const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
jerry_value_t jerryx_handler_print (const jerry_call_info_t *call_info_p,
|
||||
const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
const jerry_value_t args_p[],
|
||||
const jerry_length_t args_cnt);
|
||||
jerry_value_t jerryx_handler_resource_name (const jerry_call_info_t *call_info_p,
|
||||
const jerry_value_t args_p[], const jerry_length_t args_cnt);
|
||||
const jerry_value_t args_p[],
|
||||
const jerry_length_t args_cnt);
|
||||
|
||||
/**
|
||||
* Struct used by the `jerryx_set_functions` method to
|
||||
@@ -57,15 +58,41 @@ typedef struct
|
||||
jerry_value_t value; /**< value of the property */
|
||||
} jerryx_property_entry;
|
||||
|
||||
#define JERRYX_PROPERTY_NUMBER(NAME, NUMBER) (jerryx_property_entry) { NAME, jerry_create_number (NUMBER) }
|
||||
#define JERRYX_PROPERTY_STRING(NAME, STR) \
|
||||
(jerryx_property_entry) { NAME, jerry_create_string_from_utf8 ((const jerry_char_t *) STR) }
|
||||
#define JERRYX_PROPERTY_STRING_SZ(NAME, STR, SIZE) \
|
||||
(jerryx_property_entry) { NAME, jerry_create_string_sz_from_utf8 ((const jerry_char_t *) STR, SIZE) }
|
||||
#define JERRYX_PROPERTY_BOOLEAN(NAME, VALUE) (jerryx_property_entry) { NAME, jerry_create_boolean (VALUE) }
|
||||
#define JERRYX_PROPERTY_FUNCTION(NAME, FUNC) (jerryx_property_entry) { NAME, jerry_create_external_function (FUNC) }
|
||||
#define JERRYX_PROPERTY_UNDEFINED(NAME) (jerryx_property_entry) { NAME, jerry_create_undefined() }
|
||||
#define JERRYX_PROPERTY_LIST_END() (jerryx_property_entry) { NULL, 0 }
|
||||
#define JERRYX_PROPERTY_NUMBER(NAME, NUMBER) \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NAME, jerry_create_number (NUMBER) \
|
||||
}
|
||||
#define JERRYX_PROPERTY_STRING(NAME, STR) \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NAME, jerry_create_string_from_utf8 ((const jerry_char_t *) STR) \
|
||||
}
|
||||
#define JERRYX_PROPERTY_STRING_SZ(NAME, STR, SIZE) \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NAME, jerry_create_string_sz_from_utf8 ((const jerry_char_t *) STR, SIZE) \
|
||||
}
|
||||
#define JERRYX_PROPERTY_BOOLEAN(NAME, VALUE) \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NAME, jerry_create_boolean (VALUE) \
|
||||
}
|
||||
#define JERRYX_PROPERTY_FUNCTION(NAME, FUNC) \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NAME, jerry_create_external_function (FUNC) \
|
||||
}
|
||||
#define JERRYX_PROPERTY_UNDEFINED(NAME) \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NAME, jerry_create_undefined () \
|
||||
}
|
||||
#define JERRYX_PROPERTY_LIST_END() \
|
||||
(jerryx_property_entry) \
|
||||
{ \
|
||||
NULL, 0 \
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the result of property register operation.
|
||||
@@ -76,28 +103,17 @@ typedef struct
|
||||
uint32_t registered; /**< number of successfully registered methods */
|
||||
} jerryx_register_result;
|
||||
|
||||
jerryx_register_result
|
||||
jerryx_set_properties (const jerry_value_t target_object,
|
||||
const jerryx_property_entry entries[]);
|
||||
jerryx_register_result jerryx_set_properties (const jerry_value_t target_object, const jerryx_property_entry entries[]);
|
||||
|
||||
void
|
||||
jerryx_release_property_entry (const jerryx_property_entry entries[],
|
||||
const jerryx_register_result register_result);
|
||||
void jerryx_release_property_entry (const jerryx_property_entry entries[],
|
||||
const jerryx_register_result register_result);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_set_property_str (const jerry_value_t target_object,
|
||||
const char *name,
|
||||
const jerry_value_t value);
|
||||
jerry_value_t jerryx_set_property_str (const jerry_value_t target_object, const char *name, const jerry_value_t value);
|
||||
|
||||
jerry_value_t
|
||||
jerryx_get_property_str (const jerry_value_t target_object,
|
||||
const char *name);
|
||||
jerry_value_t jerryx_get_property_str (const jerry_value_t target_object, const char *name);
|
||||
|
||||
bool
|
||||
jerryx_has_property_str (const jerry_value_t target_object,
|
||||
const char *name);
|
||||
bool jerryx_has_property_str (const jerry_value_t target_object, const char *name);
|
||||
|
||||
JERRY_C_API_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* !JERRYX_HANDLER_H */
|
||||
|
||||
@@ -18,10 +18,7 @@
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
/**
|
||||
* Declare the signature for the module initialization function.
|
||||
@@ -47,9 +44,9 @@ typedef struct jerryx_native_module_t
|
||||
#ifdef _MSC_VER
|
||||
#error "`FEATURE_INIT_FINI` build flag isn't supported on Windows, because Microsoft Visual C/C++ Compiler \
|
||||
doesn't support library constructors and destructors."
|
||||
#endif
|
||||
#define JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE __attribute__((constructor))
|
||||
#define JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE __attribute__((destructor))
|
||||
#endif /* _MSC_VER */
|
||||
#define JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor))
|
||||
#define JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
|
||||
#define JERRYX_MODULE_REGISTRATION_QUALIFIER static
|
||||
#else /* !ENABLE_INIT_FINI */
|
||||
#define JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE
|
||||
@@ -60,32 +57,23 @@ doesn't support library constructors and destructors."
|
||||
/**
|
||||
* Having two levels of macros allows strings to be used unquoted.
|
||||
*/
|
||||
#define JERRYX_NATIVE_MODULE(module_name, on_resolve_cb) \
|
||||
JERRYX_NATIVE_MODULE_IMPLEM(module_name, on_resolve_cb)
|
||||
#define JERRYX_NATIVE_MODULE(module_name, on_resolve_cb) JERRYX_NATIVE_MODULE_IMPLEM (module_name, on_resolve_cb)
|
||||
|
||||
#define JERRYX_NATIVE_MODULE_IMPLEM(module_name, on_resolve_cb) \
|
||||
static jerryx_native_module_t _ ## module_name ## _definition = \
|
||||
{ \
|
||||
.name_p = (jerry_char_t *) #module_name, \
|
||||
.on_resolve_p = (on_resolve_cb), \
|
||||
.next_p = NULL \
|
||||
}; \
|
||||
\
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void \
|
||||
module_name ## _register (void) JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE; \
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void \
|
||||
module_name ## _register (void) \
|
||||
{ \
|
||||
jerryx_native_module_register(&_##module_name##_definition); \
|
||||
} \
|
||||
\
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void \
|
||||
module_name ## _unregister (void) \
|
||||
JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE; \
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void \
|
||||
module_name ## _unregister (void) \
|
||||
{ \
|
||||
jerryx_native_module_unregister(&_##module_name##_definition); \
|
||||
#define JERRYX_NATIVE_MODULE_IMPLEM(module_name, on_resolve_cb) \
|
||||
static jerryx_native_module_t _##module_name##_definition = { .name_p = (jerry_char_t *) #module_name, \
|
||||
.on_resolve_p = (on_resolve_cb), \
|
||||
.next_p = NULL }; \
|
||||
\
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void module_name##_register (void) JERRYX_MODULE_CONSTRUCTOR_ATTRIBUTE; \
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void module_name##_register (void) \
|
||||
{ \
|
||||
jerryx_native_module_register (&_##module_name##_definition); \
|
||||
} \
|
||||
\
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void module_name##_unregister (void) JERRYX_MODULE_DESTRUCTOR_ATTRIBUTE; \
|
||||
JERRYX_MODULE_REGISTRATION_QUALIFIER void module_name##_unregister (void) \
|
||||
{ \
|
||||
jerryx_native_module_unregister (&_##module_name##_definition); \
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,18 +122,14 @@ extern jerryx_module_resolver_t jerryx_module_native_resolver;
|
||||
* Load a copy of a module into the current context using the provided module resolvers, or return one that was already
|
||||
* loaded if it is found.
|
||||
*/
|
||||
jerry_value_t jerryx_module_resolve (const jerry_value_t name,
|
||||
const jerryx_module_resolver_t **resolvers,
|
||||
size_t count);
|
||||
jerry_value_t
|
||||
jerryx_module_resolve (const jerry_value_t name, const jerryx_module_resolver_t **resolvers, size_t count);
|
||||
|
||||
/**
|
||||
* Delete a module from the cache or, if name has the JavaScript value of undefined, clear the entire cache.
|
||||
*/
|
||||
void jerryx_module_clear_cache (const jerry_value_t name,
|
||||
const jerryx_module_resolver_t **resolvers,
|
||||
size_t count);
|
||||
void jerryx_module_clear_cache (const jerry_value_t name, const jerryx_module_resolver_t **resolvers, size_t count);
|
||||
|
||||
JERRY_C_API_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* !JERRYX_MODULE_H */
|
||||
|
||||
+20
-25
@@ -13,10 +13,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-ext/module.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
|
||||
static const jerry_char_t *module_name_property_name = (jerry_char_t *) "moduleName";
|
||||
static const jerry_char_t *module_not_found = (jerry_char_t *) "Module not found";
|
||||
static const jerry_char_t *module_name_not_string = (jerry_char_t *) "Module name is not a string";
|
||||
@@ -67,25 +69,24 @@ jerryx_module_manager_deinit (void *user_data_p) /**< context pointer to deiniti
|
||||
/**
|
||||
* Declare the context data manager for modules.
|
||||
*/
|
||||
static const jerry_context_data_manager_t jerryx_module_manager =
|
||||
{
|
||||
.init_cb = jerryx_module_manager_init,
|
||||
.deinit_cb = jerryx_module_manager_deinit,
|
||||
.bytes_needed = sizeof (jerry_value_t)
|
||||
};
|
||||
static const jerry_context_data_manager_t jerryx_module_manager = { .init_cb = jerryx_module_manager_init,
|
||||
.deinit_cb = jerryx_module_manager_deinit,
|
||||
.bytes_needed = sizeof (jerry_value_t) };
|
||||
|
||||
/**
|
||||
* Global static entry point to the linked list of available modules.
|
||||
*/
|
||||
static jerryx_native_module_t *first_module_p = NULL;
|
||||
|
||||
void jerryx_native_module_register (jerryx_native_module_t *module_p)
|
||||
void
|
||||
jerryx_native_module_register (jerryx_native_module_t *module_p)
|
||||
{
|
||||
module_p->next_p = first_module_p;
|
||||
first_module_p = module_p;
|
||||
} /* jerryx_native_module_register */
|
||||
|
||||
void jerryx_native_module_unregister (jerryx_native_module_t *module_p)
|
||||
void
|
||||
jerryx_native_module_unregister (jerryx_native_module_t *module_p)
|
||||
{
|
||||
jerryx_native_module_t *parent_p = NULL, *iter_p = NULL;
|
||||
|
||||
@@ -186,15 +187,13 @@ jerryx_resolve_native_module (const jerry_value_t canonical_name, /**< canonical
|
||||
/* Look for the module by its name in the list of module definitions. */
|
||||
for (module_p = first_module_p; module_p != NULL; module_p = module_p->next_p)
|
||||
{
|
||||
if (module_p->name_p != NULL
|
||||
&& strlen ((char *) module_p->name_p) == name_size
|
||||
if (module_p->name_p != NULL && strlen ((char *) module_p->name_p) == name_size
|
||||
&& !strncmp ((char *) module_p->name_p, (char *) name_string, name_size))
|
||||
{
|
||||
/* If we find the module by its name we load it and cache it if it has an on_resolve () and complain otherwise. */
|
||||
(*result) = ((module_p->on_resolve_p) ? module_p->on_resolve_p ()
|
||||
: jerryx_module_create_error (JERRY_ERROR_TYPE,
|
||||
on_resolve_absent,
|
||||
canonical_name));
|
||||
(*result) =
|
||||
((module_p->on_resolve_p) ? module_p->on_resolve_p ()
|
||||
: jerryx_module_create_error (JERRY_ERROR_TYPE, on_resolve_absent, canonical_name));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -202,11 +201,8 @@ jerryx_resolve_native_module (const jerry_value_t canonical_name, /**< canonical
|
||||
return false;
|
||||
} /* jerryx_resolve_native_module */
|
||||
|
||||
jerryx_module_resolver_t jerryx_module_native_resolver =
|
||||
{
|
||||
.get_canonical_name_p = NULL,
|
||||
.resolve_p = jerryx_resolve_native_module
|
||||
};
|
||||
jerryx_module_resolver_t jerryx_module_native_resolver = { .get_canonical_name_p = NULL,
|
||||
.resolve_p = jerryx_resolve_native_module };
|
||||
|
||||
static void
|
||||
jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module to load */
|
||||
@@ -219,8 +215,7 @@ jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module t
|
||||
jerry_value_t instances;
|
||||
JERRY_VLA (jerry_value_t, canonical_names, resolver_count);
|
||||
jerry_value_t (*get_canonical_name_p) (const jerry_value_t name);
|
||||
bool (*resolve_p) (const jerry_value_t canonical_name,
|
||||
jerry_value_t *result);
|
||||
bool (*resolve_p) (const jerry_value_t canonical_name, jerry_value_t *result);
|
||||
|
||||
if (!jerry_value_is_string (name))
|
||||
{
|
||||
@@ -240,8 +235,8 @@ jerryx_module_resolve_local (const jerry_value_t name, /**< name of the module t
|
||||
for (index = 0; index < resolver_count; index++)
|
||||
{
|
||||
get_canonical_name_p = (resolvers_p[index] == NULL ? NULL : resolvers_p[index]->get_canonical_name_p);
|
||||
canonical_names[index] = ((get_canonical_name_p == NULL) ? jerry_acquire_value (name)
|
||||
: get_canonical_name_p (name));
|
||||
canonical_names[index] =
|
||||
((get_canonical_name_p == NULL) ? jerry_acquire_value (name) : get_canonical_name_p (name));
|
||||
canonical_names_used++;
|
||||
if (jerryx_module_check_cache (instances, canonical_names[index], result))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user