summaryrefslogtreecommitdiff
path: root/loaders
diff options
context:
space:
mode:
authorGarrett Regier <garrettregier@gmail.com>2013-11-12 23:56:39 -0800
committerGarrett Regier <garrettregier@gmail.com>2013-11-13 01:06:40 -0800
commit730edb65d6da0ebd0bd7065aeb9435b31d304b08 (patch)
treec54f3981d830352ce0811ac32c8ffd1524871191 /loaders
parent85960307ff553a4c81c57e98fce141d1ad2f985a (diff)
downloadlibpeas-730edb65d6da0ebd0bd7065aeb9435b31d304b08.tar.gz
Remove support for gjs-based Javascript plugins
There have been changes to the gjs bindings and as the issue has only recently been noticed it is assumed that support for them is not highly desired. https://bugzilla.gnome.org/show_bug.cgi?id=711356
Diffstat (limited to 'loaders')
-rw-r--r--loaders/Makefile.am4
-rw-r--r--loaders/gjs/Makefile.am25
-rw-r--r--loaders/gjs/peas-extension-gjs.c427
-rw-r--r--loaders/gjs/peas-extension-gjs.h60
-rw-r--r--loaders/gjs/peas-plugin-loader-gjs.c396
-rw-r--r--loaders/gjs/peas-plugin-loader-gjs.h55
6 files changed, 0 insertions, 967 deletions
diff --git a/loaders/Makefile.am b/loaders/Makefile.am
index dd5ac86..dc9cb45 100644
--- a/loaders/Makefile.am
+++ b/loaders/Makefile.am
@@ -1,9 +1,5 @@
SUBDIRS =
-if ENABLE_GJS
-SUBDIRS += gjs
-endif
-
if ENABLE_PYTHON2
SUBDIRS += python
endif
diff --git a/loaders/gjs/Makefile.am b/loaders/gjs/Makefile.am
deleted file mode 100644
index fb8c1a6..0000000
--- a/loaders/gjs/Makefile.am
+++ /dev/null
@@ -1,25 +0,0 @@
-# GJS plugin loader
-
-loaderdir = $(libdir)/libpeas-1.0/loaders
-
-INCLUDES = \
- -I$(top_srcdir) \
- $(PEAS_CFLAGS) \
- $(GCOV_CFLAGS) \
- $(WARN_CFLAGS) \
- $(DISABLE_DEPRECATED) \
- $(GJS_CFLAGS)
-
-loader_LTLIBRARIES = libgjsloader.la
-
-libgjsloader_la_SOURCES = \
- peas-extension-gjs.c \
- peas-extension-gjs.h \
- peas-plugin-loader-gjs.c \
- peas-plugin-loader-gjs.h
-
-libgjsloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS) $(GCOV_LDFLAGS)
-libgjsloader_la_LIBADD = $(PEAS_LIBS) $(GJS_LIBS)
-
-gcov_sources = $(libgjsloader_la_SOURCES)
-include $(top_srcdir)/Makefile.gcov
diff --git a/loaders/gjs/peas-extension-gjs.c b/loaders/gjs/peas-extension-gjs.c
deleted file mode 100644
index 691968d..0000000
--- a/loaders/gjs/peas-extension-gjs.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * peas-extension-gjs.c
- * This file is part of libpeas
- *
- * Copyright (C) 2011 - Garrett Regier, Steve Frécinaux
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-
-#include <gjs/gjs-module.h>
-#include <girepository.h>
-#include <gi/arg.h>
-#include <gi/value.h>
-
-#include <libpeas/peas-introspection.h>
-#include <libpeas/peas-extension-subclasses.h>
-
-#include "peas-extension-gjs.h"
-
-G_DEFINE_TYPE (PeasExtensionGjs, peas_extension_gjs, PEAS_TYPE_EXTENSION_WRAPPER);
-
-typedef struct {
- GIArgInfo arg_info;
- GITypeInfo type_info;
-
- /* Only used by out arguments */
- gpointer ptr;
-} CachedArg;
-
-static void
-peas_extension_gjs_init (PeasExtensionGjs *gexten)
-{
-}
-
-static gchar *
-convert_property_name (const gchar *pname)
-{
- gint i;
- gchar *prop_name;
-
- prop_name = g_strdup (pname);
-
- for (i = 0; prop_name[i] != '\0'; ++i)
- {
- if (prop_name[i] == '-')
- prop_name[i] = '_';
- }
-
- return prop_name;
-}
-
-static void
-peas_extension_gjs_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionGjs *gexten = PEAS_EXTENSION_GJS (object);
- gchar *prop_name;
- jsval js_value;
-
- prop_name = convert_property_name (g_param_spec_get_name (pspec));
-
- if (!gjs_value_from_g_value (gexten->js_context, &js_value, value))
- {
- g_warning ("Error: failed to convert GValue to "
- "jsval for property '%s'", prop_name);
- }
- else if (!JS_SetProperty (gexten->js_context, gexten->js_object,
- prop_name, &js_value))
- {
- g_warning ("Error: failed to set property '%s'", prop_name);
- }
-
- g_free (prop_name);
-}
-
-static void
-peas_extension_gjs_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionGjs *gexten = PEAS_EXTENSION_GJS (object);
- gchar *prop_name;
- jsval js_value;
-
- prop_name = convert_property_name (g_param_spec_get_name (pspec));
-
- if (!JS_GetProperty (gexten->js_context, gexten->js_object,
- prop_name, &js_value))
- {
- g_warning ("Error: failed to get property '%s'", prop_name);
- }
- else if (!gjs_value_to_g_value (gexten->js_context, js_value, value))
- {
- g_warning ("Error: failed to convert jsval to "
- "GValue for property '%s'", prop_name);
- }
-
- g_free (prop_name);
-}
-
-static void
-peas_extension_gjs_dispose (GObject *object)
-{
- PeasExtensionGjs *gexten = PEAS_EXTENSION_GJS (object);
-
- if (gexten->js_context != NULL)
- {
- JS_RemoveObjectRoot (gexten->js_context, &gexten->js_object);
- gexten->js_context = NULL;
- gexten->js_object = NULL;
- }
-
- G_OBJECT_CLASS (peas_extension_gjs_parent_class)->dispose (object);
-}
-
-static gboolean
-set_out_arg (JSContext *js_context,
- GIFunctionInfo *func_info,
- gboolean is_return_value,
- GIArgInfo *arg_info,
- GITypeInfo *type_info,
- gpointer ptr,
- jsval js_value)
-{
- gboolean nullable;
- GITransfer transfer;
- GIArgument argument;
- GjsArgumentType arg_type;
-
- if (is_return_value)
- {
- arg_type = GJS_ARGUMENT_RETURN_VALUE;
- nullable = g_callable_info_may_return_null (func_info);
- transfer = g_callable_info_get_caller_owns (func_info);
- }
- else
- {
- arg_type = GJS_ARGUMENT_ARGUMENT;
- nullable = g_arg_info_may_be_null (arg_info);
- transfer = g_arg_info_get_ownership_transfer (arg_info);
- }
-
- if (!gjs_value_to_g_argument (js_context, js_value, type_info, NULL,
- arg_type, transfer, nullable, &argument))
- {
- if (is_return_value)
- {
- g_warning ("Error failed to convert return value to GIArgument");
- }
- else
- {
- g_warning ("Error failed to convert OUT argument '%s' from "
- "jsval to GIArgument", g_base_info_get_name (arg_info));
- }
-
- return FALSE;
- }
-
- peas_gi_argument_to_pointer (type_info, &argument, ptr);
-
- return TRUE;
-}
-
-static gboolean
-peas_extension_gjs_call (PeasExtensionWrapper *exten,
- GType exten_type,
- GICallableInfo *func_info,
- const gchar *method_name,
- GIArgument *args,
- GIArgument *retval)
-{
- PeasExtensionGjs *gexten = PEAS_EXTENSION_GJS (exten);
- gboolean success = FALSE;
- jsval js_method, js_retval;
- jsval *js_args;
- CachedArg *arg_cache;
- gint i, n_args, nth_out_arg;
- gint n_in_args = 0;
- gint n_out_args = 0;
- gint cached_args = 0;
-
- /* Fetch the JS method we want to call */
- if (!JS_GetProperty (gexten->js_context, gexten->js_object,
- method_name, &js_method) ||
- JSVAL_IS_VOID (js_method))
- {
- g_warning ("Method '%s.%s' was not found",
- g_type_name (exten_type), method_name);
- return FALSE;
- }
-
- if (JSVAL_IS_NULL (js_method) || !JSVAL_IS_OBJECT (js_method) ||
- !JS_ObjectIsFunction (gexten->js_context, JSVAL_TO_OBJECT (js_method)))
- {
- g_warning ("Method '%s.%s' in not a function",
- g_type_name (exten_type), method_name);
- return FALSE;
- }
-
- n_args = g_callable_info_get_n_args (func_info);
- if (n_args < 0)
- {
- g_warn_if_fail (n_args >= 0);
- return FALSE;
- }
-
- js_args = g_newa (jsval, n_args);
- arg_cache = g_newa (CachedArg, n_args + 1);
-
- /* Return value is an out arg */
- g_callable_info_load_return_type (func_info, &arg_cache[0].type_info);
- if (g_type_info_get_tag (&arg_cache[0].type_info) != GI_TYPE_TAG_VOID)
- {
- ++n_out_args;
- arg_cache[cached_args++].ptr = &retval->v_pointer;
- }
-
- /* Handle the arguments */
- for (i = 0; i < n_args; ++i, ++cached_args)
- {
- GIDirection direction;
-
- g_callable_info_load_arg (func_info, i, &arg_cache[cached_args].arg_info);
- direction = g_arg_info_get_direction (&arg_cache[cached_args].arg_info);
- g_arg_info_load_type (&arg_cache[cached_args].arg_info,
- &arg_cache[cached_args].type_info);
-
- if (direction == GI_DIRECTION_IN &&
- !gjs_value_from_g_argument (gexten->js_context, &js_args[n_in_args++],
- &arg_cache[cached_args].type_info,
- &args[i], TRUE))
- {
- g_warning ("Error failed to convert argument '%s'",
- g_base_info_get_name (&arg_cache[cached_args].arg_info));
- return FALSE;
- }
-
- if (direction == GI_DIRECTION_INOUT)
- {
- GIArgument arg;
-
- peas_gi_pointer_to_argument (&arg_cache[cached_args].type_info,
- args[i].v_pointer, &arg);
-
- if (!gjs_value_from_g_argument (gexten->js_context, &js_args[n_in_args++],
- &arg_cache[cached_args].type_info, &arg, TRUE))
- {
- g_warning ("Error failed to convert argument '%s'",
- g_base_info_get_name (&arg_cache[cached_args].arg_info));
- return FALSE;
- }
- }
-
- if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT)
- {
- ++n_out_args;
- arg_cache[cached_args].ptr = args[i].v_pointer;
- }
- }
-
- success = JS_CallFunctionValue (gexten->js_context, gexten->js_object,
- js_method, n_in_args, js_args, &js_retval);
-
- if (!success)
- {
- if (!gjs_log_exception (gexten->js_context))
- {
- g_warning ("Error while calling '%s.%s'",
- g_type_name (exten_type), method_name);
- }
-
- return FALSE;
- }
-
- /* First we need to release in argument */
- for (i = 0; i < cached_args; ++i)
- {
- GIDirection direction;
-
- /* First cached argument may be the return value */
- if (i == 0 && cached_args > n_args)
- continue;
-
- direction = g_arg_info_get_direction (&arg_cache[i].arg_info);
-
- if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT)
- {
- GITransfer transfer;
-
- transfer = g_arg_info_get_ownership_transfer (&arg_cache[i].arg_info);
-
- if (!gjs_g_argument_release_in_arg (gexten->js_context, transfer,
- &arg_cache[i].type_info,
- &args[i]))
- {
- g_warning ("Error failed to release IN argument '%s'",
- g_base_info_get_name (&arg_cache[i].arg_info));
- }
- }
- }
-
- /* Check that we have a valid return value */
- if (n_out_args > 1)
- {
- if (!JSVAL_IS_OBJECT (js_retval) ||
- !JS_IsArrayObject (gexten->js_context, JSVAL_TO_OBJECT (js_retval)))
- {
- g_warning ("Error return value is not an array");
- return FALSE;
- }
- }
-
- /* Set out arguments */
- for (i = 0, nth_out_arg = 0; i < cached_args && success; ++i)
- {
- gboolean is_return_value;
-
- is_return_value = i == 0 && cached_args > n_args;
-
- /* Return value does not have a GIArgInfo and is always out */
- if (!is_return_value)
- {
- GIDirection direction;
-
- direction = g_arg_info_get_direction (&arg_cache[i].arg_info);
-
- if (direction == GI_DIRECTION_IN)
- continue;
- }
-
- if (n_out_args == 1)
- {
- success = set_out_arg (gexten->js_context, func_info, is_return_value,
- &arg_cache[i].arg_info, &arg_cache[i].type_info,
- arg_cache[i].ptr, js_retval);
- break;
- }
- else if (n_out_args > 1)
- {
- jsval js_value;
-
- if (!JS_GetElement (gexten->js_context, JSVAL_TO_OBJECT (js_retval),
- nth_out_arg++, &js_value) ||
- JSVAL_IS_VOID (js_value))
- {
- g_warning ("Error failed to get out argument %i", nth_out_arg);
- return FALSE;
- }
- else
- {
- success = set_out_arg (gexten->js_context, func_info,
- is_return_value, &arg_cache[i].arg_info,
- &arg_cache[i].type_info, arg_cache[i].ptr,
- js_value);
- }
- }
- }
-
- return success;
-}
-
-static void
-peas_extension_gjs_class_init (PeasExtensionGjsClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- PeasExtensionWrapperClass *extension_class = PEAS_EXTENSION_WRAPPER_CLASS (klass);
-
- object_class->set_property = peas_extension_gjs_set_property;
- object_class->get_property = peas_extension_gjs_get_property;
- object_class->dispose = peas_extension_gjs_dispose;
-
- extension_class->call = peas_extension_gjs_call;
-}
-
-GObject *
-peas_extension_gjs_new (GType exten_type,
- GType *interfaces,
- JSContext *js_context,
- JSObject *js_object)
-{
- PeasExtensionGjs *gexten;
- GType real_type;
-
- g_return_val_if_fail (js_context != NULL, NULL);
- g_return_val_if_fail (js_object != NULL, NULL);
-
- real_type = peas_extension_register_subclass (PEAS_TYPE_EXTENSION_GJS,
- interfaces);
-
- /* Already Warned */
- if (real_type == G_TYPE_INVALID)
- {
- g_free (interfaces);
- return NULL;
- }
-
- gexten = PEAS_EXTENSION_GJS (g_object_new (real_type, NULL));
-
- gexten->js_context = js_context;
- gexten->js_object = js_object;
- PEAS_EXTENSION_WRAPPER (gexten)->exten_type = exten_type;
- PEAS_EXTENSION_WRAPPER (gexten)->interfaces = interfaces;
- JS_AddObjectRoot (gexten->js_context, &gexten->js_object);
-
- return G_OBJECT (gexten);
-}
diff --git a/loaders/gjs/peas-extension-gjs.h b/loaders/gjs/peas-extension-gjs.h
deleted file mode 100644
index 88fcf17..0000000
--- a/loaders/gjs/peas-extension-gjs.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * peas-extension-gjs.h
- * This file is part of libpeas
- *
- * Copyright (C) 2011 - Garrett Regier, Steve Frécinaux
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef __PEAS_EXTENSION_GJS_H__
-#define __PEAS_EXTENSION_GJS_H__
-
-#include <libpeas/peas-extension-wrapper.h>
-#include <gjs/gjs-module.h>
-
-G_BEGIN_DECLS
-
-#define PEAS_TYPE_EXTENSION_GJS (peas_extension_gjs_get_type ())
-#define PEAS_EXTENSION_GJS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEAS_TYPE_EXTENSION_GJS, PeasExtensionGjs))
-#define PEAS_EXTENSION_GJS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PEAS_TYPE_EXTENSION_GJS, PeasExtensionGjsClass))
-#define PEAS_IS_EXTENSION_GJS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEAS_TYPE_EXTENSION_GJS))
-#define PEAS_IS_EXTENSION_GJS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_EXTENSION_GJS))
-#define PEAS_EXTENSION_GJS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PEAS_TYPE_EXTENSION_GJS, PeasExtensionGjsClass))
-
-typedef struct _PeasExtensionGjs PeasExtensionGjs;
-typedef struct _PeasExtensionGjsClass PeasExtensionGjsClass;
-
-struct _PeasExtensionGjs {
- PeasExtensionWrapper parent;
-
- JSContext *js_context;
- JSObject *js_object;
-};
-
-struct _PeasExtensionGjsClass {
- PeasExtensionWrapperClass parent_class;
-};
-
-GType peas_extension_gjs_get_type (void) G_GNUC_CONST;
-
-GObject *peas_extension_gjs_new (GType exten_type,
- GType *interfaces,
- JSContext *js_context,
- JSObject *js_object);
-
-G_END_DECLS
-
-#endif /* __PEAS_EXTENSION_GJS_H__ */
diff --git a/loaders/gjs/peas-plugin-loader-gjs.c b/loaders/gjs/peas-plugin-loader-gjs.c
deleted file mode 100644
index 8cea724..0000000
--- a/loaders/gjs/peas-plugin-loader-gjs.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * peas-plugin-loader-gjs.c
- * This file is part of libpeas
- *
- * Copyright (C) 2011 - Garrett Regier, Steve Frécinaux
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <gjs/gjs-module.h>
-#include <gi/object.h>
-#include <gi/repo.h>
-#include <gi/value.h>
-
-#include <libpeas/peas-introspection.h>
-
-#include "peas-plugin-loader-gjs.h"
-#include "peas-extension-gjs.h"
-
-typedef struct {
- JSObject *extensions;
- GjsContext *context;
-} GjsInfo;
-
-G_DEFINE_TYPE (PeasPluginLoaderGjs, peas_plugin_loader_gjs, PEAS_TYPE_PLUGIN_LOADER);
-
-static gchar *
-get_script_filename_for_plugin_info (PeasPluginInfo *info)
-{
- gchar *basename;
- gchar *filename;
-
- basename = g_strconcat (peas_plugin_info_get_module_name (info), ".js", NULL);
- filename = g_build_filename (peas_plugin_info_get_module_dir (info), basename, NULL);
-
- g_free (basename);
-
- return filename;
-}
-
-static gboolean
-peas_plugin_loader_gjs_load (PeasPluginLoader *loader,
- PeasPluginInfo *info)
-{
- PeasPluginLoaderGjs *gloader = PEAS_PLUGIN_LOADER_GJS (loader);
- gchar **search_paths;
- const gchar *version;
- GjsContext *context;
- gchar *filename;
- GjsInfo *ginfo;
- GError *error = NULL;
- JSContext *js_context;
- JSObject *global;
- jsval extensions;
-
- filename = get_script_filename_for_plugin_info (info);
-
- g_debug ("GJS script filename is '%s'", filename);
-
- search_paths = g_new (gchar *, 2);
- search_paths[0] = g_strdup (peas_plugin_info_get_module_dir (info));
- search_paths[1] = NULL;
-
- version = gjs_context_scan_file_for_js_version (filename);
-
- context = g_object_new (GJS_TYPE_CONTEXT,
- "search-path", search_paths,
- "js-version", version,
- NULL);
-
- gjs_context_eval_file (context, filename, NULL, &error);
-
- g_strfreev (search_paths);
- g_free (filename);
-
- if (error != NULL)
- {
- g_warning ("Error: %s", error->message);
- g_error_free (error);
- g_object_unref (context);
- return FALSE;
- }
-
- js_context = gjs_context_get_native_context (context);
- global = JS_GetGlobalObject (js_context);
-
- if (!JS_GetProperty (js_context, global, "extensions", &extensions))
- {
- g_warning ("Error: could not find extensions");
- return FALSE;
- }
-
- if (!JSVAL_IS_OBJECT (extensions) || JSVAL_IS_NULL (extensions))
- {
- g_warning ("Error: 'extensions' is of invalid type '%s'",
- gjs_get_type_name (extensions));
- return FALSE;
- }
-
- ginfo = g_slice_new (GjsInfo);
- ginfo->context = g_object_ref (context);
- ginfo->extensions = JSVAL_TO_OBJECT (extensions);
- JS_AddObjectRoot (js_context, &ginfo->extensions);
-
- g_hash_table_insert (gloader->loaded_plugins, info, ginfo);
-
- g_object_unref (context);
-
- return TRUE;
-}
-
-static gboolean
-peas_plugin_loader_gjs_provides_extension (PeasPluginLoader *loader,
- PeasPluginInfo *info,
- GType exten_type)
-{
- PeasPluginLoaderGjs *gloader = PEAS_PLUGIN_LOADER_GJS (loader);
- GjsInfo *ginfo;
- JSContext *js_context;
- jsval extension;
-
- ginfo = g_hash_table_lookup (gloader->loaded_plugins, info);
-
- js_context = gjs_context_get_native_context (ginfo->context);
-
- return JS_GetProperty (js_context, ginfo->extensions,
- g_type_name (exten_type), &extension) &&
- JSVAL_IS_OBJECT (extension) && !JSVAL_IS_NULL (extension);
-}
-
-static void
-sort_interfaces (GArray *interfaces)
-{
- gint i;
-
- for (i = 0; i < interfaces->len; ++i)
- {
- gint j;
- GType *a = &g_array_index (interfaces, GType, i);
-
- for (j = i + 1; j < interfaces->len; ++j)
- {
- GType *b = &g_array_index (interfaces, GType, j);
-
- if (g_type_is_a (*a, *b))
- {
- GType temp = *a;
-
- *a = *b;
- *b = temp;
- }
- }
- }
-}
-
-static PeasExtension *
-peas_plugin_loader_gjs_create_extension (PeasPluginLoader *loader,
- PeasPluginInfo *info,
- GType exten_type,
- guint n_parameters,
- GParameter *parameters)
-{
- PeasPluginLoaderGjs *gloader = PEAS_PLUGIN_LOADER_GJS (loader);
- GjsInfo *ginfo;
- JSContext *js_context;
- jsval extension_ctor;
- JSObject *extension;
- guint i;
- jsval js_value;
- GValue gvalue = G_VALUE_INIT;
- GArray *interfaces;
- JSObject *prop_iter;
- jsid prop_name_id;
-
- ginfo = g_hash_table_lookup (gloader->loaded_plugins, info);
-
- js_context = gjs_context_get_native_context (ginfo->context);
-
- if (!JS_GetProperty (js_context, ginfo->extensions,
- g_type_name (exten_type), &extension_ctor) ||
- JSVAL_IS_VOID (extension_ctor) || JSVAL_IS_NULL (extension_ctor))
- return NULL;
-
- if (!JSVAL_IS_OBJECT (extension_ctor))
- {
- g_warning ("Extension '%s' in plugin '%s' in not a valid constructor object",
- g_type_name (exten_type),
- peas_plugin_info_get_module_name (info));
- return NULL;
- }
-
- /* Instantiate the extension ctor object to a new specific object. */
- extension = JS_New (js_context, JSVAL_TO_OBJECT (extension_ctor), 0, NULL);
-
- if (!extension)
- {
- 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;
- }
-
- /* Cannot use g_object_set_property()
- * because the property may be construct-only
- */
- for (i = 0; i < n_parameters; i++)
- {
- guint j;
- gchar *prop_name;
-
- prop_name = g_strdup (parameters[i].name);
- for (j = 0; prop_name[j] != '\0'; ++j)
- {
- if (prop_name[j] == '-')
- prop_name[j] = '_';
- }
-
- if (!gjs_value_from_g_value (js_context, &js_value, &parameters[i].value))
- {
- g_warning ("Error: failed to convert GValue to jsval for property '%s'", prop_name);
- }
- else if (!JS_SetProperty (js_context, extension, prop_name, &js_value))
- {
- g_warning ("Error: failed to set property '%s'", prop_name);
- }
-
- g_free (prop_name);
- }
-
-
- /* Set the plugin info as an attribute of the instance */
- g_value_init (&gvalue, PEAS_TYPE_PLUGIN_INFO);
- g_value_set_boxed (&gvalue, info);
-
- if (!gjs_value_from_g_value (js_context, &js_value, &gvalue))
- {
- g_warning ("Error: failed to convert PeasPluginInfo GValue to jsvalue");
- }
- else if (!JS_SetProperty (js_context, extension, "plugin_info", &js_value))
- {
- g_warning ("Error: failed to set property 'plugin_info'");
- }
-
- g_value_unset (&gvalue);
-
-
- /* Do not add exten_type as it will be added below */
- interfaces = g_array_new (TRUE, FALSE, sizeof (GType));
-
- prop_iter = JS_NewPropertyIterator (js_context, ginfo->extensions);
-
- /* If this returns FALSE then an error has occurred */
- while (JS_NextProperty (js_context, prop_iter, &prop_name_id))
- {
- jsval prop_extension_ctor;
- jsval prop_name_val;
- gchar *prop_name;
- GType the_type;
-
- /* No more properties to iterate over */
- if (prop_name_id == JSID_VOID)
- break;
-
- if (!JS_GetPropertyById (js_context, ginfo->extensions,
- prop_name_id, &prop_extension_ctor) ||
- JSVAL_TO_OBJECT (prop_extension_ctor) != JSVAL_TO_OBJECT (extension_ctor))
- continue;
-
- if (!JS_IdToValue (js_context, prop_name_id, &prop_name_val) ||
- !JSVAL_IS_STRING (prop_name_val) ||
- !gjs_string_to_utf8 (js_context, prop_name_val, &prop_name))
- {
- g_warning ("Invalid extension in plugin '%s' it is not a valid "
- "constructor object",
- peas_plugin_info_get_module_name (info));
- continue;
- }
-
- the_type = peas_gi_get_type_from_name (prop_name);
-
- if (the_type == G_TYPE_INVALID)
- {
- g_warning ("Could not find GType for '%s', "
- "did you forget to import it?", prop_name);
- }
- else
- {
- g_array_append_val (interfaces, the_type);
- }
-
- g_free (prop_name);
- }
-
- sort_interfaces (interfaces);
-
- return peas_extension_gjs_new (exten_type,
- (GType *) g_array_free (interfaces, FALSE),
- js_context, extension);
-}
-
-static void
-peas_plugin_loader_gjs_unload (PeasPluginLoader *loader,
- PeasPluginInfo *info)
-{
- PeasPluginLoaderGjs *gloader = PEAS_PLUGIN_LOADER_GJS (loader);
-
- g_hash_table_remove (gloader->loaded_plugins, info);
-}
-
-static void
-garbage_collect (PeasPluginInfo *info,
- GjsInfo *ginfo)
-{
- gjs_context_gc (ginfo->context);
-}
-
-static void
-peas_plugin_loader_gjs_garbage_collect (PeasPluginLoader *loader)
-{
- PeasPluginLoaderGjs *gloader = PEAS_PLUGIN_LOADER_GJS (loader);
-
- g_hash_table_foreach (gloader->loaded_plugins,
- (GHFunc) garbage_collect,
- NULL);
-}
-
-static void
-peas_plugin_loader_gjs_finalize (GObject *object)
-{
- PeasPluginLoaderGjs *gloader = PEAS_PLUGIN_LOADER_GJS (object);
-
- g_hash_table_destroy (gloader->loaded_plugins);
-
- G_OBJECT_CLASS (peas_plugin_loader_gjs_parent_class)->finalize (object);
-}
-
-static void
-peas_plugin_loader_gjs_class_init (PeasPluginLoaderGjsClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- PeasPluginLoaderClass *loader_class = PEAS_PLUGIN_LOADER_CLASS (klass);
-
- gobject_class->finalize = peas_plugin_loader_gjs_finalize;
-
- loader_class->load = peas_plugin_loader_gjs_load;
- loader_class->provides_extension = peas_plugin_loader_gjs_provides_extension;
- loader_class->create_extension = peas_plugin_loader_gjs_create_extension;
- loader_class->unload = peas_plugin_loader_gjs_unload;
- loader_class->garbage_collect = peas_plugin_loader_gjs_garbage_collect;
-}
-
-static void
-destroy_gjs_info (GjsInfo *ginfo)
-{
- JSContext *js_context;
-
- js_context = gjs_context_get_native_context (ginfo->context);
-
- JS_RemoveObjectRoot (js_context, &ginfo->extensions);
- g_object_unref (ginfo->context);
-
- g_slice_free (GjsInfo, ginfo);
-}
-
-static void
-peas_plugin_loader_gjs_init (PeasPluginLoaderGjs *gloader)
-{
- gloader->loaded_plugins = g_hash_table_new_full (g_direct_hash,
- g_direct_equal,
- NULL,
- (GDestroyNotify) destroy_gjs_info);
-}
-
-G_MODULE_EXPORT void
-peas_register_types (PeasObjectModule *module)
-{
- peas_object_module_register_extension_type (module,
- PEAS_TYPE_PLUGIN_LOADER,
- PEAS_TYPE_PLUGIN_LOADER_GJS);
-}
diff --git a/loaders/gjs/peas-plugin-loader-gjs.h b/loaders/gjs/peas-plugin-loader-gjs.h
deleted file mode 100644
index f717bf7..0000000
--- a/loaders/gjs/peas-plugin-loader-gjs.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * peas-plugin-loader-gjs.h
- * This file is part of libpeas
- *
- * Copyright (C) 2011 - Garrett Regier, Steve Frécinaux
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef __PEAS_PLUGIN_LOADER_GJS_H__
-#define __PEAS_PLUGIN_LOADER_GJS_H__
-
-#include <libpeas/peas-plugin-loader.h>
-#include <libpeas/peas-object-module.h>
-
-G_BEGIN_DECLS
-
-#define PEAS_TYPE_PLUGIN_LOADER_GJS (peas_plugin_loader_gjs_get_type ())
-#define PEAS_PLUGIN_LOADER_GJS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEAS_TYPE_PLUGIN_LOADER_GJS, PeasPluginLoaderGjs))
-#define PEAS_PLUGIN_LOADER_GJS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PEAS_TYPE_PLUGIN_LOADER_GJS, PeasPluginLoaderGjsClass))
-#define PEAS_IS_PLUGIN_LOADER_GJS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEAS_TYPE_PLUGIN_LOADER_GJS))
-#define PEAS_IS_PLUGIN_LOADER_GJS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_PLUGIN_LOADER_GJS))
-#define PEAS_PLUGIN_LOADER_GJS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PEAS_TYPE_PLUGIN_LOADER_GJS, PeasPluginLoaderGjsClass))
-
-typedef struct _PeasPluginLoaderGjs PeasPluginLoaderGjs;
-typedef struct _PeasPluginLoaderGjsClass PeasPluginLoaderGjsClass;
-
-struct _PeasPluginLoaderGjs {
- PeasPluginLoader parent;
-
- GHashTable *loaded_plugins;
-};
-
-struct _PeasPluginLoaderGjsClass {
- PeasPluginLoaderClass parent_class;
-};
-
-GType peas_plugin_loader_gjs_get_type (void) G_GNUC_CONST;
-G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
-
-G_END_DECLS
-
-#endif /* __PEAS_PLUGIN_LOADER_GJS_H__ */