Pass function arguments through ecma-collections.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -113,7 +113,7 @@ ecma_builtin_array_prototype_object_to_string (ecma_value_t this_arg) /**< this
|
||||
/* 4. */
|
||||
ecma_object_t *join_func_obj_p = ecma_get_object_from_value (join_value);
|
||||
|
||||
return_value = ecma_op_function_call (join_func_obj_p, this_arg, NULL, 0);
|
||||
return_value = ecma_op_function_call (join_func_obj_p, this_arg, NULL);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (join_value);
|
||||
@@ -1013,10 +1013,10 @@ ecma_builtin_array_prototype_object_sort_compare_helper (ecma_value_t j, /**< le
|
||||
ecma_value_t compare_args[] = {j, k};
|
||||
|
||||
ECMA_TRY_CATCH (call_value,
|
||||
ecma_op_function_call (comparefn_obj_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
compare_args,
|
||||
2),
|
||||
ecma_op_function_call_array_args (comparefn_obj_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
compare_args,
|
||||
2),
|
||||
ret_value);
|
||||
|
||||
if (!ecma_is_value_number (call_value))
|
||||
@@ -2069,7 +2069,7 @@ ecma_builtin_array_prototype_object_every (ecma_value_t this_arg, /**< this argu
|
||||
|
||||
ecma_value_t call_args[] = { get_value, current_index, obj_this };
|
||||
/* 7.c.ii */
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call (func_object_p, arg2, call_args, 3), ret_value);
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call_array_args (func_object_p, arg2, call_args, 3), ret_value);
|
||||
|
||||
/* 7.c.iii, ecma_op_to_boolean always returns a simple value, so no need to free. */
|
||||
if (ecma_is_completion_value_normal_false (ecma_op_to_boolean (call_value)))
|
||||
@@ -2170,7 +2170,7 @@ ecma_builtin_array_prototype_object_some (ecma_value_t this_arg, /**< this argum
|
||||
|
||||
ecma_value_t call_args[] = { get_value, current_index, obj_this };
|
||||
/* 7.c.ii */
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call (func_object_p, arg2, call_args, 3), ret_value);
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call_array_args (func_object_p, arg2, call_args, 3), ret_value);
|
||||
|
||||
/* 7.c.iii, ecma_op_to_boolean always returns a simple value, so no need to free. */
|
||||
if (ecma_is_completion_value_normal_true (ecma_op_to_boolean (call_value)))
|
||||
@@ -2270,7 +2270,7 @@ ecma_builtin_array_prototype_object_for_each (ecma_value_t this_arg, /**< this a
|
||||
|
||||
/* 7.c.ii */
|
||||
ecma_value_t call_args[] = {current_value, current_index, obj_this};
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call (func_object_p, arg2, call_args, 3), ret_value);
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call_array_args (func_object_p, arg2, call_args, 3), ret_value);
|
||||
|
||||
ECMA_FINALIZE (call_value);
|
||||
ECMA_FINALIZE (current_value);
|
||||
@@ -2367,7 +2367,7 @@ ecma_builtin_array_prototype_object_map (ecma_value_t this_arg, /**< this argume
|
||||
current_index = ecma_make_number_value (num_p);
|
||||
ecma_value_t call_args[] = {current_value, current_index, obj_this};
|
||||
|
||||
ECMA_TRY_CATCH (mapped_value, ecma_op_function_call (func_object_p, arg2, call_args, 3), ret_value);
|
||||
ECMA_TRY_CATCH (mapped_value, ecma_op_function_call_array_args (func_object_p, arg2, call_args, 3), ret_value);
|
||||
|
||||
/* 8.c.iii */
|
||||
/* This will always be a simple value since 'is_throw' is false, so no need to free. */
|
||||
@@ -2485,7 +2485,7 @@ ecma_builtin_array_prototype_object_filter (ecma_value_t this_arg, /**< this arg
|
||||
|
||||
ecma_value_t call_args[] = { get_value, current_index, obj_this };
|
||||
/* 9.c.ii */
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call (func_object_p, arg2, call_args, 3), ret_value);
|
||||
ECMA_TRY_CATCH (call_value, ecma_op_function_call_array_args (func_object_p, arg2, call_args, 3), ret_value);
|
||||
|
||||
/* 9.c.iii, ecma_op_to_boolean always returns a simple value, so no need to free. */
|
||||
if (ecma_is_completion_value_normal_true (ecma_op_to_boolean (call_value)))
|
||||
@@ -2643,10 +2643,10 @@ ecma_builtin_array_prototype_object_reduce (ecma_value_t this_arg, /**< this arg
|
||||
ecma_value_t call_args[] = {accumulator, current_value, current_index, obj_this};
|
||||
|
||||
ECMA_TRY_CATCH (call_value,
|
||||
ecma_op_function_call (func_object_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
call_args,
|
||||
4),
|
||||
ecma_op_function_call_array_args (func_object_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
call_args,
|
||||
4),
|
||||
ret_value);
|
||||
|
||||
ecma_free_value (accumulator, true);
|
||||
@@ -2787,10 +2787,10 @@ ecma_builtin_array_prototype_object_reduce_right (ecma_value_t this_arg, /**< th
|
||||
ecma_value_t call_args[] = {accumulator, current_value, current_index, obj_this};
|
||||
|
||||
ECMA_TRY_CATCH (call_value,
|
||||
ecma_op_function_call (func_object_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
call_args,
|
||||
4),
|
||||
ecma_op_function_call_array_args (func_object_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
call_args,
|
||||
4),
|
||||
ret_value);
|
||||
|
||||
ecma_free_value (accumulator, true);
|
||||
|
||||
@@ -1233,7 +1233,7 @@ ecma_builtin_date_prototype_to_json (ecma_value_t this_arg, /**< this argument *
|
||||
else
|
||||
{
|
||||
ecma_object_t *to_iso_obj_p = ecma_get_object_from_value (to_iso);
|
||||
ret_value = ecma_op_function_call (to_iso_obj_p, this_arg, NULL, 0);
|
||||
ret_value = ecma_op_function_call (to_iso_obj_p, this_arg, NULL);
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (to_iso);
|
||||
|
||||
@@ -97,10 +97,7 @@ ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this a
|
||||
/* 2. */
|
||||
if (ecma_is_value_null (arg2) || ecma_is_value_undefined (arg2))
|
||||
{
|
||||
ret_value = ecma_op_function_call (func_obj_p,
|
||||
arg1,
|
||||
NULL,
|
||||
0);
|
||||
ret_value = ecma_op_function_call (func_obj_p, arg1, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,10 +124,9 @@ ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this a
|
||||
const uint32_t length = ecma_number_to_uint32 (length_number);
|
||||
|
||||
/* 6. */
|
||||
MEM_DEFINE_LOCAL_ARRAY (arg_list, length, ecma_value_t);
|
||||
ecma_collection_header_t *arg_collection_p = ecma_new_values_collection (NULL, 0, true);
|
||||
|
||||
/* 7. */
|
||||
uint32_t appended_num = 0;
|
||||
for (uint32_t index = 0; index < length && ecma_is_completion_value_empty (ret_value); index++)
|
||||
{
|
||||
ecma_string_t *curr_idx_str_p = ecma_new_ecma_string_from_uint32 (index);
|
||||
@@ -139,29 +135,22 @@ ecma_builtin_function_prototype_object_apply (ecma_value_t this_arg, /**< this a
|
||||
ecma_op_object_get (obj_p, curr_idx_str_p),
|
||||
ret_value);
|
||||
|
||||
arg_list[index] = ecma_copy_value (get_value, true);
|
||||
appended_num++;
|
||||
ecma_append_to_values_collection (arg_collection_p, get_value, true);
|
||||
|
||||
ECMA_FINALIZE (get_value);
|
||||
ecma_deref_ecma_string (curr_idx_str_p);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (appended_num == length || !ecma_is_completion_value_empty (ret_value));
|
||||
JERRY_ASSERT (arg_collection_p->unit_number == length || !ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
if (ecma_is_completion_value_empty (ret_value))
|
||||
{
|
||||
ret_value = ecma_op_function_call (func_obj_p,
|
||||
arg1,
|
||||
arg_list,
|
||||
(ecma_length_t) appended_num);
|
||||
arg_collection_p);
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < appended_num; index++)
|
||||
{
|
||||
ecma_free_value (arg_list[index], true);
|
||||
}
|
||||
|
||||
MEM_FINALIZE_LOCAL_ARRAY (arg_list);
|
||||
ecma_free_values_collection (arg_collection_p, true);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (length_number);
|
||||
ECMA_FINALIZE (length_value);
|
||||
@@ -199,15 +188,14 @@ ecma_builtin_function_prototype_object_call (ecma_value_t this_arg, /**< this ar
|
||||
{
|
||||
return ecma_op_function_call (func_obj_p,
|
||||
ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED),
|
||||
NULL,
|
||||
0);
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ecma_op_function_call (func_obj_p,
|
||||
arguments_list_p[0],
|
||||
(arguments_number == 1u) ? NULL : (arguments_list_p + 1),
|
||||
(ecma_length_t) (arguments_number - 1u));
|
||||
return ecma_op_function_call_array_args (func_obj_p,
|
||||
arguments_list_p[0],
|
||||
(arguments_number == 1u) ? NULL : (arguments_list_p + 1),
|
||||
(ecma_length_t) (arguments_number - 1u));
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_function_prototype_object_call */
|
||||
|
||||
@@ -158,8 +158,7 @@ ecma_builtin_helper_get_to_locale_string_at_index (ecma_object_t *obj_p, /** < t
|
||||
ECMA_TRY_CATCH (call_value,
|
||||
ecma_op_function_call (locale_func_obj_p,
|
||||
ecma_make_object_value (index_obj_p),
|
||||
NULL,
|
||||
0),
|
||||
NULL),
|
||||
ret_value);
|
||||
ret_value = ecma_op_to_string (call_value);
|
||||
ECMA_FINALIZE (call_value);
|
||||
|
||||
@@ -793,10 +793,10 @@ ecma_builtin_json_walk (ecma_object_t *reviver_p, /**< reviver function */
|
||||
/*
|
||||
* The completion value can be anything including exceptions.
|
||||
*/
|
||||
ret_value = ecma_op_function_call (reviver_p,
|
||||
ecma_make_object_value (holder_p),
|
||||
arguments_list,
|
||||
2);
|
||||
ret_value = ecma_op_function_call_array_args (reviver_p,
|
||||
ecma_make_object_value (holder_p),
|
||||
arguments_list,
|
||||
2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1353,7 +1353,7 @@ ecma_builtin_json_str (ecma_string_t *key_p, /**< property key*/
|
||||
ecma_object_t *toJSON_obj_p = ecma_get_object_from_value (toJSON);
|
||||
|
||||
ECMA_TRY_CATCH (func_ret_val,
|
||||
ecma_op_function_call (toJSON_obj_p, my_val, call_args, 1),
|
||||
ecma_op_function_call_array_args (toJSON_obj_p, my_val, call_args, 1),
|
||||
ret_value);
|
||||
|
||||
ecma_free_value (my_val, true);
|
||||
@@ -1375,7 +1375,7 @@ ecma_builtin_json_str (ecma_string_t *key_p, /**< property key*/
|
||||
ecma_value_t call_args[] = { key_value, my_val };
|
||||
|
||||
ECMA_TRY_CATCH (func_ret_val,
|
||||
ecma_op_function_call (context_p->replacer_function_p, holder_value, call_args, 2),
|
||||
ecma_op_function_call_array_args (context_p->replacer_function_p, holder_value, call_args, 2),
|
||||
ret_value);
|
||||
|
||||
ecma_free_value (my_val, true);
|
||||
|
||||
@@ -110,7 +110,7 @@ ecma_builtin_object_prototype_object_to_locale_string (ecma_value_t this_arg) /*
|
||||
{
|
||||
/* 4. */
|
||||
ecma_object_t *to_string_func_obj_p = ecma_get_object_from_value (to_string_val);
|
||||
return_value = ecma_op_function_call (to_string_func_obj_p, this_arg, NULL, 0);
|
||||
return_value = ecma_op_function_call (to_string_func_obj_p, this_arg, NULL);
|
||||
}
|
||||
ECMA_FINALIZE (to_string_val);
|
||||
|
||||
|
||||
@@ -1045,10 +1045,10 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se
|
||||
arguments_list[length + 1] = ecma_copy_value (context_p->input_string, true);
|
||||
|
||||
ECMA_TRY_CATCH (result_value,
|
||||
ecma_op_function_call (context_p->replace_function_p,
|
||||
context_p->regexp_or_search_string,
|
||||
arguments_list,
|
||||
length + 2),
|
||||
ecma_op_function_call_array_args (context_p->replace_function_p,
|
||||
context_p->regexp_or_search_string,
|
||||
arguments_list,
|
||||
length + 2),
|
||||
ret_value);
|
||||
|
||||
ECMA_TRY_CATCH (to_string_value,
|
||||
|
||||
@@ -392,11 +392,25 @@ ecma_builtin_make_function_object_for_routine (ecma_builtin_id_t builtin_id, /**
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
ecma_value_t this_arg_value, /**< 'this' argument value */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< length of the arguments list */
|
||||
ecma_collection_header_t* arg_collection_p) /**< arguments collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
const ecma_length_t arguments_list_len = arg_collection_p != NULL ? arg_collection_p->unit_number : 0;
|
||||
MEM_DEFINE_LOCAL_ARRAY (arguments_list_p, arguments_list_len, ecma_value_t);
|
||||
|
||||
ecma_collection_iterator_t arg_collection_iter;
|
||||
ecma_collection_iterator_init (&arg_collection_iter,
|
||||
arg_collection_p);
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
ecma_collection_iterator_next (&arg_collection_iter);
|
||||
arg_index++)
|
||||
{
|
||||
arguments_list_p[arg_index] = *arg_collection_iter.current_value_p;
|
||||
}
|
||||
|
||||
if (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION)
|
||||
{
|
||||
@@ -417,11 +431,11 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
ecma_builtin_id_t built_in_id = (ecma_builtin_id_t) built_in_id_field;
|
||||
uint16_t routine_id = (uint16_t) routine_id_field;
|
||||
|
||||
return ecma_builtin_dispatch_routine (built_in_id,
|
||||
routine_id,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
ret_value = ecma_builtin_dispatch_routine (built_in_id,
|
||||
routine_id,
|
||||
this_arg_value,
|
||||
arguments_list_p,
|
||||
arguments_list_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -445,13 +459,10 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
{ \
|
||||
if (object_type == ECMA_OBJECT_TYPE_FUNCTION) \
|
||||
{ \
|
||||
return ecma_builtin_ ## lowercase_name ## _dispatch_call (arguments_list_p, \
|
||||
arguments_list_len); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
JERRY_UNREACHABLE (); \
|
||||
ret_value = ecma_builtin_ ## lowercase_name ## _dispatch_call (arguments_list_p, \
|
||||
arguments_list_len); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
@@ -471,7 +482,11 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
MEM_FINALIZE_LOCAL_ARRAY (arguments_list_p);
|
||||
|
||||
JERRY_ASSERT (!ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_dispatch_call */
|
||||
|
||||
/**
|
||||
@@ -481,13 +496,26 @@ ecma_builtin_dispatch_call (ecma_object_t *obj_p, /**< built-in object */
|
||||
*/
|
||||
ecma_completion_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
|
||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len) /**< length of the arguments list */
|
||||
ecma_collection_header_t* arg_collection_p) /**< arguments collection */
|
||||
{
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
|
||||
JERRY_ASSERT (ecma_get_object_is_builtin (obj_p));
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
|
||||
const ecma_length_t arguments_list_len = arg_collection_p != NULL ? arg_collection_p->unit_number : 0;
|
||||
MEM_DEFINE_LOCAL_ARRAY (arguments_list_p, arguments_list_len, ecma_value_t);
|
||||
|
||||
ecma_collection_iterator_t arg_collection_iter;
|
||||
ecma_collection_iterator_init (&arg_collection_iter,
|
||||
arg_collection_p);
|
||||
|
||||
for (ecma_length_t arg_index = 0;
|
||||
ecma_collection_iterator_next (&arg_collection_iter);
|
||||
arg_index++)
|
||||
{
|
||||
arguments_list_p[arg_index] = *arg_collection_iter.current_value_p;
|
||||
}
|
||||
|
||||
ecma_property_t *built_in_id_prop_p = ecma_get_internal_property (obj_p,
|
||||
ECMA_INTERNAL_PROPERTY_BUILT_IN_ID);
|
||||
@@ -495,6 +523,7 @@ ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
|
||||
|
||||
JERRY_ASSERT (ecma_builtin_is (obj_p, builtin_id));
|
||||
|
||||
JERRY_ASSERT (ecma_get_object_type (obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
|
||||
switch (builtin_id)
|
||||
{
|
||||
#define BUILTIN(builtin_id, \
|
||||
@@ -507,13 +536,10 @@ ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
|
||||
{ \
|
||||
if (object_type == ECMA_OBJECT_TYPE_FUNCTION) \
|
||||
{ \
|
||||
return ecma_builtin_ ## lowercase_name ## _dispatch_construct (arguments_list_p, \
|
||||
arguments_list_len); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
JERRY_UNREACHABLE (); \
|
||||
ret_value = ecma_builtin_ ## lowercase_name ## _dispatch_construct (arguments_list_p, \
|
||||
arguments_list_len); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
#include "ecma-builtins.inc.h"
|
||||
|
||||
@@ -532,7 +558,11 @@ ecma_builtin_dispatch_construct (ecma_object_t *obj_p, /**< built-in object */
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
MEM_FINALIZE_LOCAL_ARRAY (arguments_list_p);
|
||||
|
||||
JERRY_ASSERT (!ecma_is_completion_value_empty (ret_value));
|
||||
|
||||
return ret_value;
|
||||
} /* ecma_builtin_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,12 +41,10 @@ extern void ecma_finalize_builtins (void);
|
||||
extern ecma_completion_value_t
|
||||
ecma_builtin_dispatch_call (ecma_object_t *obj_p,
|
||||
ecma_value_t this_arg,
|
||||
const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len);
|
||||
ecma_collection_header_t *arg_collection_p);
|
||||
extern ecma_completion_value_t
|
||||
ecma_builtin_dispatch_construct (ecma_object_t *obj_p,
|
||||
const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len);
|
||||
ecma_collection_header_t *arg_collection_p);
|
||||
extern ecma_property_t*
|
||||
ecma_builtin_try_to_instantiate_property (ecma_object_t *object_p,
|
||||
ecma_string_t *string_p);
|
||||
|
||||
Reference in New Issue
Block a user