Title: [286054] trunk/Tools
Revision
286054
Author
carlo...@webkit.org
Date
2021-11-19 01:52:50 -0800 (Fri, 19 Nov 2021)

Log Message

Unreviewed. [GLIB] Add new test case to /jsc/class

Add a test case to check using JSC_TYPE_VALUE for a JSCClass property.

* TestWebKitAPI/Tests/_javascript_Core/glib/TestJSC.cpp:
(setFooValue):
(getFooValue):
(testJSCClass):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (286053 => 286054)


--- trunk/Tools/ChangeLog	2021-11-19 09:38:27 UTC (rev 286053)
+++ trunk/Tools/ChangeLog	2021-11-19 09:52:50 UTC (rev 286054)
@@ -1,3 +1,14 @@
+2021-11-19  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        Unreviewed. [GLIB] Add new test case to /jsc/class
+
+        Add a test case to check using JSC_TYPE_VALUE for a JSCClass property.
+
+        * TestWebKitAPI/Tests/_javascript_Core/glib/TestJSC.cpp:
+        (setFooValue):
+        (getFooValue):
+        (testJSCClass):
+
 2021-11-19  Arcady Goldmints-Orlov  <agoldmi...@igalia.com>
 
         REGRESSION(r285859) [GTK][WPE] a number of accessibility/* tests crash on GTK and WPE

Modified: trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/glib/TestJSC.cpp (286053 => 286054)


--- trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/glib/TestJSC.cpp	2021-11-19 09:38:27 UTC (rev 286053)
+++ trunk/Tools/TestWebKitAPI/Tests/_javascript_Core/glib/TestJSC.cpp	2021-11-19 09:52:50 UTC (rev 286054)
@@ -1641,6 +1641,25 @@
     return foo->foo;
 }
 
+static void setFooValue(Foo* foo, JSCValue* value)
+{
+    if (jsc_value_is_undefined(value))
+        foo->foo = std::numeric_limits<int>::min();
+    else if (jsc_value_is_null(value))
+        foo->foo = std::numeric_limits<int>::max();
+    else
+        foo->foo = jsc_value_to_int32(value);
+}
+
+static JSCValue* getFooValue(Foo* foo)
+{
+    if (foo->foo == std::numeric_limits<int>::min())
+        return jsc_value_new_undefined(jsc_context_get_current());
+    if (foo->foo == std::numeric_limits<int>::max())
+        return jsc_value_new_null(jsc_context_get_current());
+    return jsc_value_new_number(jsc_context_get_current(), foo->foo);
+}
+
 static void setSibling(Foo* foo, Foo* sibling)
 {
     foo->sibling = sibling;
@@ -2729,6 +2748,78 @@
         g_assert_true(jsc_value_is_boolean(result.get()));
         g_assert_true(jsc_value_to_boolean(result.get()));
     }
+
+    {
+        LeakChecker checker;
+        GRefPtr<JSCContext> context = adoptGRef(jsc_context_new());
+        checker.watch(context.get());
+        ExceptionHandler exceptionHandler(context.get());
+
+        JSCClass* jscClass = jsc_context_register_class(context.get(), "Foo", nullptr, &fooVTable, reinterpret_cast<GDestroyNotify>(fooFree));
+        checker.watch(jscClass);
+        g_object_set_data(G_OBJECT(jscClass), "leak-checker", &checker);
+
+        GRefPtr<JSCValue> constructor = adoptGRef(jsc_class_add_constructor(jscClass, nullptr, G_CALLBACK(fooCreate), nullptr, nullptr, G_TYPE_POINTER, 0, G_TYPE_NONE));
+        checker.watch(constructor.get());
+        g_assert_true(jsc_value_is_constructor(constructor.get()));
+        jsc_context_set_value(context.get(), jsc_class_get_name(jscClass), constructor.get());
+        jsc_class_add_property(jscClass, "foo", JSC_TYPE_VALUE, G_CALLBACK(getFooValue), G_CALLBACK(setFooValue), nullptr, nullptr);
+
+        GRefPtr<JSCValue> foo = adoptGRef(jsc_context_evaluate(context.get(), "f = new Foo();", -1));
+        checker.watch(foo.get());
+        g_assert_true(jsc_value_is_object(foo.get()));
+        g_assert_true(jsc_value_object_has_property(foo.get(), "foo"));
+
+        GRefPtr<JSCValue> result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(result.get());
+        g_assert_true(jsc_value_is_number(result.get()));
+        g_assert_cmpuint(jsc_value_to_int32(result.get()), ==, 0);
+
+        GRefPtr<JSCValue> value = adoptGRef(jsc_value_object_get_property(foo.get(), "foo"));
+        checker.watch(value.get());
+        g_assert_true(value.get() == result.get());
+
+        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo = 52", -1));
+        checker.watch(result.get());
+        value = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(value.get());
+        g_assert_true(jsc_value_is_number(value.get()));
+        g_assert_cmpint(jsc_value_to_int32(value.get()), ==, 52);
+
+        value = adoptGRef(jsc_value_new_number(context.get(), 25));
+        checker.watch(value.get());
+        jsc_value_object_set_property(foo.get(), "foo", value.get());
+        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(result.get());
+        g_assert_true(jsc_value_is_number(result.get()));
+        g_assert_cmpint(jsc_value_to_int32(result.get()), ==, 25);
+
+        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo = undefined", -1));
+        checker.watch(result.get());
+        value = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(value.get());
+        g_assert_true(jsc_value_is_undefined(value.get()));
+
+        value = adoptGRef(jsc_value_new_undefined(context.get()));
+        checker.watch(value.get());
+        jsc_value_object_set_property(foo.get(), "foo", value.get());
+        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(result.get());
+        g_assert_true(jsc_value_is_undefined(result.get()));
+
+        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo = null", -1));
+        checker.watch(result.get());
+        value = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(value.get());
+        g_assert_true(jsc_value_is_null(value.get()));
+
+        value = adoptGRef(jsc_value_new_null(context.get()));
+        checker.watch(value.get());
+        jsc_value_object_set_property(foo.get(), "foo", value.get());
+        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
+        checker.watch(result.get());
+        g_assert_true(jsc_value_is_null(result.get()));
+    }
 }
 
 typedef struct {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to