⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286054 in webkit


Ignore:
Timestamp:
Nov 19, 2021, 1:52:50 AM (5 years ago)
Author:
Carlos Garcia Campos
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/JavaScriptCore/glib/TestJSC.cpp:

(setFooValue):
(getFooValue):
(testJSCClass):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r286052 r286054  
     12021-11-19  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Unreviewed. [GLIB] Add new test case to /jsc/class
     4
     5        Add a test case to check using JSC_TYPE_VALUE for a JSCClass property.
     6
     7        * TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp:
     8        (setFooValue):
     9        (getFooValue):
     10        (testJSCClass):
     11
    1122021-11-19  Arcady Goldmints-Orlov  <agoldmints@igalia.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp

    r285988 r286054  
    16421642}
    16431643
     1644static void setFooValue(Foo* foo, JSCValue* value)
     1645{
     1646    if (jsc_value_is_undefined(value))
     1647        foo->foo = std::numeric_limits<int>::min();
     1648    else if (jsc_value_is_null(value))
     1649        foo->foo = std::numeric_limits<int>::max();
     1650    else
     1651        foo->foo = jsc_value_to_int32(value);
     1652}
     1653
     1654static JSCValue* getFooValue(Foo* foo)
     1655{
     1656    if (foo->foo == std::numeric_limits<int>::min())
     1657        return jsc_value_new_undefined(jsc_context_get_current());
     1658    if (foo->foo == std::numeric_limits<int>::max())
     1659        return jsc_value_new_null(jsc_context_get_current());
     1660    return jsc_value_new_number(jsc_context_get_current(), foo->foo);
     1661}
     1662
    16441663static void setSibling(Foo* foo, Foo* sibling)
    16451664{
     
    27292748        g_assert_true(jsc_value_is_boolean(result.get()));
    27302749        g_assert_true(jsc_value_to_boolean(result.get()));
     2750    }
     2751
     2752    {
     2753        LeakChecker checker;
     2754        GRefPtr<JSCContext> context = adoptGRef(jsc_context_new());
     2755        checker.watch(context.get());
     2756        ExceptionHandler exceptionHandler(context.get());
     2757
     2758        JSCClass* jscClass = jsc_context_register_class(context.get(), "Foo", nullptr, &fooVTable, reinterpret_cast<GDestroyNotify>(fooFree));
     2759        checker.watch(jscClass);
     2760        g_object_set_data(G_OBJECT(jscClass), "leak-checker", &checker);
     2761
     2762        GRefPtr<JSCValue> constructor = adoptGRef(jsc_class_add_constructor(jscClass, nullptr, G_CALLBACK(fooCreate), nullptr, nullptr, G_TYPE_POINTER, 0, G_TYPE_NONE));
     2763        checker.watch(constructor.get());
     2764        g_assert_true(jsc_value_is_constructor(constructor.get()));
     2765        jsc_context_set_value(context.get(), jsc_class_get_name(jscClass), constructor.get());
     2766        jsc_class_add_property(jscClass, "foo", JSC_TYPE_VALUE, G_CALLBACK(getFooValue), G_CALLBACK(setFooValue), nullptr, nullptr);
     2767
     2768        GRefPtr<JSCValue> foo = adoptGRef(jsc_context_evaluate(context.get(), "f = new Foo();", -1));
     2769        checker.watch(foo.get());
     2770        g_assert_true(jsc_value_is_object(foo.get()));
     2771        g_assert_true(jsc_value_object_has_property(foo.get(), "foo"));
     2772
     2773        GRefPtr<JSCValue> result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2774        checker.watch(result.get());
     2775        g_assert_true(jsc_value_is_number(result.get()));
     2776        g_assert_cmpuint(jsc_value_to_int32(result.get()), ==, 0);
     2777
     2778        GRefPtr<JSCValue> value = adoptGRef(jsc_value_object_get_property(foo.get(), "foo"));
     2779        checker.watch(value.get());
     2780        g_assert_true(value.get() == result.get());
     2781
     2782        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo = 52", -1));
     2783        checker.watch(result.get());
     2784        value = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2785        checker.watch(value.get());
     2786        g_assert_true(jsc_value_is_number(value.get()));
     2787        g_assert_cmpint(jsc_value_to_int32(value.get()), ==, 52);
     2788
     2789        value = adoptGRef(jsc_value_new_number(context.get(), 25));
     2790        checker.watch(value.get());
     2791        jsc_value_object_set_property(foo.get(), "foo", value.get());
     2792        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2793        checker.watch(result.get());
     2794        g_assert_true(jsc_value_is_number(result.get()));
     2795        g_assert_cmpint(jsc_value_to_int32(result.get()), ==, 25);
     2796
     2797        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo = undefined", -1));
     2798        checker.watch(result.get());
     2799        value = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2800        checker.watch(value.get());
     2801        g_assert_true(jsc_value_is_undefined(value.get()));
     2802
     2803        value = adoptGRef(jsc_value_new_undefined(context.get()));
     2804        checker.watch(value.get());
     2805        jsc_value_object_set_property(foo.get(), "foo", value.get());
     2806        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2807        checker.watch(result.get());
     2808        g_assert_true(jsc_value_is_undefined(result.get()));
     2809
     2810        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo = null", -1));
     2811        checker.watch(result.get());
     2812        value = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2813        checker.watch(value.get());
     2814        g_assert_true(jsc_value_is_null(value.get()));
     2815
     2816        value = adoptGRef(jsc_value_new_null(context.get()));
     2817        checker.watch(value.get());
     2818        jsc_value_object_set_property(foo.get(), "foo", value.get());
     2819        result = adoptGRef(jsc_context_evaluate(context.get(), "f.foo", -1));
     2820        checker.watch(result.get());
     2821        g_assert_true(jsc_value_is_null(result.get()));
    27312822    }
    27322823}
Note: See TracChangeset for help on using the changeset viewer.