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; char **paths[2] = {0}; char **search_path; paths[0] = (char**)initial_search_path; if (add_standard_search_path) { /* Stick the "standard" shared search path after the provided one. */ paths[1] = (char**)gjs_get_search_path(); } search_path = gjs_g_strv_concat(paths, 2); importer = importer_new(context); /* API users can replace this property from JS, is the idea */ if (!gjs_define_string_array(context, importer, "searchPath", -1, (const char **)search_path, /* settable (no READONLY) but not deleteable (PERMANENT) */ JSPROP_PERMANENT | JSPROP_ENUMERATE)) gjs_fatal("no memory to define importer search path prop"); g_strfreev(search_path); if (!define_meta_properties(context, importer, importer_name, in_object)) gjs_fatal("failed to define meta properties on importer"); if (!JS_DefineProperty(context, in_object, importer_name, OBJECT_TO_JSVAL(importer), NULL, NULL, GJS_MODULE_PROP_FLAGS)) gjs_fatal("no memory to define importer property"); gjs_debug(GJS_DEBUG_IMPORTER, "Defined importer '%s' %p in %p", importer_name, importer, in_object); return importer; }
static JSObject* gjs_create_importer(JSContext *context, const std::string &importer_name, std::vector<std::string> &initial_search_path, bool add_standard_search_path, bool is_root, JSObject *in_object) { JSObject *importer; std::vector<std::string> paths[2]; std::vector<std::string> search_path; paths[0] = initial_search_path; if (add_standard_search_path) { /* Stick the "standard" shared search path after the provided one. */ paths[1] = gjs_get_search_path(); } for(auto p : paths) { search_path.insert(search_path.begin(), p.begin(), p.end()); } for(auto &s : search_path) std::cout << "search_path: " << s << "\n"; importer = importer_new(context, is_root); /* API users can replace this property from JS, is the idea */ if (!gjs_define_string_array(context, importer, "searchPath", search_path, /* settable (no READONLY) but not deleteable (PERMANENT) */ JSPROP_PERMANENT | JSPROP_ENUMERATE)) g_error("no memory to define importer search path prop"); if (!define_meta_properties(context, importer, NULL, importer_name, in_object)) g_error("failed to define meta properties on importer"); return importer; }
static JSObject* gjs_create_importer(JSContext *context, const char *importer_name, const char **initial_search_path, gboolean add_standard_search_path, gboolean is_root, JSObject *in_object) { JSObject *importer; char **paths[2] = {0}; char **search_path; paths[0] = (char**)initial_search_path; if (add_standard_search_path) { /* Stick the "standard" shared search path after the provided one. */ paths[1] = (char**)gjs_get_search_path(); } search_path = gjs_g_strv_concat(paths, 2); importer = importer_new(context, is_root); /* API users can replace this property from JS, is the idea */ if (!gjs_define_string_array(context, importer, "searchPath", -1, (const char **)search_path, /* settable (no READONLY) but not deleteable (PERMANENT) */ JSPROP_PERMANENT | JSPROP_ENUMERATE)) g_error("no memory to define importer search path prop"); g_strfreev(search_path); if (!define_meta_properties(context, importer, NULL, importer_name, in_object)) g_error("failed to define meta properties on importer"); return importer; }