Esempio n. 1
0
/* 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;
}
Esempio n. 2
0
JSBool
gjs_define_byte_array_stuff(JSContext  *context,
                            JSObject  **module_out)
{
    JSObject *module;
    JSObject *prototype;

    module = JS_NewObject (context, NULL, NULL, NULL);

    prototype = JS_InitClass(context, module,
                             NULL,
                             &gjs_byte_array_class,
                             gjs_byte_array_constructor,
                             0,
                             &gjs_byte_array_proto_props[0],
                             &gjs_byte_array_proto_funcs[0],
                             NULL,
                             NULL);

    if (!JS_DefineFunctions(context, module, &gjs_byte_array_module_funcs[0]))
        return JS_FALSE;

    g_assert(JSVAL_IS_VOID(gjs_get_global_slot(context, GJS_GLOBAL_SLOT_BYTE_ARRAY_PROTOTYPE)));
    gjs_set_global_slot(context, GJS_GLOBAL_SLOT_BYTE_ARRAY_PROTOTYPE,
                        OBJECT_TO_JSVAL(prototype));

    *module_out = module;
    return JS_TRUE;
}
Esempio n. 3
0
static JSObject*
gjs_keep_alive_create(JSContext *context)
{
    JSObject *keep_alive;

    JS_BeginRequest(context);

    keep_alive = gjs_keep_alive_new(context);
    if (!keep_alive)
        g_error("could not create keep_alive on global object, no memory?");

    gjs_set_global_slot(context, GJS_GLOBAL_SLOT_KEEP_ALIVE, JS::ObjectValue(*keep_alive));

    JS_EndRequest(context);
    return keep_alive;
}