[gjs: 10/13] union: Warn when passing arguments to constructor



commit 2b97694218be0c7e3d147c3eea15eaad0698eb08
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Apr 20 15:10:03 2019 -0700

    union: Warn when passing arguments to constructor
    
    Constructors of gobject-introspected unions don't take any arguments.
    It's conceivable that someone might try to pass in some properties,
    expecting to be able to set one of fields of the union. In that case, we
    should warn that the arguments are being ignored.

 gi/union.cpp | 4 ++++
 1 file changed, 4 insertions(+)
---
diff --git a/gi/union.cpp b/gi/union.cpp
index 7c363f6b..87a16bf5 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -151,6 +151,10 @@ union_new(JSContext       *context,
 bool UnionInstance::constructor_impl(JSContext* context,
                                      JS::HandleObject object,
                                      const JS::CallArgs& args) {
+    if (args.length() > 0)
+        JS_ReportWarningASCII(context, "Arguments to constructor of %s ignored",
+                              name());
+
     /* union_new happens to be implemented by calling
      * gjs_invoke_c_function(), which returns a JS::Value.
      * The returned "gboxed" here is owned by that JS::Value,


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