@@ -35,6 +35,10 @@ static const jerry_char_t test_source[] = TEST_STRING_LITERAL (
3535 "arg2 = new Number(10.5);"
3636 "test_validator1(arg1, arg2, arg3);"
3737 "test_validator1(arg1, 10.5, 'abcdef');"
38+ "test_validator3(arg1, arg1);"
39+ "test_validator3(arg1);"
40+ "test_validator3();"
41+ "test_validator3(undefined, undefined);"
3842 "var obj_a = new MyObjectA();"
3943 "var obj_b = new MyObjectB();"
4044 "test_validator2.call(obj_a, 5);"
@@ -86,6 +90,7 @@ static my_type_b_t my_thing_b;
8690
8791static int validator1_count = 0 ;
8892static int validator2_count = 0 ;
93+ static int validator3_count = 0 ;
8994static int validator_int_count = 0 ;
9095static int validator_prop_count = 0 ;
9196static int validator_array_count = 0 ;
@@ -242,6 +247,73 @@ test_validator2_handler (const jerry_value_t func_obj_val __attribute__((unused)
242247 return jerry_create_undefined ();
243248} /* test_validator2_handler */
244249
250+ /**
251+ * The handler should have following arguments:
252+ * arg1: Bool. It is an optional argument.
253+ *
254+ */
255+ static jerry_value_t
256+ test_validator3_handler (const jerry_value_t func_obj_val __attribute__((unused )), /**< function object */
257+ const jerry_value_t this_val , /**< this value */
258+ const jerry_value_t args_p [], /**< arguments list */
259+ const jerry_length_t args_cnt ) /**< arguments length */
260+ {
261+
262+ bool arg1 = false;
263+ bool arg2 = false;
264+
265+ jerryx_arg_t mapping [] =
266+ {
267+ /* ignore this */
268+ jerryx_arg_ignore (),
269+ /* 1th argument should be boolean, and it is optional */
270+ jerryx_arg_boolean (& arg1 , JERRYX_ARG_COERCE , JERRYX_ARG_OPTIONAL ),
271+ /* 2nd argument should be boolean, and it is optional */
272+ jerryx_arg_boolean (& arg2 , JERRYX_ARG_COERCE , JERRYX_ARG_OPTIONAL ),
273+ };
274+
275+ jerry_value_t is_ok = jerryx_arg_transform_this_and_args (this_val ,
276+ args_p ,
277+ args_cnt ,
278+ mapping ,
279+ ARRAY_SIZE (mapping ));
280+
281+ if (validator3_count == 0 )
282+ {
283+ TEST_ASSERT (!jerry_value_is_error (is_ok ));
284+ TEST_ASSERT (arg1 );
285+ TEST_ASSERT (arg2 );
286+ }
287+ else if (validator3_count == 1 )
288+ {
289+ TEST_ASSERT (!jerry_value_is_error (is_ok ));
290+ TEST_ASSERT (arg1 );
291+ /* arg2 must be unchanged */
292+ TEST_ASSERT (!arg2 );
293+ }
294+ else if (validator3_count == 2 )
295+ {
296+ TEST_ASSERT (!jerry_value_is_error (is_ok ));
297+ /* arg1 must be unchanged */
298+ TEST_ASSERT (!arg1 );
299+ /* arg2 must be unchanged */
300+ TEST_ASSERT (!arg2 );
301+ }
302+ else if (validator3_count == 3 )
303+ {
304+ TEST_ASSERT (!jerry_value_is_error (is_ok ));
305+ /* arg1 must be unchanged */
306+ TEST_ASSERT (!arg1 );
307+ /* arg2 must be unchanged */
308+ TEST_ASSERT (!arg2 );
309+ }
310+
311+ jerry_release_value (is_ok );
312+ validator3_count ++ ;
313+
314+ return jerry_create_undefined ();
315+ } /* test_validator3_handler */
316+
245317/**
246318 * Calling jerryx_arg_transform_object_properties directly.
247319 */
@@ -808,6 +880,7 @@ main (void)
808880
809881 register_js_function ("test_validator1" , test_validator1_handler );
810882 register_js_function ("test_validator2" , test_validator2_handler );
883+ register_js_function ("test_validator3" , test_validator3_handler );
811884 register_js_function ("test_validator_int1" , test_validator_int1_handler );
812885 register_js_function ("test_validator_int2" , test_validator_int2_handler );
813886 register_js_function ("test_validator_int3" , test_validator_int3_handler );
0 commit comments