[geary/wip/jsc-migration] Remove Util.Webkit namespace and functions



commit 2a0de1ce41e52eb0f9153e2b55078def0f7e27ad
Author: Michael Gratton <mike vee net>
Date:   Sun Jul 21 10:46:42 2019 +1000

    Remove Util.Webkit namespace and functions
    
    After the JSC migration they were all a bunch of simple inline
    one-liners, so were just making the code more complex than it needed to
    be.

 po/POTFILES.in                                     |   1 -
 src/client/components/client-web-view.vala         |  20 ++-
 src/client/composer/composer-web-view.vala         |  10 +-
 .../conversation-viewer/conversation-web-view.vala |  15 +-
 src/client/meson.build                             |   1 -
 src/client/util/util-webkit.vala                   |  72 --------
 test/js/composer-page-state-test.vala              | 189 ++++++++++++++-------
 test/js/conversation-page-state-test.vala          |  15 +-
 8 files changed, 167 insertions(+), 156 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5e396773..edec28f5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -98,7 +98,6 @@ src/client/util/util-gtk.vala
 src/client/util/util-international.vala
 src/client/util/util-js.vala
 src/client/util/util-migrate.vala
-src/client/util/util-webkit.vala
 src/client/web-process/web-process-extension.vala
 src/console/main.vala
 src/engine/api/geary.vala
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index aa938292..7c71db58 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -392,7 +392,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
      * Returns the view's content as an HTML string.
      */
     public async string? get_html() throws Error {
-        return Util.WebKit.to_string(
+        return Util.JS.to_string(
             yield call(Util.JS.callable("geary.getHtml"), null)
         );
     }
@@ -491,10 +491,13 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
     /**
      * Invokes a {@link Util.JS.Callable} on this web view.
      */
-    protected async WebKit.JavascriptResult call(Util.JS.Callable target,
-                                                 Cancellable? cancellable)
-    throws Error {
-        return yield run_javascript(target.to_string(), cancellable);
+    protected async JSC.Value call(Util.JS.Callable target,
+                                   GLib.Cancellable? cancellable)
+        throws GLib.Error {
+        WebKit.JavascriptResult result = yield run_javascript(
+            target.to_string(), cancellable
+        );
+        return result.get_js_value();
     }
 
     /**
@@ -617,7 +620,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
     private void on_preferred_height_changed(WebKit.JavascriptResult result) {
         double height = this.webkit_reported_height;
         try {
-            height = Util.WebKit.to_double(result);
+            height = Util.JS.to_double(result.get_js_value());
         } catch (Util.JS.Error err) {
             debug("Could not get preferred height: %s", err.message);
         }
@@ -630,7 +633,8 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
 
     private void on_command_stack_changed(WebKit.JavascriptResult result) {
         try {
-            string[] values = Util.WebKit.to_string(result).split(",");
+            string[] values =
+                Util.JS.to_string(result.get_js_value()).split(",");
             command_stack_changed(values[0] == "true", values[1] == "true");
         } catch (Util.JS.Error err) {
             debug("Could not get command stack state: %s", err.message);
@@ -652,7 +656,7 @@ public abstract class ClientWebView : WebKit.WebView, Geary.BaseInterface {
 
     private void on_selection_changed(WebKit.JavascriptResult result) {
         try {
-            bool has_selection = Util.WebKit.to_bool(result);
+            bool has_selection = Util.JS.to_bool(result.get_js_value());
             // Avoid firing multiple notifies if the value hasn't
             // changed
             if (this.has_selection != has_selection) {
diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala
index e57902d8..0f230f7c 100644
--- a/src/client/composer/composer-web-view.vala
+++ b/src/client/composer/composer-web-view.vala
@@ -218,7 +218,7 @@ public class ComposerWebView : ClientWebView {
      * subsequent calls.
      */
     public async string save_selection() throws Error {
-        return Util.WebKit.to_string(
+        return Util.JS.to_string(
             yield call(Util.JS.callable("geary.saveSelection"), null)
         );
     }
@@ -400,7 +400,7 @@ public class ComposerWebView : ClientWebView {
     public async bool contains_attachment_keywords(string keyword_spec,
                                                    string subject) {
         try {
-            return Util.WebKit.to_bool(
+            return Util.JS.to_bool(
                 yield call(
                     Util.JS.callable("geary.containsAttachmentKeyword")
                     .string(keyword_spec)
@@ -430,7 +430,7 @@ public class ComposerWebView : ClientWebView {
         const int MAX_BREAKABLE_LEN = 72; // F=F recommended line limit
         const int MAX_UNBREAKABLE_LEN = 998; // SMTP line limit
 
-        string body_text = Util.WebKit.to_string(
+        string body_text = Util.JS.to_string(
             yield call(Util.JS.callable("geary.getText"), null)
         );
         string[] lines = body_text.split("\n");
@@ -506,7 +506,9 @@ public class ComposerWebView : ClientWebView {
 
     private void on_cursor_context_changed(WebKit.JavascriptResult result) {
         try {
-            cursor_context_changed(new EditContext(Util.WebKit.to_string(result)));
+            cursor_context_changed(
+                new EditContext(Util.JS.to_string(result.get_js_value()))
+            );
         } catch (Util.JS.Error err) {
             debug("Could not get text cursor style: %s", err.message);
         }
diff --git a/src/client/conversation-viewer/conversation-web-view.vala 
b/src/client/conversation-viewer/conversation-web-view.vala
index 4a972634..52f296ef 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -72,20 +72,20 @@ public class ConversationWebView : ClientWebView {
      * Returns the current selection, for prefill as find text.
      */
     public async string? get_selection_for_find() throws Error{
-        WebKit.JavascriptResult result = yield call(
+        JSC.Value result = yield call(
             Util.JS.callable("geary.getSelectionForFind"), null
         );
-        return Util.WebKit.to_string(result);
+        return Util.JS.to_string(result);
     }
 
     /**
      * Returns the current selection, for quoting in a message.
      */
     public async string? get_selection_for_quoting() throws Error {
-        WebKit.JavascriptResult result = yield call(
+        JSC.Value result = yield call(
             Util.JS.callable("geary.getSelectionForQuoting"), null
         );
-        return Util.WebKit.to_string(result);
+        return Util.JS.to_string(result);
     }
 
     /**
@@ -93,11 +93,10 @@ public class ConversationWebView : ClientWebView {
      */
     public async int? get_anchor_target_y(string anchor_body)
         throws GLib.Error {
-        WebKit.JavascriptResult result = yield call(
-            Util.JS.callable("geary.getAnchorTargetY")
-            .string(anchor_body), null
+        JSC.Value result = yield call(
+            Util.JS.callable("geary.getAnchorTargetY").string(anchor_body), null
         );
-        return (int) Util.WebKit.to_int32(result);
+        return (int) Util.JS.to_int32(result);
     }
 
     /**
diff --git a/src/client/meson.build b/src/client/meson.build
index 47cc8df6..d9008968 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -106,7 +106,6 @@ geary_client_vala_sources = files(
   'util/util-international.vala',
   'util/util-js.vala',
   'util/util-migrate.vala',
-  'util/util-webkit.vala',
 )
 
 geary_client_sources = [
diff --git a/test/js/composer-page-state-test.vala b/test/js/composer-page-state-test.vala
index adbfccae..8c1fcf08 100644
--- a/test/js/composer-page-state-test.vala
+++ b/test/js/composer-page-state-test.vala
@@ -38,8 +38,11 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
         load_body_fixture(html);
 
         try {
-            assert(Util.WebKit.to_string(run_javascript(@"new 
EditContext(document.getElementById('test')).encode()"))
-                   .has_prefix("1,url,"));
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"new EditContext(document.getElementById('test')).encode()")
+                    .get_js_value()
+                ).has_prefix("1,url,"));
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -54,8 +57,11 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
         load_body_fixture(html);
 
         try {
-            assert(Util.WebKit.to_string(run_javascript(@"new 
EditContext(document.getElementById('test')).encode()")) ==
-                   "0,,Comic Sans,144");
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"new EditContext(document.getElementById('test')).encode()")
+                    .get_js_value()
+                ) == "0,,Comic Sans,144");
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -70,9 +76,18 @@ class ComposerPageStateTest : ClientWebViewTestCase<ComposerWebView> {
         try {
             run_javascript(@"SelectionUtil.selectNode(document.getElementById('test'))");
             run_javascript(@"geary.indentLine()");
-            
assert(Util.WebKit.to_int32(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').length")) == 
1);
-            
assert(Util.WebKit.to_string(run_javascript(@"document.querySelectorAll('blockquote[type=cite]').item(0).innerText"))
 ==
-                "some text");
+            assert(
+                Util.JS.to_int32(
+                    run_javascript(@"document.querySelectorAll('blockquote[type=cite]').length")
+                    .get_js_value()
+                ) == 1
+            );
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"document.querySelectorAll('blockquote[type=cite]').item(0).innerText")
+                    .get_js_value()
+                ) == "some text"
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -94,18 +109,30 @@ some text
                           true
             );
         try {
-            assert(Util.WebKit.to_bool(run_javascript(
-                @"geary.containsAttachmentKeyword(\"some\", \"subject text\");"
-            )));
-            assert(Util.WebKit.to_bool(run_javascript(
-                @"geary.containsAttachmentKeyword(\"subject\", \"subject text\");"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
-                @"geary.containsAttachmentKeyword(\"innerquote\", \"subject text\");"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
-                @"geary.containsAttachmentKeyword(\"outerquote\", \"subject text\");"
-            )));
+            assert(
+                Util.JS.to_bool(
+                    run_javascript(@"geary.containsAttachmentKeyword(\"some\", \"subject text\");")
+                    .get_js_value()
+                )
+            );
+            assert(
+                Util.JS.to_bool(
+                    run_javascript(@"geary.containsAttachmentKeyword(\"subject\", \"subject text\");")
+                    .get_js_value()
+                )
+            );
+            assert(
+                !Util.JS.to_bool(
+                    run_javascript(@"geary.containsAttachmentKeyword(\"innerquote\", \"subject text\");")
+                    .get_js_value()
+                )
+            );
+            assert(
+                !Util.JS.to_bool(
+                    run_javascript(@"geary.containsAttachmentKeyword(\"outerquote\", \"subject text\");")
+                    .get_js_value()
+                )
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -143,8 +170,12 @@ unknown://example6.com
 
         try {
             run_javascript("geary.cleanContent();");
-            assert(Util.WebKit.to_string(run_javascript("geary.bodyPart.innerHTML;")) ==
-                   CLEAN_BODY_TEMPLATE.printf(expected));
+            assert(
+                Util.JS.to_string(
+                    run_javascript("geary.bodyPart.innerHTML;")
+                    .get_js_value()
+                ) == CLEAN_BODY_TEMPLATE.printf(expected)
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -158,8 +189,12 @@ unknown://example6.com
         string html = "<p>para</p>";
         load_body_fixture(html);
         try {
-            assert(Util.WebKit.to_string(run_javascript(@"window.geary.getHtml();")) ==
-                   COMPLETE_BODY_TEMPLATE.printf(html));
+            assert(
+                Util.JS.to_string(
+                   run_javascript(@"window.geary.getHtml();")
+                   .get_js_value()
+                ) == COMPLETE_BODY_TEMPLATE.printf(html)
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -172,8 +207,12 @@ unknown://example6.com
     public void get_text() throws Error {
         load_body_fixture("<p>para</p>");
         try {
-            assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) ==
-                   "para\n\n\n\n");
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"window.geary.getText();")
+                    .get_js_value()
+                ) == "para\n\n\n\n"
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -187,8 +226,12 @@ unknown://example6.com
         unichar q_marker = Geary.RFC822.Utils.QUOTE_MARKER;
         load_body_fixture("<p>pre</p> <blockquote><p>quote</p></blockquote> <p>post</p>");
         try {
-            assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) ==
-                   @"pre\n\n$(q_marker)quote\n$(q_marker)\npost\n\n\n\n");
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"window.geary.getText();")
+                    .get_js_value()
+                ) == @"pre\n\n$(q_marker)quote\n$(q_marker)\npost\n\n\n\n"
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s", err.message);
             assert_not_reached();
@@ -202,8 +245,12 @@ unknown://example6.com
         unichar q_marker = Geary.RFC822.Utils.QUOTE_MARKER;
         load_body_fixture("<p>pre</p> <blockquote><p>quote1</p> 
<blockquote><p>quote2</p></blockquote></blockquote> <p>post</p>");
         try {
-            assert(Util.WebKit.to_string(run_javascript(@"window.geary.getText();")) ==
-                   
@"pre\n\n$(q_marker)quote1\n$(q_marker)\n$(q_marker)$(q_marker)quote2\n$(q_marker)$(q_marker)\npost\n\n\n\n");
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"window.geary.getText();")
+                    .get_js_value()
+                ) == 
@"pre\n\n$(q_marker)quote1\n$(q_marker)\n$(q_marker)$(q_marker)quote2\n$(q_marker)$(q_marker)\npost\n\n\n\n"
+            );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -219,44 +266,66 @@ unknown://example6.com
         string suffix_keys = """new Set(["sf1", "sf2"])""";
         try {
             // Doesn't contain
-            assert(!Util.WebKit.to_bool(run_javascript(
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('notcontained', $complete_keys, $suffix_keys);"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('not contained', $complete_keys, $suffix_keys);"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('not\tcontained', $complete_keys, $suffix_keys);"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('http://www.keyword1.com', $complete_keys, 
$suffix_keys);"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('http://www.something.com/something.sf1', 
$complete_keys, $suffix_keys);"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('sf1', $complete_keys, $suffix_keys);"
-            )));
-            assert(!Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(!Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('.sf1', $complete_keys, $suffix_keys);"
-            )));
+                ).get_js_value()
+            ));
+
 
             // Does contain
-            assert(Util.WebKit.to_bool(run_javascript(
+            assert(Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('keyword1', $complete_keys, $suffix_keys);"
-            )));
-            assert(Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('keyword2 contained', $complete_keys, $suffix_keys);"
-            )));
-            assert(Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('keyword2\tcontained', $complete_keys, $suffix_keys);"
-            )));
-            assert(Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('something.sf1', $complete_keys, $suffix_keys);"
-            )));
-            assert(Util.WebKit.to_bool(run_javascript(
+                ).get_js_value()
+            ));
+
+            assert(Util.JS.to_bool(run_javascript(
                 @"ComposerPageState.containsKeywords('something.something.sf2', $complete_keys, 
$suffix_keys);"
-            )));
+                ).get_js_value()
+            ));
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
@@ -271,10 +340,16 @@ unknown://example6.com
         string single_nbsp = "a b";
         string multiple_nbsp = "a b c";
         try {
-            
assert(Util.WebKit.to_string(run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(single_nbsp)');")) 
==
-                   "a b");
-            
assert(Util.WebKit.to_string(run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(multiple_nbsp)');"))
 ==
-                   "a b c");
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(single_nbsp)');")
+                    .get_js_value()
+                ) == "a b");
+            assert(
+                Util.JS.to_string(
+                    run_javascript(@"ComposerPageState.replaceNonBreakingSpace('$(multiple_nbsp)');")
+                    .get_js_value()
+                ) == "a b c");
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);
             assert_not_reached();
diff --git a/test/js/conversation-page-state-test.vala b/test/js/conversation-page-state-test.vala
index 4f189faa..ba68cfde 100644
--- a/test/js/conversation-page-state-test.vala
+++ b/test/js/conversation-page-state-test.vala
@@ -103,12 +103,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
     public void is_descendant_of() throws GLib.Error {
         load_body_fixture("<blockquote><div id='test'>ohhai</div></blockquote>");
         assert(
-            Util.WebKit.to_bool(
+            Util.JS.to_bool(
                 run_javascript("""
                     ConversationPageState.isDescendantOf(
                         document.getElementById('test'), "BLOCKQUOTE"
                     );
                 """)
+                .get_js_value()
            )
         );
     }
@@ -116,12 +117,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
     public void is_descendant_of_with_class() throws GLib.Error {
         load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
         assert(
-            Util.WebKit.to_bool(
+            Util.JS.to_bool(
                 run_javascript("""
                     ConversationPageState.isDescendantOf(
                         document.getElementById('test'), "BLOCKQUOTE", "test-class"
                     );
                 """)
+                .get_js_value()
            )
         );
     }
@@ -129,12 +131,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
     public void is_descendant_of_no_match() throws GLib.Error {
         load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
         assert(
-            Util.WebKit.to_bool(
+            Util.JS.to_bool(
                 run_javascript("""
                     ConversationPageState.isDescendantOf(
                         document.getElementById('test'), "DIV"
                     );
                 """)
+                .get_js_value()
            )
         );
     }
@@ -142,12 +145,13 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
     public void is_descendant_of_lax() throws GLib.Error {
         load_body_fixture("<blockquote class='test-class'><div id='test'>ohhai</div></blockquote>");
         assert(
-            Util.WebKit.to_bool(
+            Util.JS.to_bool(
                 run_javascript("""
                     ConversationPageState.isDescendantOf(
                         document.getElementById('test'), "DIV", null, false
                     );
                 """)
+                .get_js_value()
            )
         );
     }
@@ -159,8 +163,9 @@ class ConversationPageStateTest : ClientWebViewTestCase<ConversationWebView> {
 
     private uint exec_is_deceptive_text(string text, string href) {
         try {
-            return (uint) Util.WebKit.to_int32(
+            return (uint) Util.JS.to_int32(
                 run_javascript(@"ConversationPageState.isDeceptiveText(\"$text\", \"$href\")")
+                .get_js_value()
             );
         } catch (Util.JS.Error err) {
             print("Util.JS.Error: %s\n", err.message);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]