src/Palete/Palete.vala
[app.Builder.js] / src / Palete / Javascript.vala
index 8f81d1d..64a73a1 100644 (file)
@@ -1,10 +1,10 @@
 
-extern JSValueRef jscore_object_call_as_function(
-       JSContextRef ctx
-       JSObjectRef object, 
-       JSObjectRef thisObject,
-       gchar * val,
-       JSValueRef* exception
+extern JSCore.Value jscore_object_call_as_function(
+       JSCore.Context ctx,
+       JSCore.Object object, 
+       JSCore.Object thisObject,
+       string  val,
+       out JSCore.Value exception
        );
        
 
@@ -124,7 +124,8 @@ namespace Palete {
                 * then a method is called, with a string argument (json encoded)
                 * 
                 */
-               public void executeFile(string fname, string call_method, string js_data)
+               public string executeFile(string fname, string call_method, string js_data)
+                               throws JavascriptError
                {
                        string file_data;
                        if (!FileUtils.test (fname, FileTest.EXISTS)) {
@@ -135,12 +136,13 @@ namespace Palete {
                        
                        var jfile_data = new JSCore.String.with_utf8_c_string(file_data);
                        var jmethod = new JSCore.String.with_utf8_c_string(call_method);
-                       var json_args = new JSCore.String.with_utf8_c_string(js_data);
+                       //var json_args = new JSCore.String.with_utf8_c_string(js_data);
                        
                             JSCore.Value exa;
                          JSCore.Value exb;
                        unowned JSCore.Value exc;
                           JSCore.Value exd;
+                          unowned JSCore.Value exe;
                        
                        var goc = new JSCore.Class(  class_definition ); 
                        var ctx = new JSCore.GlobalContext(goc);
@@ -157,7 +159,7 @@ namespace Palete {
                        
                        if (!othis.has_property(ctx,jmethod)) {
                                throw new JavascriptError.MISSING_METHOD ("Plugin: missing method  %s", call_method);
-                               return;
+                        
                        }
                        
                        var val =  othis.get_property (ctx, jmethod, out exb);
@@ -165,19 +167,32 @@ namespace Palete {
                        if (!val.is_object(ctx)) {
                                throw new JavascriptError.MISSING_METHOD ("Plugin: not a property not found  %s", call_method);
                        }
-                       var oval = val.to_object(ctx, out exc);
+                       var oval = val.to_object(ctx,  out  exc);
                        
                        if (!oval.is_function(ctx)) {
                                throw new JavascriptError.MISSING_METHOD ("Plugin: not a method  %s", call_method);
                        }
-                        
+                       
+                
+                        var res = jscore_object_call_as_function(
+                               ctx, oval, othis, js_data, out exd
+                               );
                     // this will never work, as we can not create arrays of Values - due to no 
                     // free function being available..
                         //var args =  new JSCore.Value[1] ;
                         //args[0] = new JSCore.Value.string(ctx,json_args) ;
                         
-                        unowned JSCore.Value res = oval.call_as_function(ctx, othis, null, out exd);
-
+                        //unowned JSCore.Value res = oval.call_as_function(ctx, othis, null, out exd);
+                       // extract the text value from res...
+                        JSCore.String  sv = res.to_string_copy ( ctx,  out  exe);
+                        var length = sv.get_maximum_utf8_c_string_size();
+                        var buf = new char[length];
+                       
+                        sv.get_utf8_c_string( buf, length);
+                        
+                        
+                        print("ret:%s\n",(string)  buf);
+                        return (string) buf;
                        
                }