Ordinarily you would need to use Vala's async functions to do this, I believe like so:
var result = yield webview.run_javascript(...);
This is equivalent to the C function webkit_web_view_run_javascript_finish()
.
Unfortunately you can't take the next step shown at that link in Vala, as you need to use the JavaScriptCore API to get at the return value and that API isn't available in Vala.
There are a couple of dirty tricks that you can resort to in this case. One such trick is setting the window title at the end of your Javascript script, and watching for notifications on the webview's title
property in Vala.
However, you may be better off writing a small bit of code in C that you compile into your Vala application.