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

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Sep 5 07:07:16 PDT 2015


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

--- Comment #3 from anewtobi at gmail.com ---
Comment on attachment 260684
  --> https://bugs.webkit.org/attachment.cgi?id=260684
patch that adds function get_value_as_string to WebKitJavaScriptResult

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

I had the same problem with the send-message-received singal of UserContentManager.

The problem is JavaScriptCore doesn't have a gobject based API and therefore the introspection doesn't know what to do with it.

There are some JavaScriptCore bindings for python, but all of them are unmaintained or less than ideal in some way or  the other.

Even with those bindings (or using cffi directly) I've found no way to get the actual JSValueRef address in memory and use it from python through the C API. (If someone knows how it would be possible to do this, please enlighten me. It seems you can't easily get around the "Couldn't find conversion for foreign structure 'JavaScriptCore.Value'" error)

For my use case (receiving a message) and I imagine a lot of other use cases what I want in the end is to get a string (in python or C) representing the value, not the JSValueRef itsself.

So I created a new function for WebKitJavaScriptResult named get_value_as_string, which simply converts the value represented by JSValueRef to a gchar* (user is responsible for freeing it) and returns it.

This also works for numbers by the way, they simply get converted to a string. Objects get converted to a string like "[object Object]", so this is at least letting you know that you need to convert the object to a string with something like JSON.stringify from within JavaScript. If anything can't be converted at all, NULL is returned.

I attached the patch. It should work both with 2.8.5 and with master.

-- 
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/20150905/21019a5c/attachment-0001.html>


More information about the webkit-unassigned mailing list