Split off the extension importing stuff into a new library, 'ShellJS'
This allows us to create a separate utility to import things from shell extensions that does not have the entire Shell stack built up https://bugzilla.gnome.org/show_bug.cgi?id=668429
This commit is contained in:
@ -1177,70 +1177,6 @@ shell_global_destroy_pointer_barrier (ShellGlobal *global, guint32 barrier)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shell_global_add_extension_importer:
|
||||
* @target_object_script: JavaScript code evaluating to a target object
|
||||
* @target_property: Name of property to use for importer
|
||||
* @directory: Source directory:
|
||||
* @error: A #GError
|
||||
*
|
||||
* This function sets a property named @target_property on the object
|
||||
* resulting from the evaluation of @target_object_script code, which
|
||||
* acts as a GJS importer for directory @directory.
|
||||
*
|
||||
* Returns: %TRUE on success
|
||||
*/
|
||||
gboolean
|
||||
shell_global_add_extension_importer (ShellGlobal *global,
|
||||
const char *target_object_script,
|
||||
const char *target_property,
|
||||
const char *directory,
|
||||
GError **error)
|
||||
{
|
||||
jsval target_object;
|
||||
JSContext *context = gjs_context_get_native_context (global->js_context);
|
||||
char *search_path[2] = { 0, 0 };
|
||||
|
||||
JS_BeginRequest (context);
|
||||
|
||||
// This is a bit of a hack; ideally we'd be able to pass our target
|
||||
// object directly into this function, but introspection doesn't
|
||||
// support that at the moment. Instead evaluate a string to get it.
|
||||
if (!JS_EvaluateScript(context,
|
||||
JS_GetGlobalObject(context),
|
||||
target_object_script,
|
||||
strlen (target_object_script),
|
||||
"<target_object_script>",
|
||||
0,
|
||||
&target_object))
|
||||
{
|
||||
char *message;
|
||||
gjs_log_exception(context,
|
||||
&message);
|
||||
g_set_error(error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"%s", message ? message : "(unknown)");
|
||||
g_free(message);
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (!JSVAL_IS_OBJECT (target_object))
|
||||
{
|
||||
g_error ("shell_global_add_extension_importer: invalid target object");
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
search_path[0] = (char*)directory;
|
||||
gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE);
|
||||
JS_EndRequest (context);
|
||||
return TRUE;
|
||||
out_error:
|
||||
JS_EndRequest (context);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Code to close all file descriptors before we exec; copied from gspawn.c in GLib.
|
||||
*
|
||||
* Authors: Padraig O'Briain, Matthias Clasen, Lennart Poettering
|
||||
|
Reference in New Issue
Block a user