static JSBool fill_rectangle(JSContext *context, JSObject *obj, cairo_rectangle_int_t *rect) { jsval val; if (!gjs_object_get_property_const(context, obj, GJS_STRING_X, &val)) return JS_FALSE; if (!JS_ValueToInt32(context, val, &rect->x)) return JS_FALSE; if (!gjs_object_get_property_const(context, obj, GJS_STRING_Y, &val)) return JS_FALSE; if (!JS_ValueToInt32(context, val, &rect->y)) return JS_FALSE; if (!gjs_object_get_property_const(context, obj, GJS_STRING_WIDTH, &val)) return JS_FALSE; if (!JS_ValueToInt32(context, val, &rect->width)) return JS_FALSE; if (!gjs_object_get_property_const(context, obj, GJS_STRING_HEIGHT, &val)) return JS_FALSE; if (!JS_ValueToInt32(context, val, &rect->height)) return JS_FALSE; return JS_TRUE; }
static JSObject* gjs_lookup_param_prototype(JSContext *context) { JSObject *in_object; JSObject *constructor; jsid gobject_name; jsval value; gobject_name = gjs_intern_string_to_id(context, "GObject"); in_object = gjs_lookup_namespace_object_by_name(context, gobject_name); if (G_UNLIKELY (!in_object)) return NULL; if (!JS_GetProperty(context, in_object, "ParamSpec", &value)) return NULL; if (G_UNLIKELY (!JSVAL_IS_OBJECT(value) || JSVAL_IS_NULL(value))) return NULL; constructor = JSVAL_TO_OBJECT(value); g_assert(constructor != NULL); if (!gjs_object_get_property_const(context, constructor, GJS_STRING_PROTOTYPE, &value)) return NULL; if (G_UNLIKELY (!JSVAL_IS_OBJECT(value))) return NULL; return JSVAL_TO_OBJECT(value); }
static JSObject* module_get_parent(JSContext *context, JSObject *module_obj) { jsval value; if (gjs_object_get_property_const(context, module_obj, GJS_STRING_PARENT_MODULE, &value) && !JSVAL_IS_NULL(value) && JSVAL_IS_OBJECT(value)) { return JSVAL_TO_OBJECT(value); } else { return NULL; } }
static JSObject * gjs_lookup_fundamental_prototype(JSContext *context, GIObjectInfo *info, GType gtype) { JSObject *in_object; JSObject *constructor; const char *constructor_name; jsval value; if (info) { in_object = gjs_lookup_namespace_object(context, (GIBaseInfo*) info); constructor_name = g_base_info_get_name((GIBaseInfo*) info); } else { in_object = gjs_lookup_private_namespace(context); constructor_name = g_type_name(gtype); } if (G_UNLIKELY (!in_object)) return NULL; if (!JS_GetProperty(context, in_object, constructor_name, &value)) return NULL; if (JSVAL_IS_VOID(value)) { /* In case we're looking for a private type, and we don't find it, we need to define it first. */ gjs_define_fundamental_class(context, in_object, info, &constructor, NULL); } else { if (G_UNLIKELY (!JSVAL_IS_OBJECT(value) || JSVAL_IS_NULL(value))) return NULL; constructor = JSVAL_TO_OBJECT(value); } g_assert(constructor != NULL); if (!gjs_object_get_property_const(context, constructor, GJS_STRING_PROTOTYPE, &value)) return NULL; if (G_UNLIKELY (!JSVAL_IS_OBJECT(value))) return NULL; return JSVAL_TO_OBJECT(value); }