[Webkit-unassigned] [Bug 195574] [GLib] Returning G_TYPE_OBJECT from a method does not work

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Mar 21 00:42:52 PDT 2019


https://bugs.webkit.org/show_bug.cgi?id=195574

--- Comment #12 from Carlos Garcia Campos <cgarcia at igalia.com> ---
(In reply to Michael Catanzaro from comment #11)
> Comment on attachment 364658 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=364658&action=review
> 
> > Source/JavaScriptCore/API/glib/JSCClass.cpp:735
> > + * Note that the value returned by @callback must be fully transferred. In case of boxed types, you could use
> 
> fully transferred -> transfer full

Ok.

> could -> should?

You could, not necessarily should. It depends on the boxed type, if it's refcounted, you could use the actual boxed type and return a ref, because the same pointer will be returned in the end. If the boxed type is not refcounted and you don't want to make a copy, you should use G_TYPE_POINTER instead to ensure the same pointer is returned. If you really want to make a copy, then you should use JSC_TYPE_VALUE and use jsc_value_new_object() passing the copy as the instance parameter. I'll clarify it better.

> (Ditto for copypaste below)
> 
> > Source/JavaScriptCore/API/glib/JSCClass.cpp:738
> > + * with jsc_value_new_object() that receives the copy as instance parameter.
> 
> as an instance

No, it's *the* instance parameter in:

JSCValue* jsc_value_new_object(JSCContext* context, gpointer instance, JSCClass* jscClass)

> (Ditto for copypaste below)
> 
> > Tools/TestWebKitAPI/Tests/JavaScriptCore/glib/TestJSC.cpp:1628
> > +static GString* getGStringCopyWillRaise(GString* str)
> > +{
> > +    return static_cast<GString*>(g_boxed_copy(G_TYPE_GSTRING, str));
> > +}
> 
> I don't understand, why does this cause a JS exception?

Because we are returning a pointer to a new boxed type that doesn't have a JSValue associated. Functions returning object, boxed or pointer should return a pointer of a previously wrapped object, either with jsc_value_new_object() or jsc_value_constructor_call() or new Foo called by JavaScript. That's why the documention says that if you really want to make a copy of the boxed type you should use JSC_TYPE_VALUE and return the value created with jsc_value_new_object(). That's what the other test case does.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20190321/9803a217/attachment-0001.html>


More information about the webkit-unassigned mailing list