summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
Diffstat (limited to 'gi')
-rw-r--r--gi/boxed.c32
-rw-r--r--gi/function.c67
-rw-r--r--gi/keep-alive.c20
-rw-r--r--gi/ns.c20
-rw-r--r--gi/object.c35
-rw-r--r--gi/param.c25
-rw-r--r--gi/repo.c20
-rw-r--r--gi/union.c27
8 files changed, 134 insertions, 112 deletions
diff --git a/gi/boxed.c b/gi/boxed.c
index c0b504ce..5d67a528 100644
--- a/gi/boxed.c
+++ b/gi/boxed.c
@@ -405,13 +405,9 @@ boxed_init(JSContext *context,
* identify the prototype as an object of our class with NULL private
* data.
*/
-static JSBool
-boxed_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(boxed)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(boxed)
Boxed *priv;
Boxed *proto_priv;
JSClass *obj_class;
@@ -419,27 +415,26 @@ boxed_constructor(JSContext *context,
JSObject *proto;
gboolean is_proto;
- if (!gjs_check_constructing(context))
- return JS_FALSE;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(boxed);
priv = g_slice_new0(Boxed);
GJS_INC_COUNTER(boxed);
- JS_SetPrivate(context, obj, priv);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_GBOXED,
"boxed constructor, obj %p priv %p",
- obj, priv);
+ object, priv);
- proto = JS_GetPrototype(context, obj);
+ proto = JS_GetPrototype(context, object);
gjs_debug_lifecycle(GJS_DEBUG_GBOXED, "boxed instance __proto__ is %p", proto);
/* If we're constructing the prototype, its __proto__ is not the same
* class as us, but if we're constructing an instance, the prototype
* has the same class.
*/
- obj_class = JS_GET_CLASS(context, obj);
+ obj_class = JS_GET_CLASS(context, object);
proto_class = JS_GET_CLASS(context, proto);
is_proto = (obj_class != proto_class);
@@ -485,14 +480,15 @@ boxed_constructor(JSContext *context,
GType gtype = g_registered_type_info_get_g_type( (GIRegisteredTypeInfo*) priv->info);
if (gtype != G_TYPE_NONE) {
priv->gboxed = g_boxed_copy(gtype, source_priv->gboxed);
+ GJS_NATIVE_CONSTRUCTOR_FINISH(boxed);
return JS_TRUE;
}
}
- if (!boxed_new(context, obj, priv))
+ if (!boxed_new(context, object, priv))
return JS_FALSE;
- if (!boxed_init(context, obj, priv, argc, argv))
+ if (!boxed_init(context, object, priv, argc, argv))
return JS_FALSE;
} else if (!JSVAL_IS_NULL(unthreadsafe_template_for_constructor.parent_jsval)) {
@@ -504,7 +500,7 @@ boxed_constructor(JSContext *context,
/* We never actually read the reserved slot, but we put the parent object
* into it to hold onto the parent object.
*/
- JS_SetReservedSlot(context, obj, 0,
+ JS_SetReservedSlot(context, object, 0,
unthreadsafe_template_for_constructor.parent_jsval);
unthreadsafe_template_for_constructor.parent_jsval = JSVAL_NULL;
@@ -524,7 +520,7 @@ boxed_constructor(JSContext *context,
priv->gboxed = g_boxed_copy(gtype,
unthreadsafe_template_for_constructor.gboxed);
} else if (priv->can_allocate_directly) {
- if (!boxed_new_direct(context, obj, priv))
+ if (!boxed_new_direct(context, object, priv))
return JS_FALSE;
memcpy(priv->gboxed,
@@ -542,6 +538,8 @@ boxed_constructor(JSContext *context,
}
}
+ GJS_NATIVE_CONSTRUCTOR_FINISH(boxed);
+
return JS_TRUE;
}
@@ -1158,7 +1156,7 @@ gjs_define_boxed_class(JSContext *context,
* none - just name the prototype like
* Math - rarely correct)
*/
- boxed_constructor,
+ gjs_boxed_constructor,
/* number of constructor args (less can be passed) */
1,
/* props of prototype */
diff --git a/gi/function.c b/gi/function.c
index 4a4d2476..0404bdf1 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -755,32 +755,49 @@ release:
}
}
-/* this macro was introduced with JSFastNative in 2007 */
-#ifndef JS_ARGV_CALLEE
-#define JS_ARGV_CALLEE(argv) ((argv)[-2])
-#endif
-
+#ifdef JSFUN_CONSTRUCTOR
+static JSBool
+function_call(JSContext *context,
+ uintN js_argc,
+ jsval *vp)
+{
+ jsval *js_argv = JS_ARGV(context, vp);
+ JSObject *object = JS_THIS_OBJECT(context, vp);
+ JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(context, vp));
+ jsval retval;
+#else
static JSBool
function_call(JSContext *context,
- JSObject *obj, /* "this" object, not the function object */
+ JSObject *object, /* "this" object, not the function object */
uintN js_argc,
jsval *js_argv,
- jsval *rval)
+ jsval *retval)
{
+ JSObject *callee = JSVAL_TO_OBJECT(JS_ARGV_CALLEE(js_argv));
+#endif
+ JSBool success;
Function *priv;
- JSObject *callee;
-
- callee = JSVAL_TO_OBJECT(JS_ARGV_CALLEE(js_argv)); /* Callee is the Function object being called */
priv = priv_from_js(context, callee);
gjs_debug_marshal(GJS_DEBUG_GFUNCTION, "Call callee %p priv %p this obj %p %s", callee, priv,
obj, JS_GetTypeName(context,
- JS_TypeOfValue(context, OBJECT_TO_JSVAL(obj))));
+ JS_TypeOfValue(context, OBJECT_TO_JSVAL(object))));
if (priv == NULL)
return JS_TRUE; /* we are the prototype, or have the wrong class */
- return gjs_invoke_c_function(context, priv, obj, js_argc, js_argv, rval);
+
+#ifdef JSFUN_CONSTRUCTOR
+ {
+ jsval retval;
+ success = gjs_invoke_c_function(context, priv, object, js_argc, js_argv, &retval);
+ if (success)
+ JS_SET_RVAL(context, vp, retval);
+ }
+#else
+ success = gjs_invoke_c_function(context, priv, object, js_argc, js_argv, retval);
+#endif
+ return success;
}
/* If we set JSCLASS_CONSTRUCT_PROTOTYPE flag, then this is called on
@@ -791,24 +808,42 @@ function_call(JSContext *context,
* identify the prototype as an object of our class with NULL private
* data.
*/
+#ifdef JSFUN_CONSTRUCTOR
static JSBool
function_constructor(JSContext *context,
- JSObject *obj,
+ uintN argc,
+ jsval *vp)
+{
+ JSObject *object;
+ if (!JS_IsConstructing_PossiblyWithGivenThisObject(context, vp, &object)) {
+ gjs_throw_constructor_error(context);
+ return JS_FALSE;
+ }
+ if (object == NULL)
+ object = JS_NewObjectForConstructor(context, vp);
+#else
+static JSBool
+function_constructor(JSContext *context,
+ JSObject *object,
uintN argc,
jsval *argv,
jsval *retval)
{
+#endif
Function *priv;
priv = g_slice_new0(Function);
GJS_INC_COUNTER(function);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_GFUNCTION,
- "function constructor, obj %p priv %p", obj, priv);
+ "function constructor, obj %p priv %p", object, priv);
+#ifdef JSFUN_CONSTRUCTOR
+ JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(object));
+#endif
return JS_TRUE;
}
diff --git a/gi/keep-alive.c b/gi/keep-alive.c
index b20a5f6c..87fb2f01 100644
--- a/gi/keep-alive.c
+++ b/gi/keep-alive.c
@@ -88,23 +88,23 @@ child_free(void *data)
* identify the prototype as an object of our class with NULL private
* data.
*/
-static JSBool
-keep_alive_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(keep_alive)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(keep_alive)
KeepAlive *priv;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(keep_alive);
+
priv = g_slice_new0(KeepAlive);
priv->children = g_hash_table_new_full(child_hash, child_equal, NULL, child_free);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_KEEP_ALIVE,
- "keep_alive constructor, obj %p priv %p", obj, priv);
+ "keep_alive constructor, obj %p priv %p", object, priv);
+
+ GJS_NATIVE_CONSTRUCTOR_FINISH(keep_alive);
return JS_TRUE;
}
@@ -248,7 +248,7 @@ gjs_keep_alive_new(JSContext *context)
* none - just name the prototype like
* Math - rarely correct)
*/
- keep_alive_constructor,
+ gjs_keep_alive_constructor,
/* number of constructor args */
0,
/* props of prototype */
diff --git a/gi/ns.c b/gi/ns.c
index 1fe1720a..0eb474a0 100644
--- a/gi/ns.c
+++ b/gi/ns.c
@@ -147,23 +147,23 @@ ns_new_resolve(JSContext *context,
* identify the prototype as an object of our class with NULL private
* data.
*/
-static JSBool
-ns_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(ns)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(ns)
Ns *priv;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(ns);
+
priv = g_slice_new0(Ns);
GJS_INC_COUNTER(ns);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
+
+ gjs_debug_lifecycle(GJS_DEBUG_GNAMESPACE, "ns constructor, obj %p priv %p", object, priv);
- gjs_debug_lifecycle(GJS_DEBUG_GNAMESPACE, "ns constructor, obj %p priv %p", obj, priv);
+ GJS_NATIVE_CONSTRUCTOR_FINISH(ns);
return JS_TRUE;
}
@@ -247,7 +247,7 @@ ns_new(JSContext *context,
* none - just name the prototype like
* Math - rarely correct)
*/
- ns_constructor,
+ gjs_ns_constructor,
/* number of constructor args */
0,
/* props of prototype */
diff --git a/gi/object.c b/gi/object.c
index 3bbf0b63..a2284fd0 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -615,13 +615,9 @@ wrapped_gobj_toggle_notify(gpointer data,
* also, but can be replaced with another object to use instead as the
* prototype.
*/
-static JSBool
-object_instance_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(object_instance)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(object_instance)
ObjectInstance *priv;
ObjectInstance *proto_priv;
JSObject *proto;
@@ -629,29 +625,26 @@ object_instance_constructor(JSContext *context,
JSClass *obj_class;
JSClass *proto_class;
- if (!gjs_check_constructing(context))
- return JS_FALSE;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(object_instance);
priv = g_slice_new0(ObjectInstance);
GJS_INC_COUNTER(object);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_GOBJECT,
- "obj instance constructor, obj %p priv %p retval %p", obj, priv,
- JSVAL_IS_OBJECT(*retval) ?
- JSVAL_TO_OBJECT(*retval) : NULL);
+ "obj instance constructor, obj %p priv %p", object, priv);
- proto = JS_GetPrototype(context, obj);
+ proto = JS_GetPrototype(context, object);
gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "obj instance __proto__ is %p", proto);
/* If we're constructing the prototype, its __proto__ is not the same
* class as us, but if we're constructing an instance, the prototype
* has the same class.
*/
- obj_class = JS_GET_CLASS(context, obj);
+ obj_class = JS_GET_CLASS(context, object);
proto_class = JS_GET_CLASS(context, proto);
is_proto = (obj_class != proto_class);
@@ -700,7 +693,7 @@ object_instance_constructor(JSContext *context,
return JS_FALSE;
}
- if (!object_instance_props_to_g_parameters(context, obj, argc, argv,
+ if (!object_instance_props_to_g_parameters(context, object, argc, argv,
gtype,
&params, &n_params)) {
return JS_FALSE;
@@ -731,10 +724,10 @@ object_instance_constructor(JSContext *context,
}
g_assert(peek_js_obj(context, priv->gobj) == NULL);
- set_js_obj(context, priv->gobj, obj);
+ set_js_obj(context, priv->gobj, object);
#if DEBUG_DISPOSE
- g_object_weak_ref(priv->gobj, wrapped_gobj_dispose_notify, obj);
+ g_object_weak_ref(priv->gobj, wrapped_gobj_dispose_notify, object);
#endif
/* OK, here is where things get complicated. We want the
@@ -752,7 +745,7 @@ object_instance_constructor(JSContext *context,
gjs_keep_alive_add_child(context,
priv->keep_alive,
gobj_no_longer_kept_alive_func,
- obj,
+ object,
priv);
g_object_add_toggle_ref(priv->gobj,
@@ -773,6 +766,8 @@ object_instance_constructor(JSContext *context,
g_base_info_get_name ( (GIBaseInfo*) priv->info) ));
}
+ GJS_NATIVE_CONSTRUCTOR_FINISH(object_instance);
+
return JS_TRUE;
}
@@ -1375,7 +1370,7 @@ gjs_define_object_class(JSContext *context,
* none - just name the prototype like
* Math - rarely correct)
*/
- object_instance_constructor,
+ gjs_object_instance_constructor,
/* number of constructor args */
0,
/* props of prototype */
diff --git a/gi/param.c b/gi/param.c
index ae413675..5c4c669b 100644
--- a/gi/param.c
+++ b/gi/param.c
@@ -142,13 +142,9 @@ param_new_resolve(JSContext *context,
* identify the prototype as an object of our class with NULL private
* data.
*/
-static JSBool
-param_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(param)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(param)
Param *priv;
Param *proto_priv;
JSClass *obj_class;
@@ -156,27 +152,26 @@ param_constructor(JSContext *context,
JSObject *proto;
gboolean is_proto;
- if (!gjs_check_constructing(context))
- return JS_FALSE;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(param);
priv = g_slice_new0(Param);
GJS_INC_COUNTER(param);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_GPARAM,
- "param constructor, obj %p priv %p", obj, priv);
+ "param constructor, obj %p priv %p", object, priv);
- proto = JS_GetPrototype(context, obj);
+ proto = JS_GetPrototype(context, object);
gjs_debug_lifecycle(GJS_DEBUG_GPARAM, "param instance __proto__ is %p", proto);
/* If we're constructing the prototype, its __proto__ is not the same
* class as us, but if we're constructing an instance, the prototype
* has the same class.
*/
- obj_class = JS_GET_CLASS(context, obj);
+ obj_class = JS_GET_CLASS(context, object);
proto_class = JS_GET_CLASS(context, proto);
is_proto = (obj_class != proto_class);
@@ -214,6 +209,8 @@ param_constructor(JSContext *context,
priv->gparam, g_type_name(G_TYPE_FROM_INSTANCE((GTypeInstance*) priv->gparam)));
}
+ GJS_NATIVE_CONSTRUCTOR_FINISH(param);
+
return JS_TRUE;
}
@@ -345,7 +342,7 @@ gjs_define_param_class(JSContext *context,
* none - just name the prototype like
* Math - rarely correct)
*/
- param_constructor,
+ gjs_param_constructor,
/* number of constructor args */
0,
/* props of prototype */
diff --git a/gi/repo.c b/gi/repo.c
index 9ce76bcd..7d3bbbc5 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -161,24 +161,24 @@ repo_new_resolve(JSContext *context,
* identify the prototype as an object of our class with NULL private
* data.
*/
-static JSBool
-repo_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(repo)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(repo)
Repo *priv;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(repo);
+
priv = g_slice_new0(Repo);
GJS_INC_COUNTER(repo);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_GREPO,
- "repo constructor, obj %p priv %p", obj, priv);
+ "repo constructor, obj %p priv %p", object, priv);
+
+ GJS_NATIVE_CONSTRUCTOR_FINISH(repo);
return JS_TRUE;
}
@@ -254,7 +254,7 @@ repo_new(JSContext *context)
* none - just name the prototype like
* Math - rarely correct)
*/
- repo_constructor,
+ gjs_repo_constructor,
/* number of constructor args */
0,
/* props of prototype */
diff --git a/gi/union.c b/gi/union.c
index 13442ba0..118cc880 100644
--- a/gi/union.c
+++ b/gi/union.c
@@ -201,13 +201,9 @@ union_new(JSContext *context,
* identify the prototype as an object of our class with NULL private
* data.
*/
-static JSBool
-union_constructor(JSContext *context,
- JSObject *obj,
- uintN argc,
- jsval *argv,
- jsval *retval)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(union)
{
+ GJS_NATIVE_CONSTRUCTOR_VARIABLES(union)
Union *priv;
Union *proto_priv;
JSClass *obj_class;
@@ -215,28 +211,27 @@ union_constructor(JSContext *context,
JSObject *proto;
gboolean is_proto;
- if (!gjs_check_constructing(context))
- return JS_FALSE;
+ GJS_NATIVE_CONSTRUCTOR_PRELUDE(union);
priv = g_slice_new0(Union);
GJS_INC_COUNTER(boxed);
- g_assert(priv_from_js(context, obj) == NULL);
- JS_SetPrivate(context, obj, priv);
+ g_assert(priv_from_js(context, object) == NULL);
+ JS_SetPrivate(context, object, priv);
gjs_debug_lifecycle(GJS_DEBUG_GBOXED,
"union constructor, obj %p priv %p",
- obj, priv);
+ object, priv);
- proto = JS_GetPrototype(context, obj);
+ proto = JS_GetPrototype(context, object);
gjs_debug_lifecycle(GJS_DEBUG_GBOXED, "union instance __proto__ is %p", proto);
/* If we're constructing the prototype, its __proto__ is not the same
* class as us, but if we're constructing an instance, the prototype
* has the same class.
*/
- obj_class = JS_GET_CLASS(context, obj);
+ obj_class = JS_GET_CLASS(context, object);
proto_class = JS_GET_CLASS(context, proto);
is_proto = (obj_class != proto_class);
@@ -283,7 +278,7 @@ union_constructor(JSContext *context,
* The returned "gboxed" here is owned by that jsval,
* not by us.
*/
- gboxed = union_new(context, obj, priv->info);
+ gboxed = union_new(context, object, priv->info);
if (gboxed == NULL) {
return JS_FALSE;
@@ -304,6 +299,8 @@ union_constructor(JSContext *context,
priv->gboxed, g_type_name(gtype));
}
+ GJS_NATIVE_CONSTRUCTOR_FINISH(union);
+
return JS_TRUE;
}
@@ -488,7 +485,7 @@ gjs_define_union_class(JSContext *context,
* none - just name the prototype like
* Math - rarely correct)
*/
- union_constructor,
+ gjs_union_constructor,
/* number of constructor args */
0,
/* props of prototype */