[gjs/wip/xulrunner-2-rebase3: 6/6] [REBASE] More constructor porting



commit fa20939a46ee92b6e4d729b36650afaebf6c8cec
Author: Colin Walters <walters verbum org>
Date:   Thu Oct 21 19:10:23 2010 -0400

    [REBASE] More constructor porting
    
    We need to do a lot more in our fast constructor implementation to
    be strictly correct.  We're definitely not guaranteed to have a "this"
    object; if we don't, we need to make one.

 gi/boxed.c                      |    6 +++-
 gi/function.c                   |   52 ++++++++++++++++++++++++++++---------
 gi/keep-alive.c                 |    6 +++-
 gi/ns.c                         |    6 +++-
 gi/object.c                     |    6 +++-
 gi/param.c                      |    6 +++-
 gi/repo.c                       |    6 +++-
 gi/union.c                      |    6 +++-
 gjs/byteArray.c                 |    6 +++-
 gjs/compat.h                    |   53 +++++++++++++++++++++++++++++++-------
 gjs/importer.c                  |    6 +++-
 gjs/jsapi-util.c                |   23 +++--------------
 gjs/jsapi-util.h                |    2 +-
 modules/cairo-context.c         |    6 +++-
 modules/cairo-image-surface.c   |    6 +++-
 modules/cairo-linear-gradient.c |    6 +++-
 modules/cairo-pdf-surface.c     |    6 +++-
 modules/cairo-ps-surface.c      |    6 +++-
 modules/cairo-radial-gradient.c |    6 +++-
 modules/cairo-surface-pattern.c |    6 +++-
 modules/cairo-svg-surface.c     |    6 +++-
 modules/dbus-exports.c          |   10 ++++---
 22 files changed, 161 insertions(+), 81 deletions(-)
---
diff --git a/gi/boxed.c b/gi/boxed.c
index c76accb..70c108e 100644
--- a/gi/boxed.c
+++ b/gi/boxed.c
@@ -412,7 +412,7 @@ boxed_init(JSContext   *context,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(boxed)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(boxed)
     Boxed *priv;
     Boxed *proto_priv;
     JSClass *obj_class;
@@ -420,7 +420,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(boxed)
     JSObject *proto;
     gboolean is_proto;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(boxed);
 
     priv = g_slice_new0(Boxed);
 
@@ -542,6 +542,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(boxed)
         }
     }
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(boxed);
+
     return JS_TRUE;
 }
 
diff --git a/gi/function.c b/gi/function.c
index b32b859..d6b199a 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -755,37 +755,48 @@ release:
     }
 }
 
-#ifdef HAVE_JS_FAST_CONSTRUCTORS
+#ifdef JSFUN_CONSTRUCTOR
 static JSBool
 function_call(JSContext *context,
               uintN      js_argc,
               jsval     *vp)
 {
     jsval *js_argv = JS_ARGV(context, vp);
-    jsval *obj = JS_THIS_OBJECT(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);
+        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
@@ -796,24 +807,39 @@ 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_NewObject(context, &gjs_function_class, NULL, NULL);
+#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);
 
     return JS_TRUE;
 }
diff --git a/gi/keep-alive.c b/gi/keep-alive.c
index ed9fe82..87fb2f0 100644
--- a/gi/keep-alive.c
+++ b/gi/keep-alive.c
@@ -90,10 +90,10 @@ child_free(void *data)
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(keep_alive)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(keep_alive)
     KeepAlive *priv;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    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);
@@ -104,6 +104,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(keep_alive)
     gjs_debug_lifecycle(GJS_DEBUG_KEEP_ALIVE,
                         "keep_alive constructor, obj %p priv %p", object, priv);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(keep_alive);
+
     return JS_TRUE;
 }
 
diff --git a/gi/ns.c b/gi/ns.c
index 2833a1e..0eb474a 100644
--- a/gi/ns.c
+++ b/gi/ns.c
@@ -149,10 +149,10 @@ ns_new_resolve(JSContext *context,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(ns)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(ns)
     Ns *priv;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(ns);
 
     priv = g_slice_new0(Ns);
 
@@ -163,6 +163,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(ns)
 
     gjs_debug_lifecycle(GJS_DEBUG_GNAMESPACE, "ns constructor, obj %p priv %p", object, priv);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(ns);
+
     return JS_TRUE;
 }
 
diff --git a/gi/object.c b/gi/object.c
index 26380c9..a2284fd 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -617,7 +617,7 @@ wrapped_gobj_toggle_notify(gpointer      data,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(object_instance)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(object_instance)
     ObjectInstance *priv;
     ObjectInstance *proto_priv;
     JSObject *proto;
@@ -625,7 +625,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(object_instance)
     JSClass *obj_class;
     JSClass *proto_class;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(object_instance);
 
     priv = g_slice_new0(ObjectInstance);
 
@@ -766,6 +766,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(object_instance)
                                     g_base_info_get_name ( (GIBaseInfo*) priv->info) ));
     }
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(object_instance);
+
     return JS_TRUE;
 }
 
diff --git a/gi/param.c b/gi/param.c
index 1fae433..5c4c669 100644
--- a/gi/param.c
+++ b/gi/param.c
@@ -144,7 +144,7 @@ param_new_resolve(JSContext *context,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(param)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(param)
     Param *priv;
     Param *proto_priv;
     JSClass *obj_class;
@@ -152,7 +152,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(param)
     JSObject *proto;
     gboolean is_proto;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(param);
 
     priv = g_slice_new0(Param);
 
@@ -209,6 +209,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(param)
                   priv->gparam, g_type_name(G_TYPE_FROM_INSTANCE((GTypeInstance*) priv->gparam)));
     }
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(param);
+
     return JS_TRUE;
 }
 
diff --git a/gi/repo.c b/gi/repo.c
index c73f094..7d3bbbc 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -163,10 +163,10 @@ repo_new_resolve(JSContext *context,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(repo)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(repo)
     Repo *priv;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(repo);
 
     priv = g_slice_new0(Repo);
 
@@ -178,6 +178,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(repo)
     gjs_debug_lifecycle(GJS_DEBUG_GREPO,
                         "repo constructor, obj %p priv %p", object, priv);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(repo);
+
     return JS_TRUE;
 }
 
diff --git a/gi/union.c b/gi/union.c
index a909ab5..118cc88 100644
--- a/gi/union.c
+++ b/gi/union.c
@@ -203,7 +203,7 @@ union_new(JSContext   *context,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(union)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(union)
     Union *priv;
     Union *proto_priv;
     JSClass *obj_class;
@@ -211,7 +211,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(union)
     JSObject *proto;
     gboolean is_proto;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(union);
 
     priv = g_slice_new0(Union);
 
@@ -299,6 +299,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(union)
                             priv->gboxed, g_type_name(gtype));
     }
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(union);
+
     return JS_TRUE;
 }
 
diff --git a/gjs/byteArray.c b/gjs/byteArray.c
index d64cd9d..e4b47af 100644
--- a/gjs/byteArray.c
+++ b/gjs/byteArray.c
@@ -430,7 +430,7 @@ gjs_g_byte_array_new(int preallocated_length)
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(byte_array)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(byte_array)
     ByteArrayInstance *priv;
     JSObject *proto;
     gboolean is_proto;
@@ -438,7 +438,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(byte_array)
     JSClass *proto_class;
     gsize preallocated_length;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(byte_array);
 
     preallocated_length = 0;
     if (argc >= 1) {
@@ -470,6 +470,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(byte_array)
         priv->array = gjs_g_byte_array_new(preallocated_length);
     }
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(byte_array);
+
     return JS_TRUE;
 }
 
diff --git a/gjs/compat.h b/gjs/compat.h
index 48dd1c4..508bf79 100644
--- a/gjs/compat.h
+++ b/gjs/compat.h
@@ -70,20 +70,49 @@ G_BEGIN_DECLS
 /* All functions are "fast", so define this to a no-op */
 #define JSFUN_FAST_NATIVE 0
 
+/**
+ * GJS_NATIVE_CONSTRUCTOR_DECLARE:
+ * Prototype a constructor.
+ */
 #define GJS_NATIVE_CONSTRUCTOR_DECLARE(name)            \
 static JSBool                                           \
 gjs_##name##_constructor(JSContext  *context,           \
                          uintN       argc,              \
                          jsval      *vp)
 
-#define GJS_NATIVE_CONSTRUCTOR_VARIABLES                   \
-    JSObject *object = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)); \
+/**
+ * GJS_NATIVE_CONSTRUCTOR_VARIABLES:
+ * Declare variables necessary for the constructor; should
+ * be at the very top.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_VARIABLES(name)          \
+    JSObject *object = NULL;                            \
     jsval *argv = JS_ARGV(context, vp);
 
-#define GJS_NATIVE_CONSTRUCTOR_PRELUDE                  \
-    if (!gjs_check_constructing(context, vp))           \
-        return JS_FALSE
-
+/**
+ * GJS_NATIVE_CONSTRUCTOR_PRELUDE:
+ * Call after the initial variable declaration.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_PRELUDE(name)                                         \
+    {                                                                                \
+        if (!JS_IsConstructing_PossiblyWithGivenThisObject(context, vp, &object)) {  \
+            gjs_throw_constructor_error(context);                                    \
+            return JS_FALSE;                                                         \
+        }                                                                            \
+        if (object == NULL)                                                          \
+            object = JS_NewObject(context, &gjs_##name##_class, NULL, NULL);         \
+        if (object == NULL)                                                          \
+            return JS_FALSE;                                                         \
+    }
+
+
+/**
+ * GJS_NATIVE_CONSTRUCTOR_FINISH:
+ * Call this at the end of a constructor when it's completed
+ * successfully.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_FINISH(name)             \
+    JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(object));
 #else
 
 #define GJS_NATIVE_CONSTRUCTOR_DECLARE(name)            \
@@ -94,11 +123,15 @@ gjs_##name##_constructor(JSContext *context,            \
                          jsval     *argv,               \
                          jsval     *retval)
 
-#define GJS_NATIVE_CONSTRUCTOR_VARIABLES
+#define GJS_NATIVE_CONSTRUCTOR_VARIABLES(name)
+
+#define GJS_NATIVE_CONSTRUCTOR_PRELUDE(name)            \
+    if (!JS_IsConstructing(context)) {                  \
+        gjs_throw_constructor_error(context);           \
+        return JS_FALSE;                                \
+    }
 
-#define GJS_NATIVE_CONSTRUCTOR_PRELUDE                  \
-    if (!gjs_check_constructing(context, NULL))         \
-        return JS_FALSE
+#define GJS_NATIVE_CONSTRUCTOR_FINISH(name)
 
 #endif
 
diff --git a/gjs/importer.c b/gjs/importer.c
index 60f0855..9986b9b 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -958,10 +958,10 @@ importer_new_resolve(JSContext *context,
  */
 GJS_NATIVE_CONSTRUCTOR_DECLARE(importer)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(importer)
     Importer *priv;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(importer);
 
     priv = g_slice_new0(Importer);
 
@@ -973,6 +973,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(importer)
     gjs_debug_lifecycle(GJS_DEBUG_IMPORTER,
                         "importer constructor, obj %p priv %p", object, priv);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(importer);
+
     return JS_TRUE;
 }
 
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index df07446..4695ec0 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -566,26 +566,11 @@ gjs_init_class_dynamic(JSContext      *context,
     return NULL;
 }
 
-gboolean
-gjs_check_constructing(JSContext *context, jsval *vp)
+void
+gjs_throw_constructor_error(JSContext *context)
 {
-    gboolean constructing;
-
-    JS_BeginRequest(context);
-#ifdef JSFUN_CONSTRUCTOR
-    constructing = JS_IsConstructing(context, vp);
-#else
-    constructing = JS_IsConstructing(context);
-#endif
-    if (!constructing) {
-        JS_EndRequest(context);
-        gjs_throw(context,
-                  "Constructor called as normal method. Use 'new SomeObject()' not 'SomeObject()'");
-        return FALSE;
-    }
-
-    JS_EndRequest(context);
-    return TRUE;
+    gjs_throw(context,
+              "Constructor called as normal method. Use 'new SomeObject()' not 'SomeObject()'");
 }
 
 void*
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 90751ee..cdaa6d5 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -225,7 +225,7 @@ JSObject *  gjs_init_class_dynamic           (JSContext       *context,
                                               JSFunctionSpec  *fs,
                                               JSPropertySpec  *static_ps,
                                               JSFunctionSpec  *static_fs);
-gboolean    gjs_check_constructing           (JSContext       *context, jsval *vp);
+void gjs_throw_constructor_error             (JSContext       *context);
 
 void* gjs_get_instance_private_dynamic                (JSContext  *context,
                                                        JSObject   *obj,
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 37a324e..bc104ac 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -253,12 +253,12 @@ _gjs_cairo_context_construct_internal(JSContext *context,
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_context)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_context)
     JSObject *surface_wrapper;
     cairo_surface_t *surface;
     cairo_t *cr;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_context);
 
     if (!gjs_parse_args(context, "Context", "o", argc, argv,
                         "surface", &surface_wrapper))
@@ -278,6 +278,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_context)
     _gjs_cairo_context_construct_internal(context, object, cr);
     cairo_destroy(cr);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_context);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-image-surface.c b/modules/cairo-image-surface.c
index d2243cb..c2e587f 100644
--- a/modules/cairo-image-surface.c
+++ b/modules/cairo-image-surface.c
@@ -31,11 +31,11 @@ GJS_DEFINE_PROTO("CairoImageSurface", cairo_image_surface)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_image_surface)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_image_surface)
     int format, width, height;
     cairo_surface_t *surface;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_image_surface);
 
     // create_for_data optional parameter
     if (!gjs_parse_args(context, "ImageSurface", "iii", argc, argv,
@@ -52,6 +52,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_image_surface)
     gjs_cairo_surface_construct(context, object, surface);
     cairo_surface_destroy(surface);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_image_surface);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-linear-gradient.c b/modules/cairo-linear-gradient.c
index 277b851..74efc90 100644
--- a/modules/cairo-linear-gradient.c
+++ b/modules/cairo-linear-gradient.c
@@ -31,11 +31,11 @@ GJS_DEFINE_PROTO("CairoLinearGradient", cairo_linear_gradient)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_linear_gradient)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_linear_gradient)
     double x0, y0, x1, y1;
     cairo_pattern_t *pattern;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_linear_gradient);
 
     if (!gjs_parse_args(context, "LinearGradient", "ffff", argc, argv,
                         "x0", &x0,
@@ -52,6 +52,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_linear_gradient)
     gjs_cairo_pattern_construct(context, object, pattern);
     cairo_pattern_destroy(pattern);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_linear_gradient);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-pdf-surface.c b/modules/cairo-pdf-surface.c
index 65f0a53..6aca613 100644
--- a/modules/cairo-pdf-surface.c
+++ b/modules/cairo-pdf-surface.c
@@ -34,12 +34,12 @@ GJS_DEFINE_PROTO("CairoPDFSurface", cairo_pdf_surface)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_pdf_surface)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_pdf_surface)
     char *filename;
     double width, height;
     cairo_surface_t *surface;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_pdf_surface);
 
     if (!gjs_parse_args(context, "PDFSurface", "sff", argc, argv,
                         "filename", &filename,
@@ -59,6 +59,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_pdf_surface)
     cairo_surface_destroy(surface);
     g_free(filename);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_pdf_surface);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-ps-surface.c b/modules/cairo-ps-surface.c
index f932ab5..ca0fad4 100644
--- a/modules/cairo-ps-surface.c
+++ b/modules/cairo-ps-surface.c
@@ -34,12 +34,12 @@ GJS_DEFINE_PROTO("CairoPSSurface", cairo_ps_surface)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_ps_surface)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_ps_surface)
     char *filename;
     double width, height;
     cairo_surface_t *surface;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_ps_surface);
 
     if (!gjs_parse_args(context, "PSSurface", "sff", argc, argv,
                         "filename", &filename,
@@ -59,6 +59,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_ps_surface)
     cairo_surface_destroy(surface);
     g_free(filename);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_ps_surface);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-radial-gradient.c b/modules/cairo-radial-gradient.c
index 4a2127c..48f8b0b 100644
--- a/modules/cairo-radial-gradient.c
+++ b/modules/cairo-radial-gradient.c
@@ -31,11 +31,11 @@ GJS_DEFINE_PROTO("CairoRadialGradient", cairo_radial_gradient)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_radial_gradient)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_radial_gradient)
     double cx0, cy0, radius0, cx1, cy1, radius1;
     cairo_pattern_t *pattern;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_radial_gradient);
 
     if (!gjs_parse_args(context, "RadialGradient", "ffffff", argc, argv,
                         "cx0", &cx0,
@@ -54,6 +54,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_radial_gradient)
     gjs_cairo_pattern_construct(context, object, pattern);
     cairo_pattern_destroy(pattern);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_radial_gradient);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-surface-pattern.c b/modules/cairo-surface-pattern.c
index 7ea4042..8791e32 100644
--- a/modules/cairo-surface-pattern.c
+++ b/modules/cairo-surface-pattern.c
@@ -31,12 +31,12 @@ GJS_DEFINE_PROTO("CairoSurfacePattern", cairo_surface_pattern)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_surface_pattern)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_surface_pattern)
     JSObject *surface_wrapper;
     cairo_surface_t *surface;
     cairo_pattern_t *pattern;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_surface_pattern);
 
     if (!gjs_parse_args(context, "SurfacePattern", "o", argc, argv,
                         "surface", &surface_wrapper))
@@ -56,6 +56,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_surface_pattern)
     gjs_cairo_pattern_construct(context, object, pattern);
     cairo_pattern_destroy(pattern);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_surface_pattern);
+
     return JS_TRUE;
 }
 
diff --git a/modules/cairo-svg-surface.c b/modules/cairo-svg-surface.c
index 2aab384..6acc26c 100644
--- a/modules/cairo-svg-surface.c
+++ b/modules/cairo-svg-surface.c
@@ -34,12 +34,12 @@ GJS_DEFINE_PROTO("CairoSVGSurface", cairo_svg_surface)
 
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_svg_surface)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(cairo_svg_surface)
     char *filename;
     double width, height;
     cairo_surface_t *surface;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_svg_surface);
 
     if (!gjs_parse_args(context, "SVGSurface", "sff", argc, argv,
                         "filename", &filename,
@@ -59,6 +59,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_svg_surface)
     cairo_surface_destroy(surface);
     g_free(filename);
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(cairo_svg_surface);
+
     return JS_TRUE;
 }
 
diff --git a/modules/dbus-exports.c b/modules/dbus-exports.c
index f189069..bd86ac8 100644
--- a/modules/dbus-exports.c
+++ b/modules/dbus-exports.c
@@ -1685,12 +1685,12 @@ exports_new_resolve(JSContext *context,
  * identify the prototype as an object of our class with NULL private
  * data.
  */
-GJS_NATIVE_CONSTRUCTOR_DECLARE(exports)
+GJS_NATIVE_CONSTRUCTOR_DECLARE(js_exports)
 {
-    GJS_NATIVE_CONSTRUCTOR_VARIABLES
+    GJS_NATIVE_CONSTRUCTOR_VARIABLES(js_exports)
     Exports *priv;
 
-    GJS_NATIVE_CONSTRUCTOR_PRELUDE;
+    GJS_NATIVE_CONSTRUCTOR_PRELUDE(js_exports);
 
     priv = g_slice_new0(Exports);
 
@@ -1705,6 +1705,8 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(exports)
     priv->runtime = JS_GetRuntime(context);
     priv->object = object;
 
+    GJS_NATIVE_CONSTRUCTOR_FINISH(js_exports);
+
     return JS_TRUE;
 }
 
@@ -1823,7 +1825,7 @@ exports_new(JSContext  *context,
                                   * none - just name the prototype like
                                   * Math - rarely correct)
                                   */
-                                 gjs_exports_constructor,
+                                 gjs_js_exports_constructor,
                                  /* number of constructor args */
                                  0,
                                  /* props of prototype */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]