From 2f392f33c9366218c12f283b349b8000edf89e0a Mon Sep 17 00:00:00 2001 From: Peter Hofmann Date: Sun, 31 Mar 2019 09:23:25 +0200 Subject: No longer use WebKit's deprecated JavaScript API --- BUGS | 5 ----- CHANGES | 4 ++++ browser.c | 31 +++++++++++++++++-------------- 3 files changed, 21 insertions(+), 19 deletions(-) delete mode 100644 BUGS diff --git a/BUGS b/BUGS deleted file mode 100644 index 1bf801c..0000000 --- a/BUGS +++ /dev/null @@ -1,5 +0,0 @@ -Deprecated JS functions in WebKit -================================= - -'webkit_javascript_result_get_global_context' and -'webkit_javascript_result_get_value' are deprecated. diff --git a/CHANGES b/CHANGES index 07e1fc6..06f7080 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Release history for lariza +next + [Fixed] + - We no longer use WebKit's deprecated JavaScript API. + v18.07 2018-07-29 [Added] - The input bar now shows an indicator for web feeds. diff --git a/browser.c b/browser.c index ed14575..6d022e5 100644 --- a/browser.c +++ b/browser.c @@ -678,17 +678,18 @@ grab_feeds_finished(GObject *object, GAsyncResult *result, gpointer data) { struct Client *c = (struct Client *)data; WebKitJavascriptResult *js_result; - JSValueRef value; - JSGlobalContextRef context; + JSCValue *value; + JSCException *exception; GError *err = NULL; - JSStringRef js_str_value; - gsize str_length; + gchar *str_value; g_free(c->feed_html); c->feed_html = NULL; /* This was taken almost verbatim from the example in WebKit's - * documentation. */ + * documentation: + * + * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript-finish */ js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &err); @@ -699,16 +700,18 @@ grab_feeds_finished(GObject *object, GAsyncResult *result, gpointer data) return; } - context = webkit_javascript_result_get_global_context(js_result); - value = webkit_javascript_result_get_value(js_result); - - if (JSValueIsString(context, value)) + value = webkit_javascript_result_get_js_value(js_result); + if (jsc_value_is_string(value)) { - js_str_value = JSValueToStringCopy(context, value, NULL); - str_length = JSStringGetMaximumUTF8CStringSize(js_str_value); - c->feed_html = (gchar *)g_malloc(str_length); - JSStringGetUTF8CString(js_str_value, c->feed_html, str_length); - JSStringRelease(js_str_value); + str_value = jsc_value_to_string(value); + exception = jsc_context_get_exception(jsc_value_get_context(value)); + if (exception != NULL) + { + fprintf(stderr, __NAME__": Error running javascript: %s\n", + jsc_exception_get_message(exception)); + } + else + c->feed_html = str_value; gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location), GTK_ENTRY_ICON_PRIMARY, -- cgit v1.2.3