Bug 283160
Summary: | webkit_web_view_run_javascript() incompatible with webkit_web_view_call_async_javascript_function() | ||
---|---|---|---|
Product: | WebKit | Reporter: | Milan Crha <mcrha> |
Component: | WebKitGTK | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | Normal | CC: | bugs-noreply, cgarcia |
Priority: | P2 | ||
Version: | Other | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Milan Crha
According to the documentation the `webkit_web_view_call_async_javascript_function()` is meant to replace `webkit_web_view_run_javascript()` since 2.40, but these two functions are incompatible, which means any attempt to replace one with the other means also replacing all/most-of the scripts, which is not great.
The problem: I've a script:
document.getElementById('cnt').innerText
which I want to execute form a C code. The webkit_web_view_run_javascript() returns a value, for which `jsc_value_is_string()` returns `1`, while the webkit_web_view_call_async_javascript_function() returns for the same script a value, for which jsc_value_is_undefined() returns `1`.
To make the webkit_web_view_call_async_javascript_function() work I need to change the script to:
return document.getElementById('cnt').innerText;
but then, when I run this new script with the webkit_web_view_run_javascript() I get an exception failure:
none-local://:1: SyntaxError: Return statements are only valid inside functions. (WebKitJavascriptError, 699)
I thought it's a 1:1 replacement, just hiding the WebKitJavascriptResult type, but if it does completely different things, then it's a completely different story. I know the function is called "call_async_javascript_function" (with the *function* at the end, but still, JavaScript is not (only) about functions.
Also, I usually provide temporary JavaScript code in the call to the `webkit_web_view_run_javascript()`, which can define a new (temporary) function, contains several statements, simply does more than just a simple call to a previously defined static/global/whatever function.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Carlos Garcia Campos
Then documentation is wrong, webkit_web_view_evaluate_javascript() is the replacement for webkit_web_view_run_javascript(). webkit_web_view_call_async_javascript_function() is to run async functions that can return a promise.
Milan Crha
Hmm, the documentation is correct, it's me who've been wrong. I'll sign to an elementary school class where they teach people to read... :-/
Milan Crha
You are right. I'm sorry for the noise.