[geary/wip/ricotz/webkit: 2/2] Adjust to upstream javascriptcore-4.0 bindings
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/ricotz/webkit: 2/2] Adjust to upstream javascriptcore-4.0 bindings
- Date: Mon, 23 Apr 2018 18:05:21 +0000 (UTC)
commit 93a7da09ccfe300d4f9a89c8601506fa6da8a8e9
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Apr 23 19:56:18 2018 +0200
Adjust to upstream javascriptcore-4.0 bindings
.../conversation-viewer/conversation-web-view.vala | 2 +-
src/client/util/util-webkit.vala | 10 ++++----
src/client/web-process/web-process-extension.vala | 21 +++++++------------
src/engine/util/util-js.vala | 18 +++++++---------
4 files changed, 22 insertions(+), 29 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-web-view.vala
b/src/client/conversation-viewer/conversation-web-view.vala
index 0df3a21..642eb7f 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/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 319e28a..cba9eaf 100644
--- a/src/client/util/util-webkit.vala
+++ b/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 abd9ae4..1f478a6 100644
--- a/src/client/web-process/web-process-extension.vala
+++ b/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 = JS.String.create_with_utf8_cstring(script);
- JS.String js_source = JS.String.create_with_utf8_cstring("__FILE__");
+ 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 e53ff74..dcfac4b 100644
--- a/src/engine/util/util-js.vala
+++ b/src/engine/util/util-js.vala
@@ -72,7 +72,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 +101,11 @@ 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];
+ js.get_utf8_cstring(ref str);
+ return (string) str;
}
/**
@@ -122,13 +121,12 @@ namespace Geary.JS {
global::JS.Object object,
string name)
throws Geary.JS.Error {
- global::JS.String js_name = global::JS.String.create_with_utf8_cstring(name);
+ global::JS.String js_name = new global::JS.String.create_with_utf8_cstring(name);
global::JS.Value? err = null;
global::JS.Value prop = object.get_property(context, js_name, out err);
try {
Geary.JS.check_exception(context, err);
} finally {
- js_name.release();
}
return prop;
}
@@ -157,7 +155,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))
);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]