Jerry API development.

Details:
  - support of this binding in function calls;
  - jerry_api_is_function and jerry_api_is_constructor interfaces.
This commit is contained in:
Ruben Ayrapetyan
2015-04-02 13:18:59 +03:00
3 changed files with 136 additions and 7 deletions
+6
View File
@@ -102,6 +102,11 @@ jerry_api_string_t* jerry_api_create_string (const char *v);
extern EXTERN_C
jerry_api_object_t* jerry_api_create_object (void);
extern EXTERN_C
bool jerry_api_is_function (const jerry_api_object_t *object_p);
extern EXTERN_C
bool jerry_api_is_constructor (const jerry_api_object_t *object_p);
extern EXTERN_C
bool jerry_api_add_object_field (jerry_api_object_t *object_p,
const char *field_name_p,
@@ -121,6 +126,7 @@ bool jerry_api_set_object_field_value (jerry_api_object_t *object_p,
extern EXTERN_C
bool jerry_api_call_function (jerry_api_object_t *function_object_p,
jerry_api_object_t *this_arg_p,
jerry_api_value_t *retval_p,
const jerry_api_value_t args_p [],
uint16_t args_count);
+45 -1
View File
@@ -341,6 +341,37 @@ jerry_api_create_object (void)
return ecma_op_create_object_object_noarg ();
} /* jerry_api_create_object */
/**
* Check if the specified object is a function object.
*
* @return true - if the specified object is a function object,
* false - otherwise.
*/
bool
jerry_api_is_function (const jerry_api_object_t* object_p) /**< an object */
{
JERRY_ASSERT (object_p != NULL);
return (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION
|| ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION);
} /* jerry_api_is_function */
/**
* Check if the specified object is a constructor function object.
*
* @return true - if the specified object is a function object that implements [[Construct]],
* false - otherwise.
*/
bool
jerry_api_is_constructor (const jerry_api_object_t* object_p) /**< an object */
{
JERRY_ASSERT (object_p != NULL);
return (ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
} /* jerry_api_is_constructor */
/**
* Create field (named data property) in the specified object
*
@@ -515,6 +546,8 @@ jerry_api_set_object_field_value (jerry_api_object_t *object_p, /**< object */
*/
bool
jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function object to call */
jerry_api_object_t *this_arg_p, /**< this arg for this binding
* or NULL (set this binding to the global object) */
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
@@ -535,8 +568,19 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
ecma_completion_value_t call_completion;
ecma_value_t this_arg_val;
if (this_arg_p == NULL)
{
this_arg_val = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
this_arg_val = ecma_make_object_value (this_arg_p);
}
call_completion = ecma_op_function_call (function_object_p,
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
this_arg_val,
arg_values,
args_count);