From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Using JavaScriptCore patch Date: Tue, 6 Aug 2019 18:29:27 +0200 Message-ID: <20190806162925.pnv6yg56brh67dfx@Ergus> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="fn3274ldcomvgqw2" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="86504"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180716 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 06 18:29:58 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hv2LV-000MN6-VN for ged-emacs-devel@m.gmane.org; Tue, 06 Aug 2019 18:29:58 +0200 Original-Received: from localhost ([::1]:34980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hv2LU-0007jy-TA for ged-emacs-devel@m.gmane.org; Tue, 06 Aug 2019 12:29:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46172) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hv2LC-0007js-4Y for emacs-devel@gnu.org; Tue, 06 Aug 2019 12:29:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hv2LA-0004uz-Ei for emacs-devel@gnu.org; Tue, 06 Aug 2019 12:29:38 -0400 Original-Received: from sonic305-20.consmr.mail.ir2.yahoo.com ([77.238.177.82]:39290) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hv2L9-0004qm-6n for emacs-devel@gnu.org; Tue, 06 Aug 2019 12:29:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1565108972; bh=kyMQbUwmDgnfs+gbDZOec8GYD7QHKYtgAEmbH7bsoaA=; h=Date:From:To:Subject:From:Subject; b=dUWOEVTIncS/RrlknEwSFeKqxuqbKPGupmHLHQPt+UyxApotsZxeR4Dv8IniSDVLf9HvIyO3yBWFrVL7yGmAIljSCeozD9GKfUMAdALrmS4tN5ILXl22ZPe5tCLU0sfwnBvF17RZCH74O+CF+jMKhVgnmtZ3/tXnPwzMaCtgK/mXwWgNVA1sbI8VlGNhtdNlFGlPbcM1fx+q0XvVekRNNkH/46Rh8RoAGl86H+EczwrFL4gtozih6bde3FD0ByoKO6IM+oAZR/simzshRwOiRLj9CFxIbV3kT68YZEybN7p91cFzk1vHrGP4mJLJofjJ/J3n8HHg5jPTDx0suZMlAg== X-YMail-OSG: KPBYvF4VM1mPMpB4vhyXY93BE.jEXnve4x4cbds_2ZhurEnkZYUliIhbzFocDcg .Q4Gb_21xI8qc8vntAXFekayr75QdrRVjcuhCIAaEPiCbT..4Z9__CR__zesJ4wOimAQTcT1zT4l cCUoZS_gRoBfZ0qg1OFUDR3qkiqZaYu7Xp1EvqLmnFdkEDTsN6F28QZr5s8.eE7vPp3h2mSgFKxp DOg739TTwudtsm6tk48ZA.uMcdYCZn5JrskHwTynS0fc7Kx64_.88M6LA4iTRVOhOZ8pLD16FV0N m_ts2B0aTfIk4s82Zp7ZN9X5KjIda8g18Ujiejv86eEG.aDMgOflZHK0iOvC64iMJxt9SbuzbB1W PlpLeAMqY3t7Z.OnhECvr5YaLjW7jiAng75V5XPkMx84PbGPYoH38TOG6vO7En704YwC0f4HVIMh dbyFY3VVmZaspsvvjsOL.R7KbvFT6sNUjNFSld0fCMhkaNJjM5hNqJoZ2Ex0jzD8en3yda2nfZ9t 9xwEsjHZ66iKSva4rGfmgbZKIzgU9bwiwjB1KzgFCqPD4Z39dMfgtgQDYagBjNWqMwZKzfbx2eKc AI9bUFlSz3OYj_CTCoCZ.KM_3dpZ6vL3m2n4pOaUCAzcUmys6UaLkR6F.CGloEC6G4WcqUD.6A1v 1Ys4SHRHdDbv7RDuA9cR5WKG.tHXuUzLQD7IG.NjEuhT63KQah0iLrPIyLnp7TgWybJ5HbpkiE4V 4n4vhkFObsk4otY60CwMkIw28p3QaNumzRVkPQEQtwoDPW4d.ksWlE5yRkAVVEyaWw4Vr_L6D9FT jc24J9DieNwmxdM8fM641JtK8S4abVVRg_TkskgpjB Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Tue, 6 Aug 2019 16:29:32 +0000 Original-Received: by smtp401.mail.ir2.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 75d69f263c061f8bdf2161d40dc8a650; Tue, 06 Aug 2019 16:29:30 +0000 (UTC) Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 77.238.177.82 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:239211 Archived-At: --fn3274ldcomvgqw2 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Hi: I just see that there was a TODO in src/xwidget.c to delete a warning about deprecations in two functions and use JavaScriptCore API. I don't know if anyone is working on that already, so I just propose the next patch (attachment). If there is any specialist that want to correct/improve/comment this; it is very welcome. At least it is working for me. Best, Ergus --fn3274ldcomvgqw2 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="JavaScriptCore.patch" diff --git a/src/xwidget.c b/src/xwidget.c index 121510ebac..ecb3793629 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -31,14 +31,6 @@ along with GNU Emacs. If not, see . */ #include #include -/* Suppress GCC deprecation warnings starting in WebKitGTK+ 2.21.1 for - webkit_javascript_result_get_global_context and - webkit_javascript_result_get_value (Bug#33679). - FIXME: Use the JavaScriptCore GLib API instead, and remove this hack. */ -#if WEBKIT_CHECK_VERSION (2, 21, 1) && GNUC_PREREQ (4, 2, 0) -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - static struct xwidget * allocate_xwidget (void) { @@ -284,95 +276,70 @@ webkit_view_load_changed_cb (WebKitWebView *webkitwebview, /* Recursively convert a JavaScript value to a Lisp value. */ static Lisp_Object -webkit_js_to_lisp (JSContextRef context, JSValueRef value) +webkit_js_to_lisp (JSCValue *value) { - switch (JSValueGetType (context, value)) + if (jsc_value_is_string (value)) { - case kJSTypeString: - { - JSStringRef js_str_value; - gchar *str_value; - gsize str_length; - - js_str_value = JSValueToStringCopy (context, value, NULL); - str_length = JSStringGetMaximumUTF8CStringSize (js_str_value); - str_value = (gchar *)g_malloc (str_length); - JSStringGetUTF8CString (js_str_value, str_value, str_length); - JSStringRelease (js_str_value); - return build_string (str_value); - } - case kJSTypeBoolean: - return (JSValueToBoolean (context, value)) ? Qt : Qnil; - case kJSTypeNumber: - return make_fixnum (JSValueToNumber (context, value, NULL)); - case kJSTypeObject: - { - if (JSValueIsArray (context, value)) - { - JSStringRef pname = JSStringCreateWithUTF8CString("length"); - JSValueRef len = JSObjectGetProperty (context, (JSObjectRef) value, - pname, NULL); - double dlen = JSValueToNumber (context, len, NULL); - JSStringRelease(pname); - - Lisp_Object obj; - if (! (0 <= dlen && dlen < PTRDIFF_MAX + 1.0)) - memory_full (SIZE_MAX); - ptrdiff_t n = dlen; - struct Lisp_Vector *p = allocate_vector (n); - - for (ptrdiff_t i = 0; i < n; ++i) - { - p->contents[i] = - webkit_js_to_lisp (context, - JSObjectGetPropertyAtIndex (context, - (JSObjectRef) value, - i, NULL)); - } - XSETVECTOR (obj, p); - return obj; - } - else - { - JSPropertyNameArrayRef properties = - JSObjectCopyPropertyNames (context, (JSObjectRef) value); - - size_t n = JSPropertyNameArrayGetCount (properties); - Lisp_Object obj; - - /* TODO: can we use a regular list here? */ - if (PTRDIFF_MAX < n) - memory_full (n); - struct Lisp_Vector *p = allocate_vector (n); - - for (ptrdiff_t i = 0; i < n; ++i) - { - JSStringRef name = JSPropertyNameArrayGetNameAtIndex (properties, i); - JSValueRef property = JSObjectGetProperty (context, - (JSObjectRef) value, - name, NULL); - gchar *str_name; - gsize str_length; - str_length = JSStringGetMaximumUTF8CStringSize (name); - str_name = (gchar *)g_malloc (str_length); - JSStringGetUTF8CString (name, str_name, str_length); - JSStringRelease (name); - - p->contents[i] = - Fcons (build_string (str_name), - webkit_js_to_lisp (context, property)); - } - - JSPropertyNameArrayRelease (properties); - XSETVECTOR (obj, p); - return obj; - } - } - case kJSTypeUndefined: - case kJSTypeNull: - default: - return Qnil; + gchar *str_value = jsc_value_to_string (value); + Lisp_Object ret = build_string (str_value); + g_free (str_value); + + return ret; + } + else if (jsc_value_is_boolean (value)) + { + return (jsc_value_to_boolean (value)) ? Qt : Qnil; + } + else if (jsc_value_is_number (value)) + { + return make_fixnum (jsc_value_to_int32 (value)); + } + else if (jsc_value_is_array (value)) + { + JSCValue *len = jsc_value_object_get_property (value, "length"); + const gint32 dlen = jsc_value_to_int32 (len); + + Lisp_Object obj; + if (! (0 <= dlen && dlen < PTRDIFF_MAX + 1.0)) + memory_full (SIZE_MAX); + + ptrdiff_t n = dlen; + struct Lisp_Vector *p = allocate_vector (n); + + for (ptrdiff_t i = 0; i < n; ++i) + { + p->contents[i] = + webkit_js_to_lisp (jsc_value_object_get_property_at_index (value, i)); + } + XSETVECTOR (obj, p); + return obj; + } + else if (jsc_value_is_object (value)) + { + char **properties_names = jsc_value_object_enumerate_properties (value); + guint n = g_strv_length (properties_names); + + Lisp_Object obj; + if (PTRDIFF_MAX < n) + memory_full (n); + struct Lisp_Vector *p = allocate_vector (n); + + for (ptrdiff_t i = 0; i < n; ++i) + { + const char *name = properties_names[i]; + JSCValue *property = jsc_value_object_get_property (value, name); + + p->contents[i] = + Fcons (build_string (name), webkit_js_to_lisp (property)); + } + + g_strfreev (properties_names); + + XSETVECTOR (obj, p); + return obj; } + + return Qnil; } static void @@ -380,41 +347,39 @@ webkit_javascript_finished_cb (GObject *webview, GAsyncResult *result, gpointer arg) { - WebKitJavascriptResult *js_result; - JSValueRef value; - JSGlobalContextRef context; - GError *error = NULL; - struct xwidget *xw = g_object_get_data (G_OBJECT (webview), - XG_XWIDGET); - ptrdiff_t script_idx = (intptr_t) arg; - Lisp_Object script_callback = AREF (xw->script_callbacks, script_idx); - ASET (xw->script_callbacks, script_idx, Qnil); - if (!NILP (script_callback)) - xfree (xmint_pointer (XCAR (script_callback))); - - js_result = webkit_web_view_run_javascript_finish - (WEBKIT_WEB_VIEW (webview), result, &error); - - if (!js_result) - { - g_warning ("Error running javascript: %s", error->message); - g_error_free (error); - return; - } + GError *error = NULL; + struct xwidget *xw = g_object_get_data (G_OBJECT (webview), XG_XWIDGET); - if (!NILP (script_callback) && !NILP (XCDR (script_callback))) - { - context = webkit_javascript_result_get_global_context (js_result); - value = webkit_javascript_result_get_value (js_result); - Lisp_Object lisp_value = webkit_js_to_lisp (context, value); - - /* Register an xwidget event here, which then runs the callback. - This ensures that the callback runs in sync with the Emacs - event loop. */ - store_xwidget_js_callback_event (xw, XCDR (script_callback), lisp_value); - } + ptrdiff_t script_idx = (intptr_t) arg; + Lisp_Object script_callback = AREF (xw->script_callbacks, script_idx); + ASET (xw->script_callbacks, script_idx, Qnil); + if (!NILP (script_callback)) + xfree (xmint_pointer (XCAR (script_callback))); + + WebKitJavascriptResult *js_result = + webkit_web_view_run_javascript_finish + (WEBKIT_WEB_VIEW (webview), result, &error); + + if (!js_result) + { + g_warning ("Error running javascript: %s", error->message); + g_error_free (error); + return; + } + + if (!NILP (script_callback) && !NILP (XCDR (script_callback))) + { + JSCValue *value = webkit_javascript_result_get_js_value (js_result); + + Lisp_Object lisp_value = webkit_js_to_lisp (value); + + /* Register an xwidget event here, which then runs the callback. + This ensures that the callback runs in sync with the Emacs + event loop. */ + store_xwidget_js_callback_event (xw, XCDR (script_callback), lisp_value); + } - webkit_javascript_result_unref (js_result); + webkit_javascript_result_unref (js_result); } --fn3274ldcomvgqw2--