Exemplo n.º 1
0
JSBool
gjs_define_root_importer(JSContext   *context,
                         JSObject    *in_object)
{
    jsval importer;
    JSBool success;
    jsid imports_name;

    success = JS_FALSE;
    JS_BeginRequest(context);

    importer = gjs_get_global_slot(context, GJS_GLOBAL_SLOT_IMPORTS);
    imports_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
                                                GJS_STRING_IMPORTS);
    if (!JS_DefinePropertyById(context, in_object,
                               imports_name, importer,
                               NULL, NULL,
                               GJS_MODULE_PROP_FLAGS)) {
        gjs_debug(GJS_DEBUG_IMPORTER, "DefineProperty imports on %p failed",
                  in_object);
        goto fail;
    }

    success = JS_TRUE;
 fail:
    JS_EndRequest(context);
    return success;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
JSObject*
gjs_keep_alive_get_global_if_exists (JSContext *context)
{
    JS::Value keep_alive;

    keep_alive = gjs_get_global_slot(context, GJS_GLOBAL_SLOT_KEEP_ALIVE);

    if (G_LIKELY (keep_alive.isObject()))
        return &keep_alive.toObject();

    return NULL;
}
Exemplo n.º 5
0
JSObject*
gjs_keep_alive_get_global_if_exists (JSContext *context)
{
    jsval keep_alive;

    keep_alive = gjs_get_global_slot(context, GJS_GLOBAL_SLOT_KEEP_ALIVE);

    if (G_LIKELY (JSVAL_IS_OBJECT(keep_alive)))
        return JSVAL_TO_OBJECT(keep_alive);
    
    return NULL;
}
Exemplo n.º 6
0
JSBool
gjs_define_root_importer(JSContext   *context,
                         JSObject    *in_object)
{
    JS::RootedValue importer(JS_GetRuntime(context),
                             gjs_get_global_slot(context, GJS_GLOBAL_SLOT_IMPORTS));
    JS::RootedObject rooted_in_object(JS_GetRuntime(context),
                                      in_object);
    JS::RootedObject rooted_importer(JS_GetRuntime(context),
                                     JSVAL_TO_OBJECT(importer));
    return gjs_define_root_importer_object(context,
                                           rooted_in_object,
                                           rooted_importer);
}
Exemplo n.º 7
0
/* Ensure that the module and class objects exists, and that in turn
 * ensures that JS_InitClass has been called. */
static JSObject *
byte_array_get_prototype(JSContext *context)
{
    jsval retval;
    JSObject *prototype;

    retval = gjs_get_global_slot (context, GJS_GLOBAL_SLOT_BYTE_ARRAY_PROTOTYPE);

    if (!JSVAL_IS_OBJECT (retval)) {
        if (!gjs_eval_with_scope(context, NULL,
                                 "imports.byteArray.ByteArray.prototype;", -1,
                                 "<internal>", &retval))
            g_error ("Could not import byte array prototype\n");
    }

    return JSVAL_TO_OBJECT(retval);
}