Esempio n. 1
0
gboolean
gjs_context_define_string_array(GjsContext  *js_context,
                                const char    *array_name,
                                gssize         array_length,
                                const char   **array_values,
                                GError       **error)
{
    if (!gjs_define_string_array(js_context->context,
                                 js_context->global,
                                 array_name, array_length, array_values,
                                 JSPROP_READONLY | JSPROP_PERMANENT)) {
        char *message;

        message = NULL;
        gjs_log_exception(js_context->context, &message);
        if (message) {
            g_set_error(error,
                        GJS_ERROR,
                        GJS_ERROR_FAILED,
                        "%s", message);
            g_free(message);
        } else {
            message = "gjs_define_string_array() failed but no exception message?";
            gjs_debug(GJS_DEBUG_CONTEXT, "%s", message);
            g_set_error(error,
                        GJS_ERROR,
                        GJS_ERROR_FAILED,
                        "%s", message);
        }
        return FALSE;
    }

    return TRUE;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
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;
}