@@ -494,6 +494,20 @@ static void testJSCTypes()
494494 g_assert_true (jsc_value_is_number (arrayLength.get ()));
495495 g_assert_cmpint (jsc_value_to_int32 (arrayLength.get ()), ==, gArray ->len );
496496
497+ const char * strv[] = { " one" , " two" , " three" , nullptr };
498+ array = adoptGRef (jsc_value_new_array_from_strv (context.get (), strv));
499+ checker.watch (array.get ());
500+ g_assert_true (jsc_value_is_array (array.get ()));
501+ g_assert_true (jsc_value_is_object (array.get ()));
502+ g_assert_true (jsc_value_to_boolean (array.get ()) == TRUE );
503+ g_assert_cmpint (jsc_value_to_int32 (array.get ()), ==, 0 );
504+ valueString.reset (jsc_value_to_string (array.get ()));
505+ g_assert_cmpstr (valueString.get (), ==, " one,two,three" );
506+ arrayLength = adoptGRef (jsc_value_object_get_property (array.get (), " length" ));
507+ checker.watch (arrayLength.get ());
508+ g_assert_true (jsc_value_is_number (arrayLength.get ()));
509+ g_assert_cmpint (jsc_value_to_int32 (arrayLength.get ()), ==, 3 );
510+
497511 value = adoptGRef (jsc_value_new_object (context.get (), nullptr , nullptr ));
498512 checker.watch (value.get ());
499513 g_assert_true (jsc_value_is_object (value.get ()));
@@ -562,6 +576,11 @@ static int sumFunction(GPtrArray* array)
562576 return retval;
563577}
564578
579+ static char * joinFunction (const char * const * strv, const char * sep)
580+ {
581+ return g_strjoinv (sep, const_cast <char **>(strv));
582+ }
583+
565584static void testJSCFunction ()
566585{
567586 {
@@ -744,6 +763,48 @@ static void testJSCFunction()
744763 g_assert_true (jsc_value_is_number (value.get ()));
745764 g_assert_cmpint (jsc_value_to_int32 (value.get ()), ==, 9 );
746765 }
766+
767+ {
768+ LeakChecker checker;
769+ GRefPtr<JSCContext> context = adoptGRef (jsc_context_new ());
770+ checker.watch (context.get ());
771+ ExceptionHandler exceptionHandler (context.get ());
772+
773+ GRefPtr<JSCValue> function = adoptGRef (jsc_context_evaluate (context.get (),
774+ " joinFunction = function(array, sep) {\n "
775+ " var result = '';\n "
776+ " for (var i in array) {\n "
777+ " result += array[i];\n "
778+ " if (i != array.length - 1) { result += sep; }\n "
779+ " }\n "
780+ " return result;\n "
781+ " }" , -1 ));
782+ checker.watch (function.get ());
783+ g_assert_true (jsc_value_is_object (function.get ()));
784+
785+ const char * strv[] = { " one" , " two" , " three" , nullptr };
786+ GRefPtr<JSCValue> value = adoptGRef (jsc_value_function_call (function.get (), G_TYPE_STRV , strv, G_TYPE_STRING , " " , G_TYPE_NONE ));
787+ checker.watch (value.get ());
788+ g_assert_true (jsc_value_is_string (value.get ()));
789+ GUniquePtr<char > valueString (jsc_value_to_string (value.get ()));
790+ g_assert_cmpstr (valueString.get (), ==, " one two three" );
791+
792+ function = adoptGRef (jsc_value_new_function (context.get (), " joinFunction2" , G_CALLBACK (joinFunction), nullptr , nullptr , G_TYPE_STRING , 2 , G_TYPE_STRV , G_TYPE_STRING ));
793+ checker.watch (function.get ());
794+ jsc_context_set_value (context.get (), " joinFunction2" , function.get ());
795+ value = adoptGRef (jsc_context_evaluate (context.get (), " joinFunction2(['one','two','three'], ' ')" , -1 ));
796+ checker.watch (value.get ());
797+ g_assert_true (jsc_value_is_string (value.get ()));
798+ GUniquePtr<char > valueString2 (jsc_value_to_string (value.get ()));
799+ g_assert_cmpstr (valueString2.get (), ==, valueString.get ());
800+
801+ bool didThrow = false ;
802+ g_assert_throw_begin (exceptionHandler, didThrow);
803+ value = adoptGRef (jsc_context_evaluate (context.get (), " joinFunction2(['one',2,'three'], ' ')" , -1 ));
804+ checker.watch (value.get ());
805+ g_assert_true (jsc_value_is_undefined (value.get ()));
806+ g_assert_did_throw (exceptionHandler, didThrow);
807+ }
747808}
748809
749810static void testJSCObject ()
0 commit comments