[gjs/wip/ptomato/mozjs31prep: 5/5] compat: Move native constructor macros



commit 4edfe78c144c28d0f6758f710f0838fa02304a22
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Sep 18 11:13:53 2016 -0700

    compat: Move native constructor macros
    
    These macros are no longer protected by a jsapi.h version check, so they
    should be in jsapi-util.h with the other macros, rather than in compat.h.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742249

 gjs/compat.h     |   59 ------------------------------------------------------
 gjs/jsapi-util.h |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 59 deletions(-)
---
diff --git a/gjs/compat.h b/gjs/compat.h
index 8a3982f..b5bda6f 100644
--- a/gjs/compat.h
+++ b/gjs/compat.h
@@ -51,10 +51,6 @@ _Pragma("GCC diagnostic pop")
 
 G_BEGIN_DECLS
 
-/* This file inspects jsapi.h and attempts to provide a compatibility shim.
- * See https://bugzilla.gnome.org/show_bug.cgi?id=622896 for some initial discussion.
- */
-
 #define JSVAL_IS_OBJECT(obj) \
     _Pragma("GCC warning \"JSVAL_IS_OBJECT is deprecated. Use JS::Value::isObjectOrNull() instead.\"") \
     ((obj).isObjectOrNull())
@@ -70,61 +66,6 @@ JS_NewNumberValue(JSContext *cx, double d, JS::Value *rval)
         return rval->isNumber();
     }
 
-/**
- * GJS_NATIVE_CONSTRUCTOR_DECLARE:
- * Prototype a constructor.
- */
-#define GJS_NATIVE_CONSTRUCTOR_DECLARE(name)            \
-static JSBool                                           \
-gjs_##name##_constructor(JSContext  *context,           \
-                         unsigned    argc,              \
-                         JS::Value  *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;                                            \
-    JS::CallArgs argv G_GNUC_UNUSED = JS::CallArgsFromVp(argc, vp);
-
-/**
- * GJS_NATIVE_CONSTRUCTOR_PRELUDE:
- * Call after the initial variable declaration.
- */
-#define GJS_NATIVE_CONSTRUCTOR_PRELUDE(name)                            \
-    {                                                                   \
-        if (!JS_IsConstructing(context, vp)) {                          \
-            gjs_throw_constructor_error(context);                       \
-            return false;                                               \
-        }                                                               \
-        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
-        if (object == NULL)                                             \
-            return false;                                               \
-    }
-
-/**
- * GJS_NATIVE_CONSTRUCTOR_FINISH:
- * Call this at the end of a constructor when it's completed
- * successfully.
- */
-#define GJS_NATIVE_CONSTRUCTOR_FINISH(name)             \
-    argv.rval().setObject(*object);
-
-/**
- * GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT:
- * Defines a constructor whose only purpose is to throw an error
- * and fail. To be used with classes that require a constructor (because they have
- * instances), but whose constructor cannot be used from JS code.
- */
-#define GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(name)            \
-    GJS_NATIVE_CONSTRUCTOR_DECLARE(name)                        \
-    {                                                           \
-        gjs_throw_abstract_constructor_error(context, vp);      \
-        return false;                                           \
-    }
-
 G_END_DECLS
 
 #endif  /* __GJS_COMPAT_H__ */
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 3aa0d0e..363209a 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -202,6 +202,61 @@ JS::Value gjs_##cname##_create_proto(JSContext *context, JSObject *module, const
     return rval; \
 }
 
+/**
+ * GJS_NATIVE_CONSTRUCTOR_DECLARE:
+ * Prototype a constructor.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_DECLARE(name)            \
+static JSBool                                           \
+gjs_##name##_constructor(JSContext  *context,           \
+                         unsigned    argc,              \
+                         JS::Value  *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;                                            \
+    JS::CallArgs argv G_GNUC_UNUSED = JS::CallArgsFromVp(argc, vp);
+
+/**
+ * GJS_NATIVE_CONSTRUCTOR_PRELUDE:
+ * Call after the initial variable declaration.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_PRELUDE(name)                            \
+    {                                                                   \
+        if (!JS_IsConstructing(context, vp)) {                          \
+            gjs_throw_constructor_error(context);                       \
+            return false;                                               \
+        }                                                               \
+        object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
+        if (object == NULL)                                             \
+            return false;                                               \
+    }
+
+/**
+ * GJS_NATIVE_CONSTRUCTOR_FINISH:
+ * Call this at the end of a constructor when it's completed
+ * successfully.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_FINISH(name)             \
+    argv.rval().setObject(*object);
+
+/**
+ * GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT:
+ * Defines a constructor whose only purpose is to throw an error
+ * and fail. To be used with classes that require a constructor (because they have
+ * instances), but whose constructor cannot be used from JS code.
+ */
+#define GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(name)            \
+    GJS_NATIVE_CONSTRUCTOR_DECLARE(name)                        \
+    {                                                           \
+        gjs_throw_abstract_constructor_error(context, vp);      \
+        return false;                                           \
+    }
+
 bool        gjs_init_context_standard        (JSContext       *context,
                                               JSObject       **global_out);
 


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