mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Optional arguments should advance the iterator in jerryx_arg_transform_optional (#2962)
This patch fixes #2288 JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
parent
ff22634e27
commit
6c441091b4
@ -34,7 +34,7 @@ jerryx_arg_transform_optional (jerryx_arg_js_iterator_t *js_arg_iter_p, /**< ava
|
||||
|
||||
if (jerry_value_is_undefined (js_arg))
|
||||
{
|
||||
return js_arg;
|
||||
return jerryx_arg_js_iterator_pop (js_arg_iter_p);
|
||||
}
|
||||
|
||||
return func (js_arg_iter_p, c_arg_p);
|
||||
|
||||
@ -35,6 +35,10 @@ static const jerry_char_t test_source[] = TEST_STRING_LITERAL (
|
||||
"arg2 = new Number(10.5);"
|
||||
"test_validator1(arg1, arg2, arg3);"
|
||||
"test_validator1(arg1, 10.5, 'abcdef');"
|
||||
"test_validator3(arg1, arg1);"
|
||||
"test_validator3(arg1);"
|
||||
"test_validator3();"
|
||||
"test_validator3(undefined, undefined);"
|
||||
"var obj_a = new MyObjectA();"
|
||||
"var obj_b = new MyObjectB();"
|
||||
"test_validator2.call(obj_a, 5);"
|
||||
@ -86,6 +90,7 @@ static my_type_b_t my_thing_b;
|
||||
|
||||
static int validator1_count = 0;
|
||||
static int validator2_count = 0;
|
||||
static int validator3_count = 0;
|
||||
static int validator_int_count = 0;
|
||||
static int validator_prop_count = 0;
|
||||
static int validator_array_count = 0;
|
||||
@ -242,6 +247,73 @@ test_validator2_handler (const jerry_value_t func_obj_val __attribute__((unused)
|
||||
return jerry_create_undefined ();
|
||||
} /* test_validator2_handler */
|
||||
|
||||
/**
|
||||
* The handler should have following arguments:
|
||||
* arg1: Bool. It is an optional argument.
|
||||
*
|
||||
*/
|
||||
static jerry_value_t
|
||||
test_validator3_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< function object */
|
||||
const jerry_value_t this_val, /**< this value */
|
||||
const jerry_value_t args_p[], /**< arguments list */
|
||||
const jerry_length_t args_cnt) /**< arguments length */
|
||||
{
|
||||
|
||||
bool arg1 = false;
|
||||
bool arg2 = false;
|
||||
|
||||
jerryx_arg_t mapping[] =
|
||||
{
|
||||
/* ignore this */
|
||||
jerryx_arg_ignore (),
|
||||
/* 1th argument should be boolean, and it is optional */
|
||||
jerryx_arg_boolean (&arg1, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL),
|
||||
/* 2nd argument should be boolean, and it is optional */
|
||||
jerryx_arg_boolean (&arg2, JERRYX_ARG_COERCE, JERRYX_ARG_OPTIONAL),
|
||||
};
|
||||
|
||||
jerry_value_t is_ok = jerryx_arg_transform_this_and_args (this_val,
|
||||
args_p,
|
||||
args_cnt,
|
||||
mapping,
|
||||
ARRAY_SIZE (mapping));
|
||||
|
||||
if (validator3_count == 0)
|
||||
{
|
||||
TEST_ASSERT (!jerry_value_is_error (is_ok));
|
||||
TEST_ASSERT (arg1);
|
||||
TEST_ASSERT (arg2);
|
||||
}
|
||||
else if (validator3_count == 1)
|
||||
{
|
||||
TEST_ASSERT (!jerry_value_is_error (is_ok));
|
||||
TEST_ASSERT (arg1);
|
||||
/* arg2 must be unchanged */
|
||||
TEST_ASSERT (!arg2);
|
||||
}
|
||||
else if (validator3_count == 2)
|
||||
{
|
||||
TEST_ASSERT (!jerry_value_is_error (is_ok));
|
||||
/* arg1 must be unchanged */
|
||||
TEST_ASSERT (!arg1);
|
||||
/* arg2 must be unchanged */
|
||||
TEST_ASSERT (!arg2);
|
||||
}
|
||||
else if (validator3_count == 3)
|
||||
{
|
||||
TEST_ASSERT (!jerry_value_is_error (is_ok));
|
||||
/* arg1 must be unchanged */
|
||||
TEST_ASSERT (!arg1);
|
||||
/* arg2 must be unchanged */
|
||||
TEST_ASSERT (!arg2);
|
||||
}
|
||||
|
||||
jerry_release_value (is_ok);
|
||||
validator3_count++;
|
||||
|
||||
return jerry_create_undefined ();
|
||||
} /* test_validator3_handler */
|
||||
|
||||
/**
|
||||
* Calling jerryx_arg_transform_object_properties directly.
|
||||
*/
|
||||
@ -808,6 +880,7 @@ main (void)
|
||||
|
||||
register_js_function ("test_validator1", test_validator1_handler);
|
||||
register_js_function ("test_validator2", test_validator2_handler);
|
||||
register_js_function ("test_validator3", test_validator3_handler);
|
||||
register_js_function ("test_validator_int1", test_validator_int1_handler);
|
||||
register_js_function ("test_validator_int2", test_validator_int2_handler);
|
||||
register_js_function ("test_validator_int3", test_validator_int3_handler);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user