[Webkit-unassigned] [Bug 136989] WebKit2 Gtk+ JavaScriptCore bindings doesn't work properly

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Oct 26 08:32:39 PDT 2016


https://bugs.webkit.org/show_bug.cgi?id=136989

Jack Goofy <jgdev at posteo.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jgdev at posteo.ch

--- Comment #10 from Jack Goofy <jgdev at posteo.ch> ---
modified the patch from anewtobi with the comments from Michael.

--- a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp      2016-03-17 16:58:24.866081047 +0100
+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp       2016-03-17 17:09:58.702068622 +0100
@@ -108,3 +108,34 @@
 {
     return javascriptResult->value;
 }
+
+
+/**
+ * webkit_javascript_result_to_string:
+ * @js_result: a #WebKitJavascriptResult
+ *
+ * Get string representing the value of @js_result. The value referenced by <function>JSValueRef</function>
+ * gets converted to a string, if possible. In any case where this isn't possible %NULL is returned. 
+ *
+ * Return value: (transfer full): a newly allocated result
+ * string; free with g_free()
+ */
+gchar* webkit_javascript_result_to_string(WebKitJavascriptResult* javascriptResult)
+{
+    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
+
+    JSStringRef js_str_value = JSValueToStringCopy(context, javascriptResult->value, nullptr);
+    
+    // If JSValueToStringCopy returns Null, this means JSValueRef couldn't be converted to a JSStringRef,
+    // so we return NULL
+    if (!js_str_value) {
+        return nullptr;
+    }
+
+    gsize str_length = JSStringGetMaximumUTF8CStringSize(js_str_value);
+    gchar* str_value = static_cast<gchar*>(g_malloc(str_length));
+    JSStringGetUTF8CString(js_str_value, str_value, str_length);
+    JSStringRelease(js_str_value);
+
+    return str_value;
+}



--- a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.h        2013-08-03 18:10:40.000000000 +0200
+++ a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.h 2016-03-17 17:15:28.362062718 +0100
@@ -50,6 +50,9 @@
 WEBKIT_API JSValueRef
 webkit_javascript_result_get_value          (WebKitJavascriptResult *js_result);

+WEBKIT_API gchar*
+webkit_javascript_result_to_string          (WebKitJavascriptResult *js_result);
+
 G_END_DECLS

 #endif

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20161026/ef5c00ae/attachment-0001.html>


More information about the webkit-unassigned mailing list