--- a/gjs/gplugin-gjs-loader.cc Sun May 06 01:12:11 2018 -0500
+++ b/gjs/gplugin-gjs-loader.cc Sun May 06 15:37:54 2018 -0500
@@ -20,13 +20,9 @@
-#include <gjs/gjs-module.h>
/******************************************************************************
@@ -37,118 +33,18 @@
/******************************************************************************
*****************************************************************************/
-gplugin_gjs_loader_find_function(JSContext *jsctx, JSObject *parent,
- const gchar *name, GError **error)
+_gplugin_gjs_loader_eval_file(GjsContext *ctx, - jsval value = JSVAL_VOID;
- g_message("ctx: %p", jsctx);
- g_message("parent: %p", parent);
- g_message("name: %s", name);
- if(!JS_GetProperty(jsctx, parent, name, &value)) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "Failed to find the function '%s'", name);
- if(JSVAL_IS_VOID(value)) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0, "failed to find %s", name);
- if(JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value)) {
- return JS_ValueToFunction(jsctx, value);
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- "'%s' is not a function", name);
-_gplugin_gjs_loader_eval(GjsContext *ctx, JSObject **scope,
- const gchar *content, gsize content_length,
- const gchar *filename, gint *exit_code,
- JSContext *jsctx = NULL;
- JSObject *global = NULL;
- jsctx = (JSContext *)gjs_context_get_native_context(ctx);
- global = gjs_get_global_object(jsctx);
- JSAutoCompartment ac(jsctx, global);
- JSAutoRequest ar(jsctx);
- *scope = JS_NewObject(jsctx, NULL, NULL, NULL);
- if(!gjs_eval_with_scope(jsctx, *scope, content, content_length,
- gjs_log_exception(jsctx);
- g_set_error(error, GPLUGIN_DOMAIN, 0,
- "JS_EvaluateScript() failed");
+ if(!gjs_context_eval_file(ctx, filename, &exit_code, error)) {
- if(JSVAL_IS_INT(retval)) {
- if(JS_ValueToInt32(jsctx, retval, &ret_code)) {
-_gplugin_gjs_loader_eval_file(GjsContext *ctx, JSObject **scope,
- const char *filename, GError **error)
- gchar *contents = NULL;
- file = g_file_new_for_commandline_arg(filename);
- if(!g_file_query_exists(file, NULL)) {
- g_object_unref(G_OBJECT(file));
- if(!g_file_load_contents(file, NULL, &contents, &content_length, NULL, error)) {
- g_object_unref(G_OBJECT(file));
- ret = _gplugin_gjs_loader_eval(ctx, scope, contents, content_length,
- filename, NULL, error);
- g_object_unref(G_OBJECT(file));
/******************************************************************************
@@ -167,39 +63,23 @@
GPluginPluginInfo *info = NULL;
GjsContext *context = NULL;
- JSContext *jsctx = NULL;
- JSObject *scope = NULL, *jsobj = NULL;
- JSFunction *query = NULL;
+ JSObject *jsobj = NULL; context = gjs_context_new();
- if(!_gplugin_gjs_loader_eval_file(context, &scope, filename, error)) {
+ if(!_gplugin_gjs_loader_eval_file(context, filename, error)) { g_object_unref(G_OBJECT(context));
- /* grab our context since we're going to pass it to find_function */
- jsctx = (JSContext *)gjs_context_get_native_context(context);
- /* find the query function */
- // query = gplugin_gjs_loader_find_function(jsctx, scope, "gplugin_query",
+ cx = (JSContext*)gjs_context_get_native_context(context); - // g_message("query: %p", query);
- // g_object_unref(G_OBJECT(context));
- // g_message("querying plugin");
- JS::AutoValueVector argv(jsctx);
/* now call the query function */
- if(!JS_CallFunctionName(jsctx, scope, "gplugin_query", 0, argv.begin(), &value)) {
+ JS::RootedValue rval(cx); + JS::AutoValueArray<0> argv(cx); + if(!JS_CallFunctionName(cx, NULL, "gplugin_query", argv, &rval)) { *error = g_error_new(GPLUGIN_DOMAIN, 0,
"Failed to call the query function");
@@ -211,7 +91,7 @@
/* now grab the plugin info */
- if(!JS_ValueToObject(jsctx, value, &jsobj)) {
+ if(!JS_ValueToObject(cx, rval, &jsobj)) { *error = g_error_new(GPLUGIN_DOMAIN, 0,
"Query function did not return a GObject");
@@ -222,7 +102,7 @@
- gobj = gjs_g_object_from_object(jsctx, jsobj);
+ gobj = gjs_g_object_from_object(cx, jsobj); if(!GPLUGIN_IS_PLUGIN_INFO(gobj)) {
*error = g_error_new(GPLUGIN_DOMAIN, 0,
@@ -242,7 +122,6 @@
@@ -253,60 +132,8 @@
GPLUGIN_UNUSED GError **error)
- JSContext *jsctx = NULL;
- JSFunction *func = NULL;
- JSObject *global = NULL, *js_plugin = NULL;
- const gchar *func_name = (load) ? "gplugin_load" : "gplugin_unload";
- gchar *filename = NULL;
- g_object_get(G_OBJECT(plugin),
- func = gplugin_gjs_loader_find_function(jsctx, global, func_name, error);
- js_plugin = gjs_object_from_g_object(jsctx, G_OBJECT(plugin));
- args[0] = OBJECT_TO_JSVAL(js_plugin);
- if(!JS_CallFunction(jsctx, global, func, 1, args, &rval)) {
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- (load) ? "load" : "unload", filename);
- ret = JSVAL_TO_BOOLEAN(rval);
- *error = g_error_new(GPLUGIN_DOMAIN, 0,
- (load) ? "load" : "unload", filename);
+ *error = g_error_new(GPLUGIN_DOMAIN, 0, "unimplemented") --- a/gjs/gplugin-gjs-plugin.cc Sun May 06 01:12:11 2018 -0500
+++ b/gjs/gplugin-gjs-plugin.cc Sun May 06 15:37:54 2018 -0500
@@ -25,8 +25,6 @@
*****************************************************************************/
} GPluginGjsPluginPrivate;
/******************************************************************************
@@ -35,8 +33,6 @@
@@ -63,20 +59,6 @@
-gplugin_gjs_plugin_set_global_scope(GPluginGjsPlugin *plugin, JSObject *global) {
- GPluginGjsPluginPrivate *priv = GPLUGIN_GJS_PLUGIN_GET_PRIVATE(plugin);
-gplugin_gjs_plugin_set_js_context(GPluginGjsPlugin *plugin, JSContext *jsctx) {
- GPluginGjsPluginPrivate *priv = GPLUGIN_GJS_PLUGIN_GET_PRIVATE(plugin);
- priv->js_context = jsctx;
/******************************************************************************
*****************************************************************************/
@@ -90,14 +72,6 @@
g_value_set_object(value, gplugin_gjs_plugin_get_context(plugin));
- g_value_set_pointer(value,
- gplugin_gjs_plugin_get_global_scope(plugin));
- g_value_set_pointer(value,
- gplugin_gjs_plugin_get_js_context(plugin));
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
@@ -114,14 +88,6 @@
gplugin_gjs_plugin_set_context(plugin, (GjsContext*)g_value_get_object(value));
- gplugin_gjs_plugin_set_global_scope(plugin,
- (JSObject*)g_value_get_pointer(value));
- gplugin_gjs_plugin_set_js_context(plugin,
- (JSContext*)g_value_get_pointer(value));
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
@@ -156,18 +122,6 @@
(GParamFlags)(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
- g_object_class_install_property(obj_class, PROP_GLOBAL,
- g_param_spec_pointer("global", "global",
- "The global scope for this plugin",
- (GParamFlags)(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS)));
- g_object_class_install_property(obj_class, PROP_JS_CONTEXT,
- g_param_spec_pointer("js-context", "js-context",
- "The JSContext function for this plugin",
- (GParamFlags)(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS)));
/******************************************************************************
@@ -213,26 +167,3 @@
-gplugin_gjs_plugin_get_global_scope(const GPluginGjsPlugin *plugin) {
- GPluginGjsPluginPrivate *priv = NULL;
- g_return_val_if_fail(GPLUGIN_IS_GJS_PLUGIN(plugin), NULL);
- priv = GPLUGIN_GJS_PLUGIN_GET_PRIVATE(plugin);
-gplugin_gjs_plugin_get_js_context(const GPluginGjsPlugin *plugin) {
- GPluginGjsPluginPrivate *priv = NULL;
- g_return_val_if_fail(GPLUGIN_IS_GJS_PLUGIN(plugin), NULL);
- priv = GPLUGIN_GJS_PLUGIN_GET_PRIVATE(plugin);
- return priv->js_context;
--- a/gjs/gplugin-gjs-plugin.h Sun May 06 01:12:11 2018 -0500
+++ b/gjs/gplugin-gjs-plugin.h Sun May 06 15:37:54 2018 -0500
@@ -31,7 +31,7 @@
#include <gplugin-native.h>
-#include <gjs/gjs-module.h>
struct _GPluginGjsPlugin {
@@ -52,8 +52,6 @@
GType gplugin_gjs_plugin_get_type(void);
GjsContext *gplugin_gjs_plugin_get_context(const GPluginGjsPlugin *plugin);
-JSObject *gplugin_gjs_plugin_get_global_scope(const GPluginGjsPlugin *plugin);
-JSContext *gplugin_gjs_plugin_get_js_context(const GPluginGjsPlugin *plugin);
--- a/meson.build Sun May 06 01:12:11 2018 -0500
+++ b/meson.build Sun May 06 15:37:54 2018 -0500
@@ -3,7 +3,11 @@
###############################################################################
project('gplugin', 'c', version : '0.28.0dev',
meson_version : '>=0.37.0',
- default_options : ['c_std=c99'])
parts = meson.project_version().split('-')