[gjs: 25/26] wrapperutils: Move TypecheckNoThrow type out of template



commit a0e59bce694f72379c9a01d312f4f5c55207653b
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Mar 31 19:05:20 2019 -0700

    wrapperutils: Move TypecheckNoThrow type out of template
    
    Due to the TypecheckNoThrow type being defined inside the GIWrapper
    template, the compiler would consider e.g. ObjectBase::TypecheckNoThrow
    to be a different type than BoxedBase::TypecheckNoThrow. It's not
    really necessary to differentiate those types, so we move the type
    outside of the template.

 gi/arg.cpp        |  2 +-
 gi/gerror.cpp     | 13 ++++++-------
 gi/gerror.h       |  2 +-
 gi/interface.cpp  |  2 +-
 gi/object.h       |  2 +-
 gi/value.cpp      |  2 +-
 gi/wrapperutils.h |  8 ++++----
 7 files changed, 15 insertions(+), 16 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 9f980a7e..67265c1e 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1539,7 +1539,7 @@ static bool value_to_interface_gi_argument(JSContext* cx, JS::HandleValue value,
                 // Could be a GObject interface that's missing a prerequisite,
                 // or could be a fundamental
                 if (ObjectBase::typecheck(cx, obj, nullptr, gtype,
-                                          ObjectBase::TypecheckNoThrow())) {
+                                          GjsTypecheckNoThrow())) {
                     return ObjectBase::transfer_to_gi_argument(
                         cx, obj, arg, GI_DIRECTION_IN, transfer, gtype);
                 }
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index e3f43243..2d9ec9b8 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -132,7 +132,7 @@ bool ErrorBase::to_string(JSContext* context, unsigned argc, JS::Value* vp) {
     // An error created via `new GLib.Error` will have a Boxed* private pointer,
     // not an Error*, so we can't call regular to_string() on it.
     if (BoxedBase::typecheck(context, self, nullptr, G_TYPE_ERROR,
-                             BoxedBase::TypecheckNoThrow())) {
+                             GjsTypecheckNoThrow())) {
         auto* gerror = BoxedBase::to_c_ptr<GError>(context, self);
         if (!gerror)
             return false;
@@ -393,7 +393,7 @@ GError* ErrorBase::to_c_ptr(JSContext* cx, JS::HandleObject obj) {
        delegate marshalling.
     */
     if (BoxedBase::typecheck(cx, obj, nullptr, G_TYPE_ERROR,
-                             BoxedBase::TypecheckNoThrow()))
+                             GjsTypecheckNoThrow()))
         return BoxedBase::to_c_ptr<GError>(cx, obj);
 
     return GIWrapperBase::to_c_ptr<GError>(cx, obj);
@@ -431,15 +431,14 @@ bool ErrorBase::transfer_to_gi_argument(JSContext* cx, JS::HandleObject obj,
 // Overrides GIWrapperBase::typecheck()
 bool ErrorBase::typecheck(JSContext* cx, JS::HandleObject obj) {
     if (BoxedBase::typecheck(cx, obj, nullptr, G_TYPE_ERROR,
-                             BoxedBase::TypecheckNoThrow()))
+                             GjsTypecheckNoThrow()))
         return true;
     return GIWrapperBase::typecheck(cx, obj, nullptr, G_TYPE_ERROR);
 }
 
 bool ErrorBase::typecheck(JSContext* cx, JS::HandleObject obj,
-                          TypecheckNoThrow no_throw) {
-    if (BoxedBase::typecheck(cx, obj, nullptr, G_TYPE_ERROR,
-                             BoxedBase::TypecheckNoThrow()))
+                          GjsTypecheckNoThrow no_throw) {
+    if (BoxedBase::typecheck(cx, obj, nullptr, G_TYPE_ERROR, no_throw))
         return true;
     return GIWrapperBase::typecheck(cx, obj, nullptr, G_TYPE_ERROR, no_throw);
 }
@@ -448,7 +447,7 @@ GError *
 gjs_gerror_make_from_error(JSContext       *cx,
                            JS::HandleObject obj)
 {
-    if (ErrorBase::typecheck(cx, obj, ErrorBase::TypecheckNoThrow())) {
+    if (ErrorBase::typecheck(cx, obj, GjsTypecheckNoThrow())) {
         /* This is already a GError, just copy it */
         GError* inner = ErrorBase::to_c_ptr(cx, obj);
         if (!inner)
diff --git a/gi/gerror.h b/gi/gerror.h
index dfce2a9a..4e36032a 100644
--- a/gi/gerror.h
+++ b/gi/gerror.h
@@ -105,7 +105,7 @@ class ErrorBase
     static bool typecheck(JSContext* cx, JS::HandleObject obj);
     GJS_USE
     static bool typecheck(JSContext* cx, JS::HandleObject obj,
-                          TypecheckNoThrow);
+                          GjsTypecheckNoThrow);
 };
 
 class ErrorPrototype : public GIWrapperPrototype<ErrorBase, ErrorPrototype,
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 516c391d..2f9b9839 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -112,7 +112,7 @@ bool InterfacePrototype::has_instance_impl(JSContext* cx,
     g_assert(args[0].isObject());
     JS::RootedObject instance(cx, &args[0].toObject());
     bool isinstance = ObjectBase::typecheck(cx, instance, nullptr, m_gtype,
-                                            ObjectBase::TypecheckNoThrow());
+                                            GjsTypecheckNoThrow());
     args.rval().setBoolean(isinstance);
     return true;
 }
diff --git a/gi/object.h b/gi/object.h
index f8b90785..b7a4995c 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -130,7 +130,7 @@ class ObjectBase
     GJS_USE
     static bool typecheck(JSContext* cx, JS::HandleObject obj,
                           GIObjectInfo* expected_info, GType expected_gtype,
-                          TypecheckNoThrow no_throw) {
+                          GjsTypecheckNoThrow no_throw) {
         return GIWrapperBase::typecheck(cx, obj, expected_info, expected_gtype,
                                         no_throw);
     }
diff --git a/gi/value.cpp b/gi/value.cpp
index 18005985..75b53d2e 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -565,7 +565,7 @@ gjs_value_to_g_value_internal(JSContext      *context,
                 */
                 if (!gboxed) {
                     if (UnionBase::typecheck(context, obj, nullptr, gtype,
-                                             UnionBase::TypecheckNoThrow())) {
+                                             GjsTypecheckNoThrow())) {
                         gboxed = UnionBase::to_c_ptr(context, obj);
                     } else {
                         if (!BoxedBase::typecheck(context, obj, nullptr, gtype))
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 665333ee..42f8fb9b 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -55,6 +55,8 @@ namespace InfoType {
 enum Tag { Enum, Interface, Object, Struct };
 }
 
+struct GjsTypecheckNoThrow {};
+
 /*
  * gjs_define_static_methods:
  *
@@ -642,8 +644,6 @@ class GIWrapperBase {
 
     // Public typecheck API
 
-    struct TypecheckNoThrow {};
-
     /*
      * GIWrapperBase::typecheck:
      * @expected_info: (nullable): GI info to check
@@ -654,7 +654,7 @@ class GIWrapperBase {
      * the protptype; and that the instance's wrapped pointer is of the correct
      * GType or GI info.
      *
-     * The overload with a TypecheckNoThrow parameter will not throw a JS
+     * The overload with a GjsTypecheckNoThrow parameter will not throw a JS
      * exception if the prototype is passed in or the typecheck fails.
      */
     GJS_JSAPI_RETURN_CONVENTION
@@ -686,7 +686,7 @@ class GIWrapperBase {
     GJS_USE
     static bool typecheck(JSContext* cx, JS::HandleObject object,
                           GIBaseInfo* expected_info, GType expected_gtype,
-                          TypecheckNoThrow) {
+                          GjsTypecheckNoThrow) {
         Base* priv = Base::for_js(cx, object);
         if (!priv || priv->is_prototype())
             return false;


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