aboutsummaryrefslogtreecommitdiffstats
path: root/mail/geary/files/patch-0d96695
blob: 9b6eb4f49ec8cb7450714d75364ee4c4d4a1f42c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
https://gitlab.gnome.org/GNOME/geary/issues/37

From 0d966950a2cba888873cd3a7f4f42bb7a017dc6d Mon Sep 17 00:00:00 2001
From: Rico Tzschichholz <ricotz@ubuntu.com>
Date: Mon, 23 Apr 2018 19:56:18 +0200
Subject: [PATCH] Adjust to upstream javascriptcore-4.0 bindings

---
 .../conversation-web-view.vala                |  2 +-
 src/client/util/util-webkit.vala              | 10 +++----
 .../web-process/web-process-extension.vala    | 17 ++++-------
 src/engine/util/util-js.vala                  | 30 +++++++++++++------
 4 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/src/client/conversation-viewer/conversation-web-view.vala b/src/client/conversation-viewer/conversation-web-view.vala
index 588d39bd..d8512355 100644
--- src/client/conversation-viewer/conversation-web-view.vala
+++ src/client/conversation-viewer/conversation-web-view.vala
@@ -183,7 +183,7 @@ public class ConversationWebView : ClientWebView {
 
     private void on_deceptive_link_clicked(WebKit.JavascriptResult result) {
         try {
-            JS.GlobalContext context = result.get_global_context();
+            unowned JS.GlobalContext context = result.get_global_context();
             JS.Object details = WebKitUtil.to_object(result);
 
             uint reason = (uint) Geary.JS.to_number(
diff --git a/src/client/util/util-webkit.vala b/src/client/util/util-webkit.vala
index 319e28ad..cba9eaf2 100644
--- src/client/util/util-webkit.vala
+++ src/client/util/util-webkit.vala
@@ -18,8 +18,8 @@ namespace WebKitUtil {
      */
     public bool to_bool(WebKit.JavascriptResult result)
         throws Geary.JS.Error {
-        JS.GlobalContext context = result.get_global_context();
-        JS.Value value = result.get_value();
+        unowned JS.GlobalContext context = result.get_global_context();
+        unowned JS.Value value = result.get_value();
         if (!value.is_boolean(context)) {
             throw new Geary.JS.Error.TYPE("Result is not a JS Boolean object");
         }
@@ -59,12 +59,12 @@ namespace WebKitUtil {
      */
     public string as_string(WebKit.JavascriptResult result)
         throws Geary.JS.Error {
-        JS.GlobalContext context = result.get_global_context();
-        JS.Value js_str_value = result.get_value();
+        unowned JS.GlobalContext context = result.get_global_context();
+        unowned JS.Value js_str_value = result.get_value();
         JS.Value? err = null;
         JS.String js_str = js_str_value.to_string_copy(context, out err);
         Geary.JS.check_exception(context, err);
-        return Geary.JS.to_string_released(js_str);
+        return Geary.JS.to_string_released((owned) js_str);
     }
 
     /**
diff --git a/src/client/web-process/web-process-extension.vala b/src/client/web-process/web-process-extension.vala
index ee89139d..1f478a6c 100644
--- src/client/web-process/web-process-extension.vala
+++ src/client/web-process/web-process-extension.vala
@@ -87,10 +87,9 @@ public class GearyWebExtension : Object {
         bool should_load = false;
         WebKit.Frame frame = page.get_main_frame();
         // Explicit cast fixes build on s390x/ppc64. Bug 783882
-        JS.GlobalContext context = (JS.GlobalContext)
-            frame.get_javascript_global_context();
+        unowned JS.GlobalContext context = frame.get_javascript_global_context();
         try {
-            JS.Value ret = execute_script(
+            unowned JS.Value ret = execute_script(
                 context, "geary.allowRemoteImages", int.parse("__LINE__")
             );
             should_load = ret.to_boolean(context);
@@ -106,8 +105,7 @@ public class GearyWebExtension : Object {
     private void remote_image_load_blocked(WebKit.WebPage page) {
         WebKit.Frame frame = page.get_main_frame();
         // Explicit cast fixes build on s390x/ppc64. Bug 783882
-        JS.GlobalContext context = (JS.GlobalContext)
-            frame.get_javascript_global_context();
+        unowned JS.GlobalContext context = frame.get_javascript_global_context();
         try {
             execute_script(
                 context, "geary.remoteImageLoadBlocked();", int.parse("__LINE__")
@@ -123,8 +121,7 @@ public class GearyWebExtension : Object {
     private void selection_changed(WebKit.WebPage page) {
         WebKit.Frame frame = page.get_main_frame();
         // Explicit cast fixes build on s390x/ppc64. Bug 783882
-        JS.GlobalContext context = (JS.GlobalContext)
-            frame.get_javascript_global_context();
+        unowned JS.GlobalContext context = frame.get_javascript_global_context();
         try {
             execute_script(
                 context, "geary.selectionChanged();", int.parse("__LINE__")
@@ -136,20 +133,18 @@ public class GearyWebExtension : Object {
 
     // Return type is nullable as a workaround for Bug 778046, it will
     // never actually be null.
-    private JS.Value? execute_script(JS.Context context, string script, int line)
+    private unowned JS.Value? execute_script(JS.Context context, string script, int line)
     throws Geary.JS.Error {
         JS.String js_script = new JS.String.create_with_utf8_cstring(script);
         JS.String js_source = new JS.String.create_with_utf8_cstring("__FILE__");
         JS.Value? err = null;
         try {
-            JS.Value ret = context.evaluate_script(
+            unowned JS.Value ret = context.evaluate_script(
                 js_script, null, js_source, line, out err
             );
             Geary.JS.check_exception(context, err);
             return ret;
         } finally {
-            js_script.release();
-            js_source.release();
         }
     }
 
diff --git a/src/engine/util/util-js.vala b/src/engine/util/util-js.vala
index 4d224297..ea955e99 100644
--- src/engine/util/util-js.vala
+++ src/engine/util/util-js.vala
@@ -10,6 +10,16 @@
  */
 namespace Geary.JS {
 
+#if !VALA_0_42
+    // Workaround broken version of this in the vala bindings. See Bug
+    // 788113.
+    [CCode (cname = "JSStringGetUTF8CString")]
+    private extern size_t js_string_get_utf8_cstring(
+        global::JS.String js,
+        [CCode (array_length_type = "gsize")] char[] buffer
+    );
+#endif
+
     /**
      * Errors produced by functions in {@link Geary.JS}.
      */
@@ -72,7 +82,7 @@ namespace Geary.JS {
         global::JS.String js_str = value.to_string_copy(context, out err);
         Geary.JS.check_exception(context, err);
 
-        return Geary.JS.to_string_released(js_str);
+        return Geary.JS.to_string_released((owned) js_str);
     }
 
     /**
@@ -101,12 +111,15 @@ namespace Geary.JS {
     /**
      * Returns a JSC {@link JS.String} as a Vala {@link string}.
      */
-    public inline string to_string_released(global::JS.String js) {
-        int len = js.get_maximum_utf8_cstring_size();
-        string str = string.nfill(len, 0);
-        js.get_utf8_cstring(str, len);
-        js.release();
-        return str;
+    public inline string to_string_released(owned global::JS.String js) {
+        size_t len = js.get_maximum_utf8_cstring_size();
+        uint8[] str = new uint8[len];
+#if VALA_0_42
+        js.get_utf8_cstring(str);
+#else
+        js_string_get_utf8_cstring(js, (char[]) str);
+#endif
+        return (string) str;
     }
 
     /**
@@ -128,7 +141,6 @@ namespace Geary.JS {
         try {
             Geary.JS.check_exception(context, err);
         } finally {
-            js_name.release();
         }
         return prop;
     }
@@ -157,7 +169,7 @@ namespace Geary.JS {
 
             throw new Error.EXCEPTION(
                 "JS exception thrown [%s]: %s"
-                .printf(err_type.to_string(), to_string_released(err_str))
+                .printf(err_type.to_string(), to_string_released((owned) err_str))
             );
         }
     }
-- 
2.18.1