static JSBool getGroupTarget_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JSObject *obj = JSVAL_TO_OBJECT(rec.thisv()); cairo_t *cr; cairo_surface_t *surface; JSObject *surface_wrapper; if (argc > 0) { gjs_throw(context, "Context.getGroupTarget() takes no arguments"); return JS_FALSE; } cr = gjs_cairo_context_get_context(context, obj); surface = cairo_get_group_target(cr); if (!gjs_cairo_check_status(context, cairo_status(cr), "context")) return JS_FALSE; /* surface belongs to the context, so keep the reference */ surface_wrapper = gjs_cairo_surface_from_surface(context, surface); if (!surface_wrapper) { /* exception already set */ return JS_FALSE; } rec.rval().set(OBJECT_TO_JSVAL(surface_wrapper)); return JS_TRUE; }
static JSBool getSource_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JSObject *obj = JSVAL_TO_OBJECT(rec.thisv()); cairo_t *cr; cairo_pattern_t *pattern; JSObject *pattern_wrapper; if (argc > 0) { gjs_throw(context, "Context.getSource() takes no arguments"); return JS_FALSE; } cr = gjs_cairo_context_get_context(context, obj); pattern = cairo_get_source(cr); if (!gjs_cairo_check_status(context, cairo_status(cr), "context")) return JS_FALSE; /* pattern belongs to the context, so keep the reference */ pattern_wrapper = gjs_cairo_pattern_from_pattern(context, pattern); if (!pattern_wrapper) { gjs_throw(context, "failed to create pattern"); return JS_FALSE; } rec.rval().set(OBJECT_TO_JSVAL(pattern_wrapper)); return JS_TRUE; }
static JSBool dispose_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JSObject *obj = JSVAL_TO_OBJECT(rec.thisv()); GjsCairoContext *priv; priv = priv_from_js(context, obj); if (priv->cr != NULL) { cairo_destroy(priv->cr); priv->cr = NULL; } rec.rval().set(JSVAL_VOID); return JS_TRUE; }
static JSBool to_string_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JSObject *obj = JSVAL_TO_OBJECT(rec.thisv()); FundamentalInstance *priv; JSBool ret = JS_FALSE; jsval retval; if (!priv_from_js_with_typecheck(context, obj, &priv)) goto out; if (!priv->prototype) { Fundamental *proto_priv = (Fundamental *) priv; if (!_gjs_proxy_to_string_func(context, obj, "fundamental", (GIBaseInfo *) proto_priv->info, proto_priv->gtype, proto_priv->gfundamental, &retval)) goto out; } else { if (!_gjs_proxy_to_string_func(context, obj, "fundamental", (GIBaseInfo *) priv->prototype->info, priv->prototype->gtype, priv->gfundamental, &retval)) goto out; } ret = JS_TRUE; rec.rval().set(retval); out: return ret; }
static JSBool to_gbytes_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JSObject *object = JSVAL_TO_OBJECT(rec.thisv()); ByteArrayInstance *priv; JSObject *ret_bytes_obj; GIBaseInfo *gbytes_info; priv = priv_from_js(context, object); if (priv == NULL) return JS_TRUE; /* prototype, not instance */ byte_array_ensure_gbytes(priv); gbytes_info = g_irepository_find_by_gtype(NULL, G_TYPE_BYTES); ret_bytes_obj = gjs_boxed_from_c_struct(context, (GIStructInfo*)gbytes_info, priv->bytes, GJS_BOXED_CREATION_NONE); rec.rval().set(OBJECT_TO_JSVAL(ret_bytes_obj)); return JS_TRUE; }