Jerry API for calling functions C -> Jerry, creating objects, reading / writing object's properties (currently, only interface declaration, without implementation).

This commit is contained in:
Ruben Ayrapetyan
2015-03-27 18:01:20 +03:00
parent 80d9328c1f
commit 9746b2fd76
7 changed files with 316 additions and 120 deletions
@@ -150,10 +150,10 @@ ecma_builtin_jerry_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
uint32_t arg_index; uint32_t arg_index;
for (arg_index = 0; arg_index < function_p->args_number; arg_index++) for (arg_index = 0; arg_index < function_p->args_number; arg_index++)
{ {
jerry_extension_function_arg_t *arg_p = &function_p->args_p [arg_index]; jerry_api_value_t *arg_p = &function_p->args_p [arg_index];
const ecma_value_t arg_value = arguments_list [arg_index]; const ecma_value_t arg_value = arguments_list [arg_index];
if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_BOOLEAN) if (arg_p->type == JERRY_API_DATA_TYPE_BOOLEAN)
{ {
if (!ecma_is_value_boolean (arg_value)) if (!ecma_is_value_boolean (arg_value))
{ {
@@ -164,9 +164,9 @@ ecma_builtin_jerry_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
arg_p->v_bool = ecma_is_value_true (arg_value); arg_p->v_bool = ecma_is_value_true (arg_value);
} }
} }
else if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_FLOAT32 else if (arg_p->type == JERRY_API_DATA_TYPE_FLOAT32
|| arg_p->type == JERRY_EXTENSION_FIELD_TYPE_FLOAT64 || arg_p->type == JERRY_API_DATA_TYPE_FLOAT64
|| arg_p->type == JERRY_EXTENSION_FIELD_TYPE_UINT32) || arg_p->type == JERRY_API_DATA_TYPE_UINT32)
{ {
if (!ecma_is_value_number (arg_value)) if (!ecma_is_value_number (arg_value))
{ {
@@ -175,11 +175,11 @@ ecma_builtin_jerry_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
else else
{ {
ecma_number_t num_value = *ecma_get_number_from_value (arg_value); ecma_number_t num_value = *ecma_get_number_from_value (arg_value);
if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_FLOAT32) if (arg_p->type == JERRY_API_DATA_TYPE_FLOAT32)
{ {
arg_p->v_float32 = (float) num_value; arg_p->v_float32 = (float) num_value;
} }
else if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_FLOAT64) else if (arg_p->type == JERRY_API_DATA_TYPE_FLOAT64)
{ {
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 #if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
JERRY_UNREACHABLE (); JERRY_UNREACHABLE ();
@@ -187,13 +187,13 @@ ecma_builtin_jerry_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
arg_p->v_float64 = num_value; arg_p->v_float64 = num_value;
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */ #endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT64 */
} }
else if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_UINT32) else if (arg_p->type == JERRY_API_DATA_TYPE_UINT32)
{ {
arg_p->v_uint32 = ecma_number_to_uint32 (num_value); arg_p->v_uint32 = ecma_number_to_uint32 (num_value);
} }
} }
} }
else if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_STRING) else if (arg_p->type == JERRY_API_DATA_TYPE_STRING)
{ {
if (!ecma_is_value_string (arg_value)) if (!ecma_is_value_string (arg_value))
{ {
@@ -206,7 +206,7 @@ ecma_builtin_jerry_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
} }
else else
{ {
JERRY_ASSERT (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_OBJECT); JERRY_ASSERT (arg_p->type == JERRY_API_DATA_TYPE_OBJECT);
if (!ecma_is_value_object (arg_value)) if (!ecma_is_value_object (arg_value))
{ {
@@ -234,22 +234,22 @@ ecma_builtin_jerry_dispatch_routine (uint16_t builtin_routine_id, /**< built-in
arg_index < initialized_args_count; arg_index < initialized_args_count;
arg_index++) arg_index++)
{ {
jerry_extension_function_arg_t *arg_p = &function_p->args_p [arg_index]; jerry_api_value_t *arg_p = &function_p->args_p [arg_index];
if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_STRING) if (arg_p->type == JERRY_API_DATA_TYPE_STRING)
{ {
arg_p->v_string = NULL; arg_p->v_string = NULL;
} }
else if (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_OBJECT) else if (arg_p->type == JERRY_API_DATA_TYPE_OBJECT)
{ {
arg_p->v_object = NULL; arg_p->v_object = NULL;
} }
else else
{ {
JERRY_ASSERT (arg_p->type == JERRY_EXTENSION_FIELD_TYPE_BOOLEAN JERRY_ASSERT (arg_p->type == JERRY_API_DATA_TYPE_BOOLEAN
|| arg_p->type == JERRY_EXTENSION_FIELD_TYPE_FLOAT32 || arg_p->type == JERRY_API_DATA_TYPE_FLOAT32
|| arg_p->type == JERRY_EXTENSION_FIELD_TYPE_FLOAT64 || arg_p->type == JERRY_API_DATA_TYPE_FLOAT64
|| arg_p->type == JERRY_EXTENSION_FIELD_TYPE_UINT32); || arg_p->type == JERRY_API_DATA_TYPE_UINT32);
} }
} }
} }
@@ -302,7 +302,7 @@ ecma_extension_register (jerry_extension_descriptor_t *extension_desc_p) /**< ex
/* Check if we can represent the arguments' values */ /* Check if we can represent the arguments' values */
for (uint32_t j = 0; j < extension_desc_p->functions_p [i].args_number; j++) for (uint32_t j = 0; j < extension_desc_p->functions_p [i].args_number; j++)
{ {
if (extension_desc_p->functions_p[i].args_p[j].type == JERRY_EXTENSION_FIELD_TYPE_FLOAT64) if (extension_desc_p->functions_p[i].args_p[j].type == JERRY_API_DATA_TYPE_FLOAT64)
{ {
return false; return false;
} }
@@ -325,12 +325,12 @@ ecma_extension_register (jerry_extension_descriptor_t *extension_desc_p) /**< ex
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 #if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
/* Check if we can represent the field's value */ /* Check if we can represent the field's value */
if (extension_desc_p->fields_p[i].type == JERRY_EXTENSION_FIELD_TYPE_FLOAT64) if (extension_desc_p->fields_p[i].type == JERRY_API_DATA_TYPE_FLOAT64)
{ {
return false; return false;
} }
if (extension_desc_p->fields_p[i].type == JERRY_EXTENSION_FIELD_TYPE_UINT32 if (extension_desc_p->fields_p[i].type == JERRY_API_DATA_TYPE_UINT32
&& ecma_number_to_uint32 (ecma_uint32_to_number (extension_desc_p->fields_p[i].v_uint32)) && ecma_number_to_uint32 (ecma_uint32_to_number (extension_desc_p->fields_p[i].v_uint32))
!= extension_desc_p->fields_p[i].v_uint32) != extension_desc_p->fields_p[i].v_uint32)
{ {
@@ -440,13 +440,13 @@ ecma_op_extension_object_get_own_property (ecma_object_t *obj_p, /**< the extens
switch (field_p->type) switch (field_p->type)
{ {
case JERRY_EXTENSION_FIELD_TYPE_BOOLEAN: case JERRY_API_DATA_TYPE_BOOLEAN:
{ {
value = ecma_make_simple_value (field_p->v_bool ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE); value = ecma_make_simple_value (field_p->v_bool ? ECMA_SIMPLE_VALUE_TRUE : ECMA_SIMPLE_VALUE_FALSE);
break; break;
} }
case JERRY_EXTENSION_FIELD_TYPE_FLOAT32: case JERRY_API_DATA_TYPE_FLOAT32:
{ {
ecma_number_t *num_p = ecma_alloc_number (); ecma_number_t *num_p = ecma_alloc_number ();
*num_p = field_p->v_float32; *num_p = field_p->v_float32;
@@ -454,7 +454,7 @@ ecma_op_extension_object_get_own_property (ecma_object_t *obj_p, /**< the extens
break; break;
} }
case JERRY_EXTENSION_FIELD_TYPE_FLOAT64: case JERRY_API_DATA_TYPE_FLOAT64:
{ {
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 #if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
JERRY_UNREACHABLE (); JERRY_UNREACHABLE ();
@@ -466,7 +466,7 @@ ecma_op_extension_object_get_own_property (ecma_object_t *obj_p, /**< the extens
break; break;
} }
case JERRY_EXTENSION_FIELD_TYPE_UINT32: case JERRY_API_DATA_TYPE_UINT32:
{ {
ecma_number_t *num_p = ecma_alloc_number (); ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ecma_uint32_to_number (field_p->v_uint32); *num_p = ecma_uint32_to_number (field_p->v_uint32);
@@ -475,7 +475,7 @@ ecma_op_extension_object_get_own_property (ecma_object_t *obj_p, /**< the extens
break; break;
} }
case JERRY_EXTENSION_FIELD_TYPE_STRING: case JERRY_API_DATA_TYPE_STRING:
{ {
const ecma_char_t *string_p = (const ecma_char_t*) field_p->v_string; const ecma_char_t *string_p = (const ecma_char_t*) field_p->v_string;
ecma_string_t *str_p = ecma_new_ecma_string (string_p); ecma_string_t *str_p = ecma_new_ecma_string (string_p);
@@ -483,7 +483,7 @@ ecma_op_extension_object_get_own_property (ecma_object_t *obj_p, /**< the extens
break; break;
} }
case JERRY_EXTENSION_FIELD_TYPE_OBJECT: case JERRY_API_DATA_TYPE_OBJECT:
{ {
JERRY_UNREACHABLE (); JERRY_UNREACHABLE ();
} }
+125
View File
@@ -0,0 +1,125 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* 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 JERRY_API_H
#define JERRY_API_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
# define EXTERN_C "C"
#else /* !__cplusplus */
# define EXTERN_C
#endif /* !__cplusplus */
/** \addtogroup jerry Jerry engine interface
* @{
*/
/**
* Jerry API data types
*/
typedef enum
{
JERRY_API_DATA_TYPE_BOOLEAN, /**< bool */
JERRY_API_DATA_TYPE_FLOAT32, /**< 32-bit float */
JERRY_API_DATA_TYPE_FLOAT64, /**< 64-bit float */
JERRY_API_DATA_TYPE_UINT32, /**< number converted to 32-bit unsigned integer*/
JERRY_API_DATA_TYPE_STRING, /**< string */
JERRY_API_DATA_TYPE_OBJECT /**< object */
} jerry_api_data_type_t;
/**
* Jerry's string value
*/
typedef struct ecma_string_t jerry_api_string_t;
/**
* Jerry's object value
*/
typedef struct ecma_object_t jerry_api_object_t;
/**
* Description of an extension function's argument
*/
typedef struct
{
const jerry_api_data_type_t type; /**< argument data type */
union
{
bool v_bool; /**< boolean */
float v_float32; /**< 32-bit float */
double v_float64; /**< 64-bit float */
uint32_t v_uint32; /**< number converted 32-bit unsigned integer */
union
{
jerry_api_string_t *v_string; /**< pointer to a JS string */
jerry_api_object_t *v_object; /**< pointer to a JS object */
};
};
} jerry_api_value_t;
extern EXTERN_C ssize_t
jerry_api_string_to_char_buffer (const jerry_api_string_t *string_p,
char *buffer_p,
ssize_t buffer_size);
extern EXTERN_C
jerry_api_string_t* jerry_api_acquire_string (jerry_api_string_t *string_p);
extern EXTERN_C
void jerry_api_release_string (jerry_api_string_t *string_p);
extern EXTERN_C
jerry_api_object_t* jerry_api_acquire_object (jerry_api_object_t *object_p);
extern EXTERN_C
void jerry_api_release_object (jerry_api_object_t *object_p);
extern EXTERN_C
bool jerry_api_call_function (jerry_api_object_t *function_object_p,
jerry_api_value_t *retval_p,
const jerry_api_value_t args_p [],
uint32_t args_count);
extern EXTERN_C
jerry_api_object_t* jerry_api_create_object (void);
extern EXTERN_C
bool jerry_api_add_object_field (jerry_api_object_t *object_p,
const char *field_name_p,
const jerry_api_value_t *field_value_p,
bool is_writable);
extern EXTERN_C
bool jerry_api_delete_object_field (jerry_api_object_t *object_p,
const char *field_name_p);
extern EXTERN_C
bool jerry_api_get_object_field_value (jerry_api_object_t *object_p,
const char *field_name_p,
jerry_api_value_t *field_value_p);
extern EXTERN_C
bool jerry_api_set_object_field_value (jerry_api_object_t *object_p,
const char *field_name_p,
const jerry_api_value_t *field_value_p);
/**
* @}
*/
#endif /* !JERRY_API_H */
+8 -63
View File
@@ -21,39 +21,16 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef __cplusplus #include "jerry-api.h"
# define EXTERN_C "C"
#else /* !__cplusplus */ /** \addtogroup jerry Jerry engine interface
# define EXTERN_C * @{
#endif /* !__cplusplus */ */
/** \addtogroup jerry Jerry engine extension interface /** \addtogroup jerry Jerry engine extension interface
* @{ * @{
*/ */
/**
* Jerry's extension-related data types
*/
typedef enum
{
JERRY_EXTENSION_FIELD_TYPE_BOOLEAN, /**< bool */
JERRY_EXTENSION_FIELD_TYPE_FLOAT32, /**< 32-bit float */
JERRY_EXTENSION_FIELD_TYPE_FLOAT64, /**< 64-bit float */
JERRY_EXTENSION_FIELD_TYPE_UINT32, /**< number converted to 32-bit unsigned integer*/
JERRY_EXTENSION_FIELD_TYPE_STRING, /**< string */
JERRY_EXTENSION_FIELD_TYPE_OBJECT /**< object */
} jerry_extension_data_type_t;
/**
* An interface for Jerry's string value
*/
typedef struct ecma_string_t jerry_string_t;
/**
* An interface for Jerry's object value
*/
typedef struct ecma_object_t jerry_object_t;
/** /**
* Description of an extension object's fields * Description of an extension object's fields
*/ */
@@ -61,7 +38,7 @@ typedef struct
{ {
const char *field_name_p; /**< field name */ const char *field_name_p; /**< field name */
const jerry_extension_data_type_t type; /**< field data type */ const jerry_api_data_type_t type; /**< field data type */
/** /**
* Value description * Value description
@@ -76,30 +53,6 @@ typedef struct
}; };
} jerry_extension_field_t; } jerry_extension_field_t;
/**
* Description of an extension function's argument
*/
typedef struct
{
const jerry_extension_data_type_t type; /**< argument data type */
union
{
bool v_bool; /**< boolean */
float v_float32; /**< 32-bit float */
double v_float64; /**< 64-bit float */
uint32_t v_uint32; /**< number converted 32-bit unsigned integer */
union
{
jerry_string_t *v_string; /**< pointer to a JS string */
jerry_object_t *v_object; /**< pointer to a JS object */
};
};
} jerry_extension_function_arg_t;
/** /**
* Pointer to extension function implementation * Pointer to extension function implementation
*/ */
@@ -114,7 +67,7 @@ typedef struct jerry_extension_function_t
jerry_extension_function_pointer_t function_wrapper_p; /**< pointer to function implementation */ jerry_extension_function_pointer_t function_wrapper_p; /**< pointer to function implementation */
jerry_extension_function_arg_t *args_p; /**< arrays of the function's arguments */ jerry_api_value_t *args_p; /**< arrays of the function's arguments */
uint32_t args_number; /**< number of arguments */ uint32_t args_number; /**< number of arguments */
} jerry_extension_function_t; } jerry_extension_function_t;
@@ -137,16 +90,8 @@ typedef struct jerry_extension_descriptor_t
extern EXTERN_C bool extern EXTERN_C bool
jerry_extend_with (jerry_extension_descriptor_t *desc_p); jerry_extend_with (jerry_extension_descriptor_t *desc_p);
extern EXTERN_C ssize_t
jerry_string_to_char_buffer (const jerry_string_t *string_p,
char *buffer_p,
ssize_t buffer_size);
extern EXTERN_C jerry_string_t* jerry_acquire_string (jerry_string_t *string_p);
extern EXTERN_C void jerry_release_string (jerry_string_t *string_p);
extern EXTERN_C jerry_object_t* jerry_acquire_object (jerry_object_t *object_p);
extern EXTERN_C void jerry_release_object (jerry_object_t *object_p);
/** /**
* @}
* @} * @}
*/ */
+4 -4
View File
@@ -39,7 +39,7 @@ enum
static const jerry_extension_field_t jerry_extension_fields [JERRY_EXTENSION_FIELDS_NUMBER + 1] = static const jerry_extension_field_t jerry_extension_fields [JERRY_EXTENSION_FIELDS_NUMBER + 1] =
{ {
#define EXTENSION_FIELD(_field_name, _type, _value) \ #define EXTENSION_FIELD(_field_name, _type, _value) \
{ # _field_name, JERRY_EXTENSION_FIELD_TYPE_ ## _type, _value }, { # _field_name, JERRY_API_DATA_TYPE_ ## _type, _value },
# include EXTENSION_DESCRIPTION_HEADER # include EXTENSION_DESCRIPTION_HEADER
#undef EXTENSION_FIELD #undef EXTENSION_FIELD
}; };
@@ -61,7 +61,7 @@ static const jerry_extension_field_t jerry_extension_fields [JERRY_EXTENSION_FIE
#define EXTENSION_FUNCTION(_function_name, _function_to_call, _args_number, ...) \ #define EXTENSION_FUNCTION(_function_name, _function_to_call, _args_number, ...) \
static void jerry_extension_ ## _function_name ## _wrapper (const jerry_extension_function_t *function_block_p) \ static void jerry_extension_ ## _function_name ## _wrapper (const jerry_extension_function_t *function_block_p) \
{ \ { \
const jerry_extension_function_arg_t *args_p = function_block_p->args_p; \ const jerry_api_value_t *args_p = function_block_p->args_p; \
_function_to_call (__VA_ARGS__); \ _function_to_call (__VA_ARGS__); \
} }
# include EXTENSION_DESCRIPTION_HEADER # include EXTENSION_DESCRIPTION_HEADER
@@ -76,11 +76,11 @@ static const jerry_extension_field_t jerry_extension_fields [JERRY_EXTENSION_FIE
/* Functions' arguments description */ /* Functions' arguments description */
#define EXTENSION_ARG(_arg_index, _type) [_arg_index] = { \ #define EXTENSION_ARG(_arg_index, _type) [_arg_index] = { \
(JERRY_EXTENSION_FIELD_TYPE_ ## _type), \ (JERRY_API_DATA_TYPE_ ## _type), \
false /* just for initialization, should be overwritten upon call */ \ false /* just for initialization, should be overwritten upon call */ \
} }
#define EXTENSION_FUNCTION(_function_name, _function_to_call, _args_number, ...) \ #define EXTENSION_FUNCTION(_function_name, _function_to_call, _args_number, ...) \
static jerry_extension_function_arg_t jerry_extension_function_ ## _function_name ## _args [_args_number] = { \ static jerry_api_value_t jerry_extension_function_ ## _function_name ## _args [_args_number] = { \
__VA_ARGS__ \ __VA_ARGS__ \
}; };
# include EXTENSION_DESCRIPTION_HEADER # include EXTENSION_DESCRIPTION_HEADER
+150 -18
View File
@@ -18,6 +18,7 @@
#include "ecma-gc.h" #include "ecma-gc.h"
#include "ecma-helpers.h" #include "ecma-helpers.h"
#include "ecma-init-finalize.h" #include "ecma-init-finalize.h"
#include "ecma-objects-general.h"
#include "jerry.h" #include "jerry.h"
#include "jrt.h" #include "jrt.h"
#include "parser.h" #include "parser.h"
@@ -65,6 +66,10 @@ jerry_extend_with (jerry_extension_descriptor_t *desc_p) /**< description of the
return ecma_extension_register (desc_p); return ecma_extension_register (desc_p);
} /* jerry_extend_with */ } /* jerry_extend_with */
/**
* @}
*/
/** /**
* Copy string characters to specified buffer, append zero character at end of the buffer. * Copy string characters to specified buffer, append zero character at end of the buffer.
* *
@@ -73,65 +78,188 @@ jerry_extend_with (jerry_extension_descriptor_t *desc_p) /**< description of the
* as negation of buffer size, that is required to hold the string's content. * as negation of buffer size, that is required to hold the string's content.
*/ */
ssize_t ssize_t
jerry_string_to_char_buffer (const jerry_string_t *string_p, /**< string descriptor */ jerry_api_string_to_char_buffer (const jerry_api_string_t *string_p, /**< string descriptor */
char *buffer_p, /**< output characters buffer */ char *buffer_p, /**< output characters buffer */
ssize_t buffer_size) /**< size of output buffer */ ssize_t buffer_size) /**< size of output buffer */
{ {
return ecma_string_to_zt_string (string_p, (ecma_char_t*) buffer_p, buffer_size); return ecma_string_to_zt_string (string_p, (ecma_char_t*) buffer_p, buffer_size);
} /* jerry_string_to_char_buffer */ } /* jerry_api_string_to_char_buffer */
/** /**
* Acquire string pointer for usage outside of the engine * Acquire string pointer for usage outside of the engine
* from string retrieved in extension routine call from engine.
* *
* Warning: * Warning:
* acquired pointer should be released with jerry_release_string * acquired pointer should be released with jerry_api_release_string
* *
* @return pointer that may be used outside of the engine * @return pointer that may be used outside of the engine
*/ */
jerry_string_t* jerry_api_string_t*
jerry_acquire_string (jerry_string_t *string_p) /**< pointer passed to function */ jerry_api_acquire_string (jerry_api_string_t *string_p) /**< pointer passed to function */
{ {
return ecma_copy_or_ref_ecma_string (string_p); return ecma_copy_or_ref_ecma_string (string_p);
} /* jerry_acquire_string */ } /* jerry_api_acquire_string */
/** /**
* Release string pointer acquired through jerry_acquire_string. * Release string pointer
*
* See also:
* jerry_api_acquire_string
* jerry_api_call_function
*
*/ */
void void
jerry_release_string (jerry_string_t *string_p) /**< pointer acquired through jerry_acquire_string */ jerry_api_release_string (jerry_api_string_t *string_p) /**< pointer acquired through jerry_api_acquire_string */
{ {
ecma_deref_ecma_string (string_p); ecma_deref_ecma_string (string_p);
} /* jerry_release_string */ } /* jerry_api_release_string */
/** /**
* Acquire object pointer for usage outside of the engine * Acquire object pointer for usage outside of the engine
* from object retrieved in extension routine call from engine.
* *
* Warning: * Warning:
* acquired pointer should be released with jerry_release_object * acquired pointer should be released with jerry_api_release_object
* *
* @return pointer that may be used outside of the engine * @return pointer that may be used outside of the engine
*/ */
jerry_object_t* jerry_api_object_t*
jerry_acquire_object (jerry_object_t *object_p) /**< pointer passed to function */ jerry_api_acquire_object (jerry_api_object_t *object_p) /**< pointer passed to function */
{ {
ecma_ref_object (object_p); ecma_ref_object (object_p);
return object_p; return object_p;
} /* jerry_acquire_object */ } /* jerry_api_acquire_object */
/** /**
* Release object pointer acquired through jerry_acquire_object. * Release object pointer
*
* See also:
* jerry_api_acquire_object
* jerry_api_call_function
* jerry_api_get_object_field_value
*/ */
void void
jerry_release_object (jerry_object_t *object_p) /**< pointer acquired through jerry_acquire_object */ jerry_api_release_object (jerry_api_object_t *object_p) /**< pointer acquired through jerry_api_acquire_object */
{ {
ecma_deref_object (object_p); ecma_deref_object (object_p);
} /* jerry_release_object */ } /* jerry_api_release_object */
/** /**
* @} * Call function specified by a function object
*
* Note:
* if call was performed successfully and returned value of type string or object, then caller
* should release the string / object with corresponding jerry_api_release_string / jerry_api_release_object,
* just when the value becomes unnecessary.
*
* @return true, if call was performed successfully, i.e.:
* - arguments number equals to the function's length property;
* - no unhandled exceptions were thrown;
* - returned value type is corresponding to one of jerry_api_data_type_t (if retval_p is not NULL)
* or is 'undefined' (if retval_p is NULL);
* false - otherwise.
*/ */
bool
jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function object to call */
jerry_api_value_t *retval_p, /**< place for function's return value (if it is required)
* or NULL (if it should be 'undefined') */
const jerry_api_value_t args_p [], /**< function's call arguments
* (NULL if arguments number is zero) */
uint32_t args_count) /**< number of the arguments */
{
JERRY_ASSERT (args_count == 0
|| args_p != NULL);
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("API routine is not implemented",
function_object_p, retval_p, args_p, args_count);
} /* jerry_api_call_function */
/**
* Create an object
*
* Note:
* caller should release the object with jerry_api_release_object, just when the value becomes unnecessary.
*
* @return pointer to created object
*/
jerry_api_object_t*
jerry_api_create_object (void)
{
return ecma_op_create_object_object_noarg ();
} /* jerry_api_create_object */
/**
* Create field (named data property) in the specified object
*
* @return true, if field was created successfully, i.e. upon the call:
* - there is no field with same name in the object;
* - the object is extensible;
* false - otherwise.
*/
bool
jerry_api_add_object_field (jerry_api_object_t *object_p, /**< object to add field at */
const char *field_name_p, /**< name of the field */
const jerry_api_value_t *field_value_p, /**< value of the field */
bool is_writable) /**< flag indicating whether the created field should be writable */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("API routine is not implemented",
object_p, field_name_p, field_value_p, is_writable);
} /* jerry_api_add_object_field */
/**
* Delete field in the specified object
*
* @return true, if field was deleted successfully, i.e. upon the call:
* - there is field with specified name in the object;
* false - otherwise.
*/
bool
jerry_api_delete_object_field (jerry_api_object_t *object_p, /**< object to delete field at */
const char *field_name_p) /**< name of the field */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("API routine is not implemented",
object_p, field_name_p);
} /* jerry_api_delete_object_field */
/**
* Get value of field in the specified object
*
* Note:
* if value was retrieved successfully and it is of type string or object, then caller
* should release the string / object with corresponding jerry_api_release_string / jerry_api_release_object,
* just when the value becomes unnecessary.
*
* @return true, if field value was retrieved successfully, i.e. upon the call:
* - there is field with specified name in the object;
* - field value is not undefined nor null;
* false - otherwise.
*/
bool
jerry_api_get_object_field_value (jerry_api_object_t *object_p, /**< object */
const char *field_name_p, /**< name of the field */
jerry_api_value_t *field_value_p) /**< out: field value, if retrieved successfully */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("API routine is not implemented",
object_p, field_name_p, field_value_p);
} /* jerry_api_get_object_field_value */
/**
* Set value of field in the specified object
*
* @return true, if field value was set successfully, i.e. upon the call:
* - there is field with specified name in the object;
* - field value is writable;
* false - otherwise.
*/
bool
jerry_api_set_object_field_value (jerry_api_object_t *object_p, /**< object */
const char *field_name_p, /**< name of the field */
const jerry_api_value_t *field_value_p) /**< field value to set */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS ("API routine is not implemented",
object_p, field_name_p, field_value_p);
} /* jerry_api_set_object_field_value */
/** /**
* Jerry engine initialization * Jerry engine initialization
@@ -231,6 +359,8 @@ jerry_parse (jerry_ctx_t* ctx_p, /**< run context */
/** /**
* Run Jerry in specified run context * Run Jerry in specified run context
*
* @return completion status
*/ */
jerry_completion_code_t jerry_completion_code_t
jerry_run (jerry_ctx_t* ctx_p) /**< run context */ jerry_run (jerry_ctx_t* ctx_p) /**< run context */
@@ -243,6 +373,8 @@ jerry_run (jerry_ctx_t* ctx_p) /**< run context */
/** /**
* Simple jerry runner * Simple jerry runner
*
* @return completion status
*/ */
jerry_completion_code_t jerry_completion_code_t
jerry_run_simple (const char *script_source, /**< script source */ jerry_run_simple (const char *script_source, /**< script source */
-6
View File
@@ -84,12 +84,6 @@ extern const char *jerry_branch_name;
*/ */
typedef void (*jerry_error_callback_t) (jerry_fatal_code_t); typedef void (*jerry_error_callback_t) (jerry_fatal_code_t);
#ifdef __cplusplus
# define EXTERN_C "C"
#else /* !__cplusplus */
# define EXTERN_C
#endif /* !__cplusplus */
extern EXTERN_C void jerry_init (jerry_flag_t flags); extern EXTERN_C void jerry_init (jerry_flag_t flags);
extern EXTERN_C void jerry_cleanup (void); extern EXTERN_C void jerry_cleanup (void);
+3 -3
View File
@@ -19,7 +19,7 @@
#include "jerry.h" #include "jerry.h"
static void plugin_io_print_uint32 (uint32_t); static void plugin_io_print_uint32 (uint32_t);
static void plugin_io_print_string (jerry_string_t *string_p); static void plugin_io_print_string (jerry_api_string_t *string_p);
#include "io-extension-description.inc.h" #include "io-extension-description.inc.h"
@@ -46,11 +46,11 @@ plugin_io_print_uint32 (uint32_t num) /**< uint32 to print */
* If string is too long for the function, then nothing will be printed. * If string is too long for the function, then nothing will be printed.
*/ */
static void static void
plugin_io_print_string (jerry_string_t *string_p) /**< string to print */ plugin_io_print_string (jerry_api_string_t *string_p) /**< string to print */
{ {
char buffer [32]; char buffer [32];
ssize_t req_size = jerry_string_to_char_buffer (string_p, buffer, (ssize_t) sizeof (buffer)); ssize_t req_size = jerry_api_string_to_char_buffer (string_p, buffer, (ssize_t) sizeof (buffer));
if (req_size < 0) if (req_size < 0)
{ {