Bug 261043

Summary: [GTK] Wrong free function in documentation for webkit_web_view_evaluate_javascript
Product: WebKit Reporter: Rolf Gebhardt <buggy>
Component: WebKitGTKAssignee: Michael Catanzaro <mcatanzaro>
Status: RESOLVED FIXED    
Severity: Normal CC: buggy, bugs-noreply, mcatanzaro
Priority: P2 Keywords: Gtk
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
URL: https://webkitgtk.org/reference/webkit2gtk/stable/method.WebView.evaluate_javascript.html

Description Rolf Gebhardt 2023-09-01 12:02:57 PDT
The example in the documentation for webkit_web_view_evaluate_javascript at

https://webkitgtk.org/reference/webkit2gtk/stable/method.WebView.evaluate_javascript.html

is incorrect.

The statement "webkit_javascript_result_unref(js_result);" (see code fragment below) seems to be a holdover from the example for the deprecated Function webkit_web_view_run_javascript.
Therefore, it remains unclear how to correctly deal with the JSCValue "value" returned by the function webkit_web_view_evaluate_javascript_finish.

Code fragment from the documentation:

static void
web_view_javascript_finished (GObject      *object,
                              GAsyncResult *result,
                              gpointer      user_data)
{
    JSCValue               *value;
    GError                 *error = NULL;

    value = webkit_web_view_evaluate_javascript_finish (WEBKIT_WEB_VIEW (object), result, &error);

    --- some lines of code removed ---

    webkit_javascript_result_unref (js_result);
}
Comment 1 Michael Catanzaro 2023-09-01 13:17:35 PDT
Good catch, thanks!

(In reply to Rolf from comment #0)
> Therefore, it remains unclear how to correctly deal with the JSCValue
> "value" returned by the function webkit_web_view_evaluate_javascript_finish.

It's a GObject, so use g_object_unref().
Comment 2 Michael Catanzaro 2023-09-01 13:19:36 PDT
Pull request: https://github.com/WebKit/WebKit/pull/17354
Comment 3 Rolf Gebhardt 2023-09-01 14:33:49 PDT
(In reply to Michael Catanzaro from comment #1)
> Good catch, thanks!
> 
> (In reply to Rolf from comment #0)
> > Therefore, it remains unclear how to correctly deal with the JSCValue
> > "value" returned by the function webkit_web_view_evaluate_javascript_finish.
> 
> It's a GObject, so use g_object_unref().

Thanks a lot for the hint and for fixing.

I have another small point concerning the same function:

The documentation to the first parameter "script" says: "The value is a NUL terminated UTF-8 string."

The second parameter "length" tells us: "Length of script, or -1 if script is a nul-terminated string."

I understand what is meant. But perhaps the description of "script" should reflect the two possibilities to specify the end of the string.

(Not really important, just a suggestion)
Comment 4 Michael Catanzaro 2023-09-02 06:34:47 PDT
Let's fix that too.
Comment 5 Michael Catanzaro 2023-09-02 06:38:45 PDT
Actually that's not part of the docs itself, but from gi-docgen. We should have used unsigned char * for this API to indicate that it is a string of bytes that may or may not be nul-terminated, rather than char * which indicates a nul-terminated UTF-8 string. But we cannot fix the type until the next API version.
Comment 6 EWS 2023-09-02 06:52:08 PDT
Committed 267583@main (ddb67f54d767): <https://commits.webkit.org/267583@main>

Reviewed commits have been landed. Closing PR #17354 and removing active labels.