summaryrefslogtreecommitdiff
path: root/gjs/bootstrap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gjs/bootstrap.cpp')
-rw-r--r--gjs/bootstrap.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/gjs/bootstrap.cpp b/gjs/bootstrap.cpp
index b049ec4b..406c26f5 100644
--- a/gjs/bootstrap.cpp
+++ b/gjs/bootstrap.cpp
@@ -26,9 +26,48 @@
#include <gjs/gjs.h>
#include "bootstrap.h"
+#include "native.h"
#include <gio/gio.h>
+/* The bootstrap process is the thing that sets up the import system.
+ * As such, we give it a hook to import any native modules it may need.
+ *
+ * The rest of the functionality that the bootstrap code needs should be
+ * in independent native modules which can be imported by this API,
+ * rather than in the bootstrap environment.
+ */
+
+static JSBool
+import_native_module(JSContext *context,
+ unsigned argc,
+ jsval *vp)
+{
+ JSBool ret = JS_FALSE;
+ JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+ char *module_name = NULL;
+ JSObject *module_obj;
+
+ if (!gjs_parse_call_args(context, "importNativeModule", "s", args,
+ "moduleName", &module_name))
+ goto out;
+
+ if (!gjs_import_native_module(context, module_name, &module_obj))
+ goto out;
+
+ ret = JS_TRUE;
+ args.rval().setObjectOrNull(module_obj);
+
+ out:
+ g_free(module_name);
+ return ret;
+}
+
+static JSFunctionSpec environment_funcs[] = {
+ { "importNativeModule", JSOP_WRAPPER (import_native_module), 1, GJS_MODULE_PROP_FLAGS },
+ { NULL },
+};
+
static gboolean
define_bootstrap_environment(JSContext *context,
JSObject **environment_out)
@@ -38,6 +77,9 @@ define_bootstrap_environment(JSContext *context,
if (!environment)
return FALSE;
+ if (!JS_DefineFunctions(context, environment, &environment_funcs[0]))
+ return FALSE;
+
*environment_out = environment;
return TRUE;
}