/* If this were called twice for the same runtime with different args it * would basically be a bug, but checking for that is a lot of code so * we just ignore all calls after the first and hope the args are the same. */ JSBool gjs_create_root_importer(JSContext *context, const char **initial_search_path, gboolean add_standard_search_path) { jsval importer; JS_BeginRequest(context); importer = gjs_get_global_slot(context, GJS_GLOBAL_SLOT_IMPORTS); if (G_UNLIKELY (!JSVAL_IS_VOID(importer))) { gjs_debug(GJS_DEBUG_IMPORTER, "Someone else already created root importer, ignoring second request"); JS_EndRequest(context); return JS_TRUE; } importer = OBJECT_TO_JSVAL(gjs_create_importer(context, "imports", initial_search_path, add_standard_search_path, TRUE, NULL)); gjs_set_global_slot(context, GJS_GLOBAL_SLOT_IMPORTS, importer); JS_EndRequest(context); return JS_TRUE; }
JSObject* gjs_define_importer(JSContext *context, JSObject *in_object, const char *importer_name, const char **initial_search_path, gboolean add_standard_search_path) { JSObject *importer; importer = gjs_create_importer(context, importer_name, initial_search_path, add_standard_search_path, FALSE, in_object); if (!JS_DefineProperty(context, in_object, importer_name, OBJECT_TO_JSVAL(importer), NULL, NULL, GJS_MODULE_PROP_FLAGS)) g_error("no memory to define importer property"); gjs_debug(GJS_DEBUG_IMPORTER, "Defined importer '%s' %p in %p", importer_name, importer, in_object); return importer; }
JSObject* gjs_define_importer(JSContext *context, JSObject *in_object, const std::string &importer_name, std::vector<std::string> initial_search_path, bool add_standard_search_path) { JSObject *importer; importer = gjs_create_importer(context, importer_name, initial_search_path, add_standard_search_path, false, in_object); if (!JS_DefineProperty(context, in_object, importer_name.c_str(), OBJECT_TO_JSVAL(importer), NULL, NULL, GJS_MODULE_PROP_FLAGS)) g_error("no memory to define importer property"); gjs_debug(GJS_DEBUG_IMPORTER, "Defined importer '%s' %p in %p", importer_name, importer, in_object); return importer; }