Adding Jerry api for calling function with specific this binding.

This commit is contained in:
Ilyong Cho
2015-03-31 21:01:12 +09:00
parent ef2265ee41
commit 3c2009d331
3 changed files with 120 additions and 7 deletions
+32 -2
View File
@@ -133,6 +133,8 @@ static void
jerry_api_convert_api_value_to_ecma_value (ecma_value_t *out_value_p, /**< out: ecma-value */
const jerry_api_value_t* api_value_p) /**< value in Jerry API format */
{
*out_value_p = 0;
switch (api_value_p->type)
{
case JERRY_API_DATA_TYPE_UNDEFINED:
@@ -341,6 +343,20 @@ 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 sepcfied object is a function object.
* false - otherwise.
*/
bool
jerry_api_is_function(const jerry_api_object_t* object_p)
{
JERRY_ASSERT (object_p != NULL);
return ecma_get_object_type (object_p) == ECMA_OBJECT_TYPE_FUNCTION;
}
/**
* Create field (named data property) in the specified object
*
@@ -515,6 +531,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 +553,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 = 0;
if (this_arg_p == NULL)
{
this_arg_val = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
}
else
{
ecma_ref_object(this_arg_p);
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);
@@ -557,6 +586,7 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
is_successful = false;
}
ecma_free_value (this_arg_val, true);
ecma_free_completion_value (call_completion);
for (uint32_t i = 0; i < args_count; i++)
@@ -567,7 +597,7 @@ jerry_api_call_function (jerry_api_object_t *function_object_p, /**< function ob
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
return is_successful;
} /* jerry_api_call_function */
} /* jerry_api_call_funition */
/**
* Get global object