[gjs: 1/2] object: Warn when setting a deprecated property



commit 8a9317192ead47606e4001c4704b5323da14955b
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Dec 16 14:29:12 2019 +0100

    object: Warn when setting a deprecated property
    
    GParamSpec allows marking properties as deprecated, which is not only
    an indication that the property will be removed at some point in the
    future, but may also mean that it has been turned into a no-op.
    
    In any case showing a warning seems appropriate.

 gi/object.cpp       | 4 ++++
 gjs/deprecation.cpp | 3 +++
 gjs/deprecation.h   | 1 +
 3 files changed, 8 insertions(+)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 8472f481..75b1dd58 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -50,6 +50,7 @@
 #include "gjs/atoms.h"
 #include "gjs/context-private.h"
 #include "gjs/context.h"
+#include "gjs/deprecation.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-util-args.h"
 #include "gjs/jsapi-util-root.h"
@@ -468,6 +469,9 @@ bool ObjectInstance::prop_setter_impl(JSContext* cx, JS::HandleString name,
         /* prevent setting the prop even in JS */
         return gjs_wrapper_throw_readonly_field(cx, gtype(), param_spec->name);
 
+    if (param_spec->flags & G_PARAM_DEPRECATED)
+        _gjs_warn_deprecated_once_per_callsite(cx, DeprecatedGObjectProperty);
+
     gjs_debug_jsprop(GJS_DEBUG_GOBJECT, "Setting GObject prop %s",
                      param_spec->name);
 
diff --git a/gjs/deprecation.cpp b/gjs/deprecation.cpp
index 4c8d889d..9fd95e84 100644
--- a/gjs/deprecation.cpp
+++ b/gjs/deprecation.cpp
@@ -45,6 +45,9 @@ const char* messages[] = {
     "preserved, but please fix your code anyway to explicitly call ByteArray"
     ".toString(array).\n"
     "(Note that array.toString() may have been called implicitly.)",
+
+    // DeprecatedGObjectProperty:
+    "Some code tried to set a deprecated GObject property.",
 };
 
 struct DeprecationEntry {
diff --git a/gjs/deprecation.h b/gjs/deprecation.h
index 14921972..e7eb5e00 100644
--- a/gjs/deprecation.h
+++ b/gjs/deprecation.h
@@ -29,6 +29,7 @@ struct JSContext;
 enum GjsDeprecationMessageId {
     None,
     ByteArrayInstanceToString,
+    DeprecatedGObjectProperty,
 };
 
 void _gjs_warn_deprecated_once_per_callsite(JSContext* cx,


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