Changeset 243289 in webkit
- Timestamp:
- Mar 21, 2019, 7:36:12 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
Source/JavaScriptCore/API/glib/JSCClass.cpp (modified) (1 diff)
-
Source/JavaScriptCore/API/glib/JSCValue.cpp (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/glib/JSCClass.cpp
r243283 r243289 555 555 static GRefPtr<JSCValue> jscClassCreateConstructor(JSCClass* jscClass, const char* name, GCallback callback, gpointer userData, GDestroyNotify destroyNotify, GType returnType, Optional<Vector<GType>>&& parameters) 556 556 { 557 // If the constructor doesn't have arguments, we need to swap the fake instance and user data to ensure 558 // user data is the first parameter and fake instance ignored. 559 GRefPtr<GClosure> closure; 560 if (parameters && parameters->isEmpty() && userData) 561 closure = adoptGRef(g_cclosure_new_swap(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify)))); 562 else 563 closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify)))); 557 564 JSCClassPrivate* priv = jscClass->priv; 558 GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify))));559 565 JSC::ExecState* exec = toJS(jscContextGetJSContext(priv->context)); 560 566 JSC::VM& vm = exec->vm(); -
trunk/Source/JavaScriptCore/API/glib/JSCValue.cpp
r243283 r243289 1141 1141 static GRefPtr<JSCValue> jscValueFunctionCreate(JSCContext* context, const char* name, GCallback callback, gpointer userData, GDestroyNotify destroyNotify, GType returnType, Optional<Vector<GType>>&& parameters) 1142 1142 { 1143 GRefPtr<GClosure> closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify)))); 1143 GRefPtr<GClosure> closure; 1144 // If the function doesn't have arguments, we need to swap the fake instance and user data to ensure 1145 // user data is the first parameter and fake instance ignored. 1146 if (parameters && parameters->isEmpty() && userData) 1147 closure = adoptGRef(g_cclosure_new_swap(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify)))); 1148 else 1149 closure = adoptGRef(g_cclosure_new(callback, userData, reinterpret_cast<GClosureNotify>(reinterpret_cast<GCallback>(destroyNotify)))); 1144 1150 JSC::ExecState* exec = toJS(jscContextGetJSContext(context)); 1145 1151 JSC::VM& vm = exec->vm(); -
trunk/Source/JavaScriptCore/ChangeLog
r243286 r243289 1 2019-03-21 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GLIB] User data not correctly passed to callback of functions and constructors with no parameters 4 https://bugs.webkit.org/show_bug.cgi?id=196073 5 6 Reviewed by Michael Catanzaro. 7 8 This is because GClosure always expects a first parameter as instance. In case of functions or constructors with 9 no parameters we insert a fake instance which is just a null pointer that is ignored by the callback. But 10 if the function/constructor has user data the callback will expect one parameter for the user data. In that case 11 we can simply swap instance/user data so that the fake instance will be the second argument and user data the 12 first one. 13 14 * API/glib/JSCClass.cpp: 15 (jscClassCreateConstructor): Use g_cclosure_new_swap() if parameters is empty and user data was provided. 16 * API/glib/JSCValue.cpp: 17 (jscValueFunctionCreate): Ditto. 18 1 19 2019-03-21 Pablo Saavedra <psaavedra@igalia.com> 2 20 -
trunk/Tools/ChangeLog
r243288 r243289 1 2019-03-21 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GLIB] User data not correctly passed to callback of functions and constructors with no parameters 4 https://bugs.webkit.org/show_bug.cgi?id=196073 5 6 Reviewed by Michael Catanzaro. 7 8 Add test cases to check functions and constructors with no arguments but receiving user data. 9 10 * TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp: 11 (checkUserData): 12 (testJSCFunction): 13 (fooCreateWithUserData): 14 (testJSCClass): 15 1 16 2019-03-21 Carlos Garcia Campos <cgarcia@igalia.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp
r243283 r243289 848 848 } 849 849 850 static gboolean checkUserData(GFile* file) 851 { 852 return G_IS_FILE(file); 853 } 854 850 855 static void testJSCFunction() 851 856 { … … 1093 1098 g_assert_cmpint(jsc_value_to_int32(value.get()), ==, 0); 1094 1099 } 1100 1101 { 1102 LeakChecker checker; 1103 GRefPtr<JSCContext> context = adoptGRef(jsc_context_new()); 1104 checker.watch(context.get()); 1105 ExceptionHandler exceptionHandler(context.get()); 1106 1107 GFile* file = g_file_new_for_path("."); 1108 checker.watch(file); 1109 GRefPtr<JSCValue> function = adoptGRef(jsc_value_new_function(context.get(), "checkUserData", G_CALLBACK(checkUserData), 1110 file, g_object_unref, G_TYPE_BOOLEAN, 0, G_TYPE_NONE)); 1111 checker.watch(function.get()); 1112 jsc_context_set_value(context.get(), "checkUserData", function.get()); 1113 1114 GRefPtr<JSCValue> value = adoptGRef(jsc_context_evaluate(context.get(), "checkUserData()", -1)); 1115 checker.watch(value.get()); 1116 g_assert_true(jsc_value_is_boolean(value.get())); 1117 g_assert_true(jsc_value_to_boolean(value.get())); 1118 1119 value = adoptGRef(jsc_value_function_call(function.get(), G_TYPE_NONE)); 1120 checker.watch(value.get()); 1121 g_assert_true(jsc_value_is_boolean(value.get())); 1122 g_assert_true(jsc_value_to_boolean(value.get())); 1123 } 1095 1124 } 1096 1125 … … 1396 1425 }, f); 1397 1426 return f; 1427 } 1428 1429 static Foo* fooCreateWithUserData(GFile* file) 1430 { 1431 g_assert_true(G_IS_FILE(file)); 1432 return fooCreate(); 1398 1433 } 1399 1434 … … 1799 1834 g_assert_true(jsc_value_is_number(value.get())); 1800 1835 g_assert_cmpint(jsc_value_to_int32(value.get()), ==, 0); 1836 1837 GFile* file = g_file_new_for_path("."); 1838 checker.watch(file); 1839 GRefPtr<JSCValue> constructorUserData = adoptGRef(jsc_class_add_constructor(jscClass, "CreateWithUserData", G_CALLBACK(fooCreateWithUserData), 1840 file, g_object_unref, G_TYPE_POINTER, 0, G_TYPE_NONE)); 1841 checker.watch(constructorUserData.get()); 1842 g_assert_true(jsc_value_is_constructor(constructorUserData.get())); 1843 jsc_value_object_set_property(constructor.get(), "CreateWithUserData", constructorUserData.get()); 1844 1845 GRefPtr<JSCValue> foo5 = adoptGRef(jsc_context_evaluate(context.get(), "f5 = new Foo.CreateWithUserData();", -1)); 1846 checker.watch(foo5.get()); 1847 g_assert_true(jsc_value_is_object(foo5.get())); 1848 g_assert_true(jsc_value_object_is_instance_of(foo5.get(), jsc_class_get_name(jscClass))); 1801 1849 1802 1850 JSCClass* otherClass = jsc_context_register_class(context.get(), "Baz", nullptr, nullptr, g_free);
Note:
See TracChangeset
for help on using the changeset viewer.