[geary/wip/vala-js-bindings] Import javascriptcoregtk-4.0.vapi from vala and fix String binding.



commit 271d135e14cc62f06108ff17188e6abbb4180201
Author: Michael James Gratton <mike vee net>
Date:   Sun May 20 18:35:03 2018 +1000

    Import javascriptcoregtk-4.0.vapi from vala and fix String binding.
    
    The version of the legacy JS VAPI vala is shipping has a broken binding
    for JS.String.get_utf8_cstring. This imports the VAPI and fixes the
    binding, so that the client unit tests pass fine.

 bindings/vapi/javascriptcoregtk-4.0.vapi |  150 ++++++++++++++++++++++++++++++
 meson.build                              |   12 ++-
 src/engine/util/util-js.vala             |    2 +-
 src/meson.build                          |   14 +++-
 4 files changed, 174 insertions(+), 4 deletions(-)
---
diff --git a/bindings/vapi/javascriptcoregtk-4.0.vapi b/bindings/vapi/javascriptcoregtk-4.0.vapi
new file mode 100644
index 0000000..4fd45b8
--- /dev/null
+++ b/bindings/vapi/javascriptcoregtk-4.0.vapi
@@ -0,0 +1,150 @@
+/* javascriptcoregtk-4.0.vapi generated by vapigen, do not modify. */
+
+[CCode (cprefix = "JS", gir_namespace = "JavaScriptCore", gir_version = "4.0", lower_case_cprefix = "JS_")]
+namespace JS {
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "void", free_function = 
"JSClassRelease", has_type_id = false)]
+       [Compact]
+       public class Class {
+               [CCode (cname = "JSClassRelease")]
+               [DestroysInstance]
+               public void release ();
+               [CCode (cname = "JSClassRetain")]
+               public JS.Class retain ();
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "const struct OpaqueJSContext", 
free_function = "", has_type_id = false)]
+       [Compact]
+       public class Context {
+               [CCode (cname = "JSCheckScriptSyntax")]
+               public bool check_script_syntax (JS.String script, JS.String? source_url = null, int 
starting_line_number = 1, out JS.Value? exception = null);
+               [CCode (cname = "JSGarbageCollect")]
+               public void collect_garbage ();
+               [CCode (cname = "JSEvaluateScript")]
+               public unowned JS.Value? evaluate_script (JS.String script, JS.Object? this_object = null, 
JS.String? source_url = null, int starting_line_number = 1, out JS.Value? exception = null);
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "struct OpaqueJSContext", 
free_function = "JSGlobalContextRelease", has_type_id = false)]
+       [Compact]
+       public class GlobalContext : JS.Context {
+               [CCode (cname = "JSGlobalContextCreate")]
+               public GlobalContext (JS.Class? global_object_class = null);
+               [CCode (cname = "JSGlobalContextRelease")]
+               [DestroysInstance]
+               public void release ();
+               [CCode (cname = "JSGlobalContextRetain")]
+               public JS.GlobalContext retain ();
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "struct OpaqueJSValue", 
free_function = "", has_type_id = false)]
+       [Compact]
+       public class Object {
+               [CCode (cname = "JSObjectCallAsFunction", instance_pos = 1.1)]
+               public JS.Value call_as_function (JS.Context ctx, JS.Object? this_object, [CCode 
(array_length_pos = 2.5)] JS.Value[]? arguments, out JS.Value? exception);
+               [CCode (cname = "JSObjectGetProperty", instance_pos = 1.1)]
+               public JS.Value get_property (JS.Context ctx, JS.String property_name, out JS.Value? 
exception);
+               [CCode (cname = "JSObjectHasProperty", instance_pos = 1.1)]
+               public bool has_property (JS.Context ctx, JS.String property_name);
+               [CCode (cname = "JSObjectMakeFunction")]
+               public Object.make_function (JS.String? name, [CCode (array_length_pos = 1.5)] JS.String[]? 
parameter_names, JS.String body, JS.String? source_url, int starting_line_number, out JS.Value? exception);
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "struct OpaqueJSString", 
free_function = "JSStringRelease", has_type_id = false)]
+       [Compact]
+       public class String {
+               [CCode (cname = "JSStringCreateWithUTF8CString")]
+               public String.create_with_utf8_cstring (string str);
+               [CCode (cname = "JSStringGetLength")]
+               public size_t get_length ();
+               [CCode (cname = "JSStringGetMaximumUTF8CStringSize")]
+               public size_t get_maximum_utf8_cstring_size ();
+               [CCode (cname = "JSStringGetUTF8CString")]
+               public size_t get_utf8_cstring (uint8[] buffer);
+               [CCode (cname = "JSStringIsEqual")]
+               public bool is_equal (JS.String b);
+               [CCode (cname = "JSStringIsEqualToUTF8CString")]
+               public bool is_equal_to_utf8_cstring (string b);
+               [CCode (cname = "JSStringRelease")]
+               [DestroysInstance]
+               public void release ();
+               [CCode (cname = "JSStringRetain")]
+               public JS.String retain ();
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "const struct OpaqueJSValue", 
free_function = "", has_type_id = false)]
+       [Compact]
+       public class Value {
+               [CCode (cname = "JSValueGetType", instance_pos = 1.1)]
+               public JS.Type get_type (JS.Context ctx);
+               [CCode (cname = "JSValueGetTypedArrayType", instance_pos = 1.1)]
+               public JS.TypedArrayType get_typed_array_type (JS.Context ctx);
+               [CCode (cname = "JSValueIsArray", instance_pos = 1.1)]
+               public bool is_array (JS.Context ctx);
+               [CCode (cname = "JSValueIsBoolean", instance_pos = 1.1)]
+               public bool is_boolean (JS.Context ctx);
+               [CCode (cname = "JSValueIsDate", instance_pos = 1.1)]
+               public bool is_date (JS.Context ctx);
+               [CCode (cname = "JSValueIsEqual", instance_pos = 1.1)]
+               public bool is_equal (JS.Context ctx, JS.Value b, out JS.Value? exception = null);
+               [CCode (cname = "JSValueIsNull", instance_pos = 1.1)]
+               public bool is_null (JS.Context ctx);
+               [CCode (cname = "JSValueIsNumber", instance_pos = 1.1)]
+               public bool is_number (JS.Context ctx);
+               [CCode (cname = "JSValueIsObject", instance_pos = 1.1)]
+               public bool is_object (JS.Context ctx);
+               [CCode (cname = "JSValueIsObjectOfClass", instance_pos = 1.1)]
+               public bool is_object_of_class (JS.Context ctx, JS.Class js_class);
+               [CCode (cname = "JSValueIsStrictEqual", instance_pos = 1.1)]
+               public bool is_strict_equal (JS.Context ctx, JS.Value b);
+               [CCode (cname = "JSValueIsString", instance_pos = 1.1)]
+               public bool is_string (JS.Context ctx);
+               [CCode (cname = "JSValueIsUndefined", instance_pos = 1.1)]
+               public bool is_undefined (JS.Context ctx);
+               [CCode (cname = "JSValueProtect", instance_pos = 1.1)]
+               public void protect (JS.Context ctx);
+               [CCode (cname = "JSValueToBoolean", instance_pos = 1.1)]
+               public bool to_boolean (JS.Context ctx);
+               [CCode (cname = "JSValueToNumber", instance_pos = 1.1)]
+               public double to_number (JS.Context ctx, out JS.Value? exception = null);
+               [CCode (cname = "JSValueToObject", instance_pos = 1.1)]
+               public JS.Object to_object (JS.Context ctx, out JS.Value? exception = null);
+               [CCode (cname = "JSValueToStringCopy", instance_pos = 1.1)]
+               public JS.String to_string_copy (JS.Context ctx, out JS.Value? exception = null);
+               [CCode (cname = "JSValueUnprotect", instance_pos = 1.1)]
+               public void unprotect (JS.Context ctx);
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "JSType", has_type_id = false)]
+       public enum Type {
+               [CCode (cname = "kJSTypeUndefined")]
+               UNDEFINED,
+               [CCode (cname = "kJSTypeNull")]
+               NULL,
+               [CCode (cname = "kJSTypeBoolean")]
+               BOOLEAN,
+               [CCode (cname = "kJSTypeNumber")]
+               NUMBER,
+               [CCode (cname = "kJSTypeString")]
+               STRING,
+               [CCode (cname = "kJSTypeObject")]
+               OBJECT
+       }
+       [CCode (cheader_filename = "JavaScriptCore/JavaScript.h", cname = "JSTypedArrayType", has_type_id = 
false)]
+       public enum TypedArrayType {
+               [CCode (cname = "kJSTypedArrayTypeInt8Array")]
+               INT8,
+               [CCode (cname = "kJSTypedArrayTypeInt16Array")]
+               INT16,
+               [CCode (cname = "kJSTypedArrayTypeInt32Array")]
+               INT32,
+               [CCode (cname = "kJSTypedArrayTypeUint8Array")]
+               UINT8,
+               [CCode (cname = "kJSTypedArrayTypeUint8ClampedArray")]
+               UINT8_CLAMPED,
+               [CCode (cname = "kJSTypedArrayTypeUint16Array")]
+               UINT16,
+               [CCode (cname = "kJSTypedArrayTypeUint32Array")]
+               UINT32,
+               [CCode (cname = "kJSTypedArrayTypeFloat32Array")]
+               FLOAT32,
+               [CCode (cname = "kJSTypedArrayTypeFloat64Array")]
+               FLOAT64,
+               [CCode (cname = "kJSTypedArrayTypeArrayBuffer")]
+               BUFFER,
+               [CCode (cname = "kJSTypedArrayTypeNone")]
+               NONE
+       }
+}
diff --git a/meson.build b/meson.build
index 1f407dd..3cfab8b 100644
--- a/meson.build
+++ b/meson.build
@@ -62,9 +62,19 @@ gcr = dependency('gcr-3', version: '>= 3.10.1')
 gobject_introspection = dependency('gobject-introspection-1.0')
 webkit2gtk = dependency('webkit2gtk-4.0', version: '>=' + target_webkit)
 webkit2gtk_web_extension = dependency('webkit2gtk-web-extension-4.0', version: '>=' + target_webkit)
-javascriptcoregtk = dependency('javascriptcoregtk-4.0', version: '>=' + target_webkit)
 enchant = dependency('enchant', version: '>= 1.6')
 
+webkit2gtk_include = include_directories(
+  webkit2gtk.get_pkgconfig_variable('includedir') + '/webkitgtk-4.0'
+)
+javascriptcoregtk = declare_dependency(
+  dependencies: [
+    valac.find_library('javascriptcoregtk-4.0', dirs: vapi_dir),
+    cc.find_library('javascriptcoregtk-4.0'),
+  ],
+  include_directories: webkit2gtk_include
+)
+
 # System dependencies ensures appropriate versions, but the declared
 # depencency is what we actually build against.
 libunwind_dep = dependency('libunwind', version: '>= 1.1')
diff --git a/src/engine/util/util-js.vala b/src/engine/util/util-js.vala
index dcfac4b..a16f880 100644
--- a/src/engine/util/util-js.vala
+++ b/src/engine/util/util-js.vala
@@ -104,7 +104,7 @@ namespace Geary.JS {
     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);
+        js.get_utf8_cstring(str);
         return (string) str;
     }
 
diff --git a/src/meson.build b/src/meson.build
index 83ccf2c..894f9d3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -105,8 +105,18 @@ if enable_valadoc
       '-o', '@OUTPUT@',
       '--vapidir=@0@'.format(vapi_dir),
       '--vapidir=@0@'.format(meson.current_build_dir()),
-      # Hopefully, Meson gets baked-in valadoc support, so we don't have to do this (see also 
https://github.com/mesonbuild/meson/issues/894)
-      '--pkg', 'glib-2.0', '--pkg', 'gio-2.0', '--pkg', 'gee-0.8', '--pkg', 'sqlite3', '--pkg', 'gmime-2.6', 
'--pkg', 'javascriptcore-4.0', '--pkg', 'libxml-2.0', '--pkg', 'libunwind',
+
+      # Hopefully, Meson gets baked-in valadoc support, so we don't have to
+      # do this (see also https://github.com/mesonbuild/meson/issues/894)
+      '--pkg', 'glib-2.0',
+      '--pkg', 'gio-2.0',
+      '--pkg', 'gee-0.8',
+      '--pkg', 'sqlite3',
+      '--pkg', 'gmime-2.6',
+      '--pkg', 'javascriptcoregtk-4.0',
+      '--pkg', 'libxml-2.0',
+      '--pkg', 'libunwind',
+
       '@INPUT@',
     ]
   )


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