[gjs: 4/7] compat: Move native constructor macros
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 4/7] compat: Move native constructor macros
- Date: Thu, 22 Sep 2016 06:43:24 +0000 (UTC)
commit 941be0556faf34a2c917ca0ff1e4556f2dba3713
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 fbbc4b5..8f73a7d 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,
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 JS_FALSE; \
- } \
- object = gjs_new_object_for_constructor(context, &gjs_##name##_class, vp); \
- 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) \
- 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 JS_FALSE; \
- }
-
G_END_DECLS
#endif /* __GJS_COMPAT_H__ */
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index a22f1e0..ff6a6e9 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 JS_FALSE; \
+ } \
+ object = gjs_new_object_for_constructor(context, &gjs_##name##_class, vp); \
+ 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) \
+ 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 JS_FALSE; \
+ }
+
gboolean gjs_init_context_standard (JSContext *context,
JSObject **global_out);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]