1044
1049
ObjectInstance *priv;
1047
/* DO NOT use priv_from_js here: that uses JS_BeginRequest,
1048
but this is called from the GC thread, and deadlocks
1049
We know we're of the right JSClass anyway.
1051
priv = JS_GetPrivate(tracer->context, obj);
1052
priv = priv_from_js(tracer->context, obj);
1053
1054
for (iter = priv->signals; iter; iter = iter->next) {
1054
1055
ConnectData *cd = iter->data;
1162
1168
ConnectData *connect_data;
1163
1169
JSBool ret = JS_FALSE;
1171
if (!do_base_typecheck(context, obj, JS_TRUE))
1165
1174
priv = priv_from_js(context, obj);
1166
1175
gjs_debug_gsignal("connect obj %p priv %p argc %d", obj, priv, argc);
1167
1176
if (priv == NULL) {
1261
1270
ObjectInstance *priv;
1273
if (!do_base_typecheck(context, obj, JS_TRUE))
1264
1276
priv = priv_from_js(context, obj);
1265
1277
gjs_debug_gsignal("disconnect obj %p priv %p argc %d", obj, priv, argc);
1312
1324
JSBool ret = JS_FALSE;
1326
if (!do_base_typecheck(context, obj, JS_TRUE))
1314
1329
priv = priv_from_js(context, obj);
1315
1330
gjs_debug_gsignal("emit obj %p priv %p argc %d", obj, priv, argc);
1718
1736
g_assert(gjs_object_has_property(context, in_object, constructor_name));
1738
GJS_INC_COUNTER(object);
1720
1739
priv = g_slice_new0(ObjectInstance);
1721
1740
priv->info = info;
1723
1742
g_base_info_ref( (GIBaseInfo*) priv->info);
1724
1743
priv->gtype = gtype;
1744
priv->klass = g_type_class_ref (gtype);
1725
1745
JS_SetPrivate(context, prototype, priv);
1727
1747
gjs_debug(GJS_DEBUG_GOBJECT, "Defined class %s prototype %p class %p in object %p",
1886
1906
priv = priv_from_js(context, obj);
1890
"Object instance or prototype has not been properly initialized yet. "
1891
"Did you forget to chain-up from _init()?");
1895
if (priv->gobj == NULL) {
1897
"Object is %s.%s.prototype, not an object instance - cannot convert to GObject*",
1898
priv->info ? g_base_info_get_namespace( (GIBaseInfo*) priv->info) : "",
1899
priv->info ? g_base_info_get_name( (GIBaseInfo*) priv->info) : g_type_name(priv->gtype));
1903
1907
return priv->gobj;
1911
gjs_typecheck_object(JSContext *context,
1913
GType expected_type,
1916
ObjectInstance *priv;
1919
if (!do_base_typecheck(context, object, throw))
1922
priv = priv_from_js(context, object);
1927
"Object instance or prototype has not been properly initialized yet. "
1928
"Did you forget to chain-up from _init()?");
1934
if (priv->gobj == NULL) {
1937
"Object is %s.%s.prototype, not an object instance - cannot convert to GObject*",
1938
priv->info ? g_base_info_get_namespace( (GIBaseInfo*) priv->info) : "",
1939
priv->info ? g_base_info_get_name( (GIBaseInfo*) priv->info) : g_type_name(priv->gtype));
1945
g_assert(priv->gtype == G_OBJECT_TYPE(priv->gobj));
1947
if (expected_type != G_TYPE_NONE)
1948
result = g_type_is_a (priv->gtype, expected_type);
1952
if (!result && throw) {
1954
gjs_throw_custom(context, "TypeError",
1955
"Object is of type %s.%s - cannot convert to %s",
1956
g_base_info_get_namespace((GIBaseInfo*) priv->info),
1957
g_base_info_get_name((GIBaseInfo*) priv->info),
1958
g_type_name(expected_type));
1960
gjs_throw_custom(context, "TypeError",
1961
"Object is of type %s - cannot convert to %s",
1962
g_type_name(priv->gtype),
1963
g_type_name(expected_type));
1907
1972
find_vfunc_info (JSContext *context,
1908
1973
GType implementor_gtype,
2193
2261
JSObject *parent, *constructor;
2194
2262
GType instance_type, parent_type;
2195
2263
GTypeQuery query;
2264
GTypeModule *type_module;
2196
2265
ObjectInstance *parent_priv;
2197
2266
GTypeInfo type_info = {
2198
2267
0, /* class_size */
2231
2303
type_info.class_size = query.class_size;
2232
2304
type_info.instance_size = query.instance_size;
2234
instance_type = g_type_register_static(parent_type,
2306
type_module = G_TYPE_MODULE (gjs_type_module_get());
2307
instance_type = g_type_module_register_type(type_module,
2268
2342
"gtype", &iface_jsobj))
2269
2343
return JS_FALSE;
2345
if (!do_base_typecheck(cx, object, JS_TRUE))
2271
2348
priv = priv_from_js(cx, object);
2273
2350
g_type_add_interface_static(priv->gtype,
2299
2375
obj = JSVAL_TO_OBJECT(argv[0]);
2300
2376
pspec_js = JSVAL_TO_OBJECT(argv[1]);
2378
if (!do_base_typecheck(cx, obj, JS_TRUE))
2380
if (!gjs_typecheck_param(cx, pspec_js, G_TYPE_NONE, JS_TRUE))
2302
2383
priv = priv_from_js(cx, obj);
2303
2384
pspec = gjs_g_param_from_param(cx, pspec_js);
2305
2386
g_param_spec_set_qdata(pspec, gjs_is_custom_property_quark(), GINT_TO_POINTER(1));
2307
oclass = g_type_class_ref(priv->gtype);
2308
g_object_class_install_property(oclass, PROP_JS_HANDLED, pspec);
2309
g_type_class_unref(oclass);
2388
g_object_class_install_property(G_OBJECT_CLASS (priv->klass), PROP_JS_HANDLED, pspec);
2311
2390
JS_SET_RVAL(cx, vp, JSVAL_VOID);
2312
2391
return JS_TRUE;
2340
2419
obj = JSVAL_TO_OBJECT(argv[0]);
2420
if (!do_base_typecheck(cx, obj, JS_TRUE)) {
2341
2425
priv = priv_from_js(cx, obj);
2343
2427
/* we only support standard accumulators for now */