[libpeas] WIP: use new() keyword for the seed loader.



commit 71a1f1ccd7b74d78407a7e31f96acc2445301b8f
Author: Steve Frécinaux <code istique net>
Date:   Mon Apr 4 23:50:38 2011 +0200

    WIP: use new() keyword for the seed loader.
    
    FIXME: we should still support the old way and warn when it is used.

 loaders/seed/peas-plugin-loader-seed.c             |   41 ++++++++------------
 peas-demo/plugins/seedhello/seedhello.js           |   20 +++++-----
 .../plugins/extension-seed/extension-seed.js       |   24 ++++++------
 3 files changed, 38 insertions(+), 47 deletions(-)
---
diff --git a/loaders/seed/peas-plugin-loader-seed.c b/loaders/seed/peas-plugin-loader-seed.c
index 9e87204..f412de9 100644
--- a/loaders/seed/peas-plugin-loader-seed.c
+++ b/loaders/seed/peas-plugin-loader-seed.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <seed.h>
+#include <JavaScriptCore/JavaScript.h>
 
 #include "peas-plugin-loader-seed.h"
 #include "peas-extension-seed.h"
@@ -131,8 +132,7 @@ peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
 {
   PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (loader);
   SeedInfo *sinfo;
-  SeedValue extension_methods, extension;
-  gchar **property_names;
+  SeedValue extension_ctor, extension;
   guint i, j;
   SeedValue value;
   GValue gvalue = { 0 };
@@ -140,36 +140,29 @@ peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
   sinfo = (SeedInfo *) g_hash_table_lookup (sloader->loaded_plugins, info);
 
   /* FIXME: instantiate new object and pass the parameters */
-  extension_methods = seed_object_get_property (sinfo->context,
-                                                sinfo->extensions,
-                                                g_type_name (exten_type));
-  if (!extension_methods ||
-      seed_value_is_undefined (sinfo->context, extension_methods) ||
-      seed_value_is_null (sinfo->context, extension_methods))
+  extension_ctor = seed_object_get_property (sinfo->context,
+                                             sinfo->extensions,
+                                             g_type_name (exten_type));
+  if (!extension_ctor ||
+      seed_value_is_undefined (sinfo->context, extension_ctor) ||
+      seed_value_is_null (sinfo->context, extension_ctor))
     return NULL;
 
-  if (!seed_value_is_object (sinfo->context, extension_methods))
+  if (!seed_value_is_object (sinfo->context, extension_ctor))
     {
       g_warning ("Extension '%s' in plugin '%s' is not a Seed object",
                  g_type_name (exten_type), peas_plugin_info_get_module_name (info));
       return NULL;
     }
 
-  /* Copy the original extension_methods object to a new specific object. */
-  extension = seed_make_object (sinfo->context, NULL, NULL);
-  property_names = seed_object_copy_property_names (sinfo->context,
-                                                    extension_methods);
-  for (i = 0; property_names[i] != NULL; i++)
-    {
-      SeedValue value;
+  /* Instantiate the ctor object into a new specific object. */
+  extension = JSObjectCallAsConstructor (sinfo->context, extension_ctor, 0, NULL, NULL);
 
-      value = seed_object_get_property (sinfo->context,
-                                        extension_methods,
-                                        property_names[i]);
-      seed_object_set_property (sinfo->context,
-                                extension,
-                                property_names[i],
-                                value);
+  if (extension == NULL)
+    {
+      g_warning ("Extension '%s' in plugin '%s' is not a valid constructor object",
+                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));
+      return NULL;
     }
 
   /* Set the properties as well, cannot use
@@ -199,8 +192,6 @@ peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
       g_free (key);
     }
 
-  g_strfreev (property_names);
-
   /* Set the plugin info as an attribute of the instance */
   g_value_init (&gvalue, PEAS_TYPE_PLUGIN_INFO);
   g_value_set_boxed (&gvalue, info);
diff --git a/peas-demo/plugins/seedhello/seedhello.js b/peas-demo/plugins/seedhello/seedhello.js
index 46401cb..a06d914 100644
--- a/peas-demo/plugins/seedhello/seedhello.js
+++ b/peas-demo/plugins/seedhello/seedhello.js
@@ -25,27 +25,27 @@ var LABEL_STRING = "Seed Says Hello Too!";
 
 print("LABEL_STRING=" +  LABEL_STRING);
 
-activatable_extension = {
-  activate: function() {
+function activatable_extension() {
+  this.activate = function() {
     print("SeedHelloPlugin.activate");
     this.object._seedhello_label = new Gtk.Label({ label: LABEL_STRING });
     this.object._seedhello_label.show();
     this.object.get_child().pack_start(this.object._seedhello_label);
-  },
-  deactivate: function() {
+  };
+  this.deactivate = function() {
     print("SeedHelloPlugin.deactivate");
     this.object.get_child().remove(this.object._seedhello_label);
     this.object._seedhello_label.destroy();
-  },
-  update_state: function() {
+  };
+  this.update_state = function() {
     print("SeedHelloPlugin.update_state");
-  }
+  };
 };
 
-configurable_extension = {
-  create_configure_widget: function () {
+function configurable_extension() {
+  this.create_configure_widget = function () {
     return new Gtk.Label({ label: "Example of configuration dialog for a Seed plugin" });
-  }
+  };
 };
 
 extensions = {
diff --git a/tests/libpeas/plugins/extension-seed/extension-seed.js b/tests/libpeas/plugins/extension-seed/extension-seed.js
index 4dddce4..876b4d8 100644
--- a/tests/libpeas/plugins/extension-seed/extension-seed.js
+++ b/tests/libpeas/plugins/extension-seed/extension-seed.js
@@ -1,20 +1,20 @@
-callable_extension = {
-  call_with_return: function() {
+function callable_extension() {
+  this.call_with_return = function() {
     return "Hello, World!"
-  },
-  call_no_args: function() {
-  },
-  call_single_arg: function() {
+  };
+  this.call_no_args = function() {
+  };
+  this.call_single_arg = function() {
     return true
-  },
-  call_multi_args: function() {
+  };
+  this.call_multi_args = function() {
     return [ true, true, true ]
-  }
+  };
 };
 
-properties_extension = {
-  read_only: "read-only",
-  readwrite: "readwrite"
+function properties_extension() {
+  this.read_only = "read-only";
+  this.readwrite = "readwrite";
 };
 
 extensions = {



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