@@ -35,6 +35,8 @@ static const jerry_char_t test_source[] = TEST_STRING_LITERAL (
35
35
"arg2 = new Number(10.5);"
36
36
"test_validator1(arg1, arg2, arg3);"
37
37
"test_validator1(arg1, 10.5, 'abcdef');"
38
+ "test_validator3(arg1);"
39
+ "test_validator3();"
38
40
"var obj_a = new MyObjectA();"
39
41
"var obj_b = new MyObjectB();"
40
42
"test_validator2.call(obj_a, 5);"
@@ -86,6 +88,7 @@ static my_type_b_t my_thing_b;
86
88
87
89
static int validator1_count = 0 ;
88
90
static int validator2_count = 0 ;
91
+ static int validator3_count = 0 ;
89
92
static int validator_int_count = 0 ;
90
93
static int validator_prop_count = 0 ;
91
94
static int validator_array_count = 0 ;
@@ -242,6 +245,52 @@ test_validator2_handler (const jerry_value_t func_obj_val __attribute__((unused)
242
245
return jerry_create_undefined ();
243
246
} /* test_validator2_handler */
244
247
248
+ /**
249
+ * The handler should have following arguments:
250
+ * arg1: Bool. It is an optional argument.
251
+ *
252
+ */
253
+ static jerry_value_t
254
+ test_validator3_handler (const jerry_value_t func_obj_val __attribute__((unused )), /**< function object */
255
+ const jerry_value_t this_val , /**< this value */
256
+ const jerry_value_t args_p [], /**< arguments list */
257
+ const jerry_length_t args_cnt ) /**< arguments length */
258
+ {
259
+
260
+ bool arg1 = false;
261
+
262
+ jerryx_arg_t mapping [] =
263
+ {
264
+ /* ignore this */
265
+ jerryx_arg_ignore (),
266
+ /* 1th argument should be boolean, and it is optional */
267
+ jerryx_arg_boolean (& arg1 , JERRYX_ARG_COERCE , JERRYX_ARG_OPTIONAL ),
268
+ };
269
+
270
+ jerry_value_t is_ok = jerryx_arg_transform_this_and_args (this_val ,
271
+ args_p ,
272
+ args_cnt ,
273
+ mapping ,
274
+ ARRAY_SIZE (mapping ));
275
+
276
+ if (validator3_count == 0 )
277
+ {
278
+ TEST_ASSERT (!jerry_value_is_error (is_ok ));
279
+ TEST_ASSERT (arg1 );
280
+ }
281
+ else if (validator3_count == 1 )
282
+ {
283
+ TEST_ASSERT (!jerry_value_is_error (is_ok ));
284
+ /* arg1 must be unchanged */
285
+ TEST_ASSERT (!arg1 );
286
+ }
287
+
288
+ jerry_release_value (is_ok );
289
+ validator3_count ++ ;
290
+
291
+ return jerry_create_undefined ();
292
+ } /* test_validator3_handler */
293
+
245
294
/**
246
295
* Calling jerryx_arg_transform_object_properties directly.
247
296
*/
@@ -808,6 +857,7 @@ main (void)
808
857
809
858
register_js_function ("test_validator1" , test_validator1_handler );
810
859
register_js_function ("test_validator2" , test_validator2_handler );
860
+ register_js_function ("test_validator3" , test_validator3_handler );
811
861
register_js_function ("test_validator_int1" , test_validator_int1_handler );
812
862
register_js_function ("test_validator_int2" , test_validator_int2_handler );
813
863
register_js_function ("test_validator_int3" , test_validator_int3_handler );
0 commit comments