Exemple #1
0
void
gjs_closure_invoke(GClosure *closure,
                   int       argc,
                   jsval    *argv,
                   jsval    *retval)
{
    Closure *c;
    JSContext *context;
    JSObject *global;

    c = (Closure*) closure;

    check_context_valid(c);

    if (c->obj == NULL) {
        /* We were destroyed; become a no-op */
        c->context = NULL;
        return;
    }

    context = gjs_runtime_get_context(c->runtime);
    JS_BeginRequest(context);
    global = JS_GetGlobalObject(context);
    JSAutoCompartment ac(context, global);

    if (JS_IsExceptionPending(context)) {
        gjs_debug_closure("Exception was pending before invoking callback??? "
                          "Not expected");
        gjs_log_exception(context);
    }

    if (!gjs_call_function_value(context,
                                 NULL, /* "this" object; NULL is some kind of default presumably */
                                 OBJECT_TO_JSVAL(c->obj),
                                 argc,
                                 argv,
                                 retval)) {
        /* Exception thrown... */
        gjs_debug_closure("Closure invocation failed (exception should "
                          "have been thrown) closure %p callable %p",
                          closure, c->obj);
        if (!gjs_log_exception(context))
            gjs_debug_closure("Closure invocation failed but no exception was set?");
        goto out;
    }

    if (gjs_log_exception(context)) {
        gjs_debug_closure("Closure invocation succeeded but an exception was set");
    }

 out:
    JS_EndRequest(context);
}
Exemple #2
0
static JSBool
boxed_invoke_constructor(JSContext   *context,
                         JSObject    *obj,
                         const gchar *constructor_name,
                         unsigned     argc,
                         jsval       *argv,
                         jsval       *rval)
{
    jsval js_constructor, js_constructor_func;

    if (!gjs_object_require_property (context, obj, NULL, "constructor", &js_constructor))
        return JS_FALSE;

    if (!gjs_object_require_property (context, JSVAL_TO_OBJECT(js_constructor), NULL,
                                      constructor_name, &js_constructor_func))
        return JS_FALSE;

    return gjs_call_function_value (context, NULL, js_constructor_func, argc, argv, rval);
}