[gjs: 1/5] gjs: Define once GCPolicy instead of repeating it all over the places




commit 1865c62944f8fb3e503982899b4c95f69dc1c9c7
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Thu May 6 18:34:52 2021 +0200

    gjs: Define once GCPolicy instead of repeating it all over the places
    
    We are redefining the gc policy in multiple places while we can just it
    once in the jsapi util header and include it when it's not the case

 gjs/atoms.cpp                     |  8 +-------
 gjs/context-private.h             | 19 -------------------
 gjs/deprecation.cpp               |  8 +-------
 gjs/jsapi-util-string.cpp         |  7 -------
 gjs/jsapi-util.h                  | 17 ++++++++++++++++-
 gjs/objectbox.cpp                 |  2 +-
 gjs/stack.cpp                     |  7 -------
 modules/cairo-context.cpp         |  7 -------
 modules/cairo-gradient.cpp        |  7 -------
 modules/cairo-image-surface.cpp   |  7 -------
 modules/cairo-linear-gradient.cpp |  4 ----
 modules/cairo-path.cpp            |  7 -------
 modules/cairo-pdf-surface.cpp     |  4 ----
 modules/cairo-ps-surface.cpp      |  4 ----
 modules/cairo-radial-gradient.cpp |  5 +----
 modules/cairo-solid-pattern.cpp   |  7 -------
 modules/cairo-surface-pattern.cpp |  7 -------
 modules/cairo-svg-surface.cpp     |  4 ----
 modules/cairo.cpp                 |  7 -------
 modules/print.cpp                 |  7 -------
 20 files changed, 20 insertions(+), 125 deletions(-)
---
diff --git a/gjs/atoms.cpp b/gjs/atoms.cpp
index 9ff286f1..ce8c125c 100644
--- a/gjs/atoms.cpp
+++ b/gjs/atoms.cpp
@@ -7,7 +7,6 @@
 
 #include <config.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/Id.h>
 #include <js/RootingAPI.h>
 #include <js/Symbol.h>
@@ -16,12 +15,7 @@
 #include <jsapi.h>  // for JS_AtomizeAndPinString
 
 #include "gjs/atoms.h"
-
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
+#include "gjs/jsapi-util.h"  // IWYU pragma: keep
 
 bool GjsAtom::init(JSContext* cx, const char* str) {
     JSString* s = JS_AtomizeAndPinString(cx, str);
diff --git a/gjs/context-private.h b/gjs/context-private.h
index 3a771719..bcd99e57 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -12,7 +12,6 @@
 
 #include <atomic>
 #include <string>
-#include <type_traits>  // for is_same
 #include <unordered_map>
 #include <vector>
 
@@ -20,7 +19,6 @@
 #include <glib.h>
 
 #include <js/GCHashTable.h>
-#include <js/GCPolicyAPI.h>
 #include <js/GCVector.h>
 #include <js/HashTable.h>  // for DefaultHasher
 #include <js/Promise.h>
@@ -53,23 +51,6 @@ using GTypeTable =
     JS::GCHashMap<GType, JS::Heap<JSObject*>, js::DefaultHasher<GType>,
                   js::SystemAllocPolicy>;
 
-struct Dummy {};
-using GTypeNotUint64 =
-    std::conditional_t<!std::is_same_v<GType, uint64_t>, GType, Dummy>;
-
-// The GC sweep method should ignore FundamentalTable and GTypeTable's key types
-namespace JS {
-// Forward declarations
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-// We need GCPolicy<GType> for GTypeTable. SpiderMonkey already defines
-// GCPolicy<uint64_t> which is equal to GType on some systems; for others we
-// need to define it. (macOS's uint64_t is unsigned long long, which is a
-// different type from unsigned long, even if they are the same width)
-template <>
-struct GCPolicy<GTypeNotUint64> : public IgnoreGCPolicy<GTypeNotUint64> {};
-}  // namespace JS
-
 class GjsContextPrivate : public JS::JobQueue {
     GjsContext* m_public_context;
     JSContext* m_cx;
diff --git a/gjs/deprecation.cpp b/gjs/deprecation.cpp
index f48f87d9..3fdd64d4 100644
--- a/gjs/deprecation.cpp
+++ b/gjs/deprecation.cpp
@@ -15,7 +15,6 @@
 
 #include <js/CharacterEncoding.h>
 #include <js/Conversions.h>
-#include <js/GCPolicyAPI.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <js/Utility.h>  // for UniqueChars
@@ -24,14 +23,9 @@
 #include <jsfriendapi.h>  // for FormatStackDump
 
 #include "gjs/deprecation.h"
+#include "gjs/jsapi-util.h"  // IWYU pragma: keep
 #include "gjs/macros.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 const char* messages[] = {
     // None:
     "(invalid message)",
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 5fc1164a..5b681005 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -20,7 +20,6 @@
 #include <js/Class.h>
 #include <js/ComparisonOperators.h>
 #include <js/GCAPI.h>  // for AutoCheckCannotGC
-#include <js/GCPolicyAPI.h>
 #include <js/Id.h>     // for JSID_IS_STRING...
 #include <js/Promise.h>
 #include <js/RootingAPI.h>
@@ -36,12 +35,6 @@
 #include "gjs/macros.h"
 #include "util/misc.h"  // for _gjs_memdup2
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 class JSLinearString;
 
 GjsAutoChar gjs_hyphen_to_underscore(const char* str) {
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 4e399f25..9af700f1 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -32,7 +32,22 @@
 class JSErrorReport;
 namespace JS {
 class CallArgs;
-}
+
+struct Dummy {};
+using GTypeNotUint64 =
+    std::conditional_t<!std::is_same_v<GType, uint64_t>, GType, Dummy>;
+
+// The GC sweep method should ignore FundamentalTable and GTypeTable's key types
+// Forward declarations
+template <>
+struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
+// We need GCPolicy<GType> for GTypeTable. SpiderMonkey already defines
+// GCPolicy<uint64_t> which is equal to GType on some systems; for others we
+// need to define it. (macOS's uint64_t is unsigned long long, which is a
+// different type from unsigned long, even if they are the same width)
+template <>
+struct GCPolicy<GTypeNotUint64> : public IgnoreGCPolicy<GTypeNotUint64> {};
+}  // namespace JS
 
 struct GjsAutoTakeOwnership {};
 
diff --git a/gjs/objectbox.cpp b/gjs/objectbox.cpp
index 2ad6cddc..82984703 100644
--- a/gjs/objectbox.cpp
+++ b/gjs/objectbox.cpp
@@ -10,7 +10,7 @@
 
 #include <js/AllocPolicy.h>
 #include <js/ComparisonOperators.h>
-#include <js/GCPolicyAPI.h>
+#include <js/GCPolicyAPI.h>  // for GCPolicy (ptr only), NonGCPointe...
 #include <js/GCVector.h>
 #include <js/RootingAPI.h>
 #include <js/TracingAPI.h>
diff --git a/gjs/stack.cpp b/gjs/stack.cpp
index cdf56915..a223ad0d 100644
--- a/gjs/stack.cpp
+++ b/gjs/stack.cpp
@@ -9,19 +9,12 @@
 #include <glib-object.h>
 #include <glib.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/TypeDecls.h>
 #include <jsfriendapi.h>  // for DumpBacktrace
 
 #include "gjs/context.h"
 #include "gjs/jsapi-util.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 void
 gjs_context_print_stack_stderr(GjsContext *context)
 {
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index f1d12b23..696af554 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -13,7 +13,6 @@
 #include <js/Array.h>  // for JS::NewArrayObject
 #include <js/CallArgs.h>
 #include <js/Conversions.h>
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -32,12 +31,6 @@
 #include "gjs/macros.h"
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 #define _GJS_CAIRO_CONTEXT_GET_PRIV_CR_CHECKED(cx, argc, vp, argv, obj) \
     GJS_GET_THIS(cx, argc, vp, argv, obj);                              \
     cairo_t* cr;                                                        \
diff --git a/modules/cairo-gradient.cpp b/modules/cairo-gradient.cpp
index c8491ae8..07c29328 100644
--- a/modules/cairo-gradient.cpp
+++ b/modules/cairo-gradient.cpp
@@ -7,7 +7,6 @@
 #include <cairo.h>
 
 #include <js/CallArgs.h>
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -20,12 +19,6 @@
 #include "gjs/macros.h"
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 JSObject* CairoGradient::new_proto(JSContext* cx, JSProtoKey) {
     JS::RootedObject parent_proto(cx, CairoPattern::prototype(cx));
     return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
diff --git a/modules/cairo-image-surface.cpp b/modules/cairo-image-surface.cpp
index 6bb5aefa..1ec8da4b 100644
--- a/modules/cairo-image-surface.cpp
+++ b/modules/cairo-image-surface.cpp
@@ -7,7 +7,6 @@
 #include <cairo.h>
 
 #include <js/CallArgs.h>
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -20,12 +19,6 @@
 #include "gjs/macros.h"
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 JSObject* CairoImageSurface::new_proto(JSContext* cx, JSProtoKey) {
     JS::RootedObject parent_proto(cx, CairoSurface::prototype(cx));
     return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
diff --git a/modules/cairo-linear-gradient.cpp b/modules/cairo-linear-gradient.cpp
index 45b8fb17..13842396 100644
--- a/modules/cairo-linear-gradient.cpp
+++ b/modules/cairo-linear-gradient.cpp
@@ -6,7 +6,6 @@
 
 #include <cairo.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -19,9 +18,6 @@
 
 namespace JS {
 class CallArgs;
-// Avoid static_assert in MSVC builds
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
 }
 
 JSObject* CairoLinearGradient::new_proto(JSContext* cx, JSProtoKey) {
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index 3216aacb..a4a82725 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -8,7 +8,6 @@
 #include <cairo.h>
 #include <glib.h>  // for g_assert
 
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -17,12 +16,6 @@
 
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 // clang-format off
 const JSPropertySpec CairoPath::proto_props[] = {
     JS_STRING_SYM_PS(toStringTag, "Path", JSPROP_READONLY),
diff --git a/modules/cairo-pdf-surface.cpp b/modules/cairo-pdf-surface.cpp
index add65a1c..77c9d71e 100644
--- a/modules/cairo-pdf-surface.cpp
+++ b/modules/cairo-pdf-surface.cpp
@@ -8,7 +8,6 @@
 #include <cairo-features.h>  // for CAIRO_HAS_PDF_SURFACE
 #include <cairo.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/TypeDecls.h>
 
 #include "gjs/jsapi-util.h"
@@ -27,9 +26,6 @@
 
 namespace JS {
 class CallArgs;
-// Avoid static_assert in MSVC builds
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
 }
 
 JSObject* CairoPDFSurface::new_proto(JSContext* cx, JSProtoKey) {
diff --git a/modules/cairo-ps-surface.cpp b/modules/cairo-ps-surface.cpp
index 5da8b787..fc75774f 100644
--- a/modules/cairo-ps-surface.cpp
+++ b/modules/cairo-ps-surface.cpp
@@ -8,7 +8,6 @@
 #include <cairo-features.h>  // for CAIRO_HAS_PS_SURFACE
 #include <cairo.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/TypeDecls.h>
 
 #include "gjs/jsapi-util.h"
@@ -27,9 +26,6 @@
 
 namespace JS {
 class CallArgs;
-// Avoid static_assert in MSVC builds
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
 }
 
 JSObject* CairoPSSurface::new_proto(JSContext* cx, JSProtoKey) {
diff --git a/modules/cairo-radial-gradient.cpp b/modules/cairo-radial-gradient.cpp
index 5f2516e6..a4936148 100644
--- a/modules/cairo-radial-gradient.cpp
+++ b/modules/cairo-radial-gradient.cpp
@@ -6,7 +6,6 @@
 
 #include <cairo.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -15,13 +14,11 @@
 #include <jspubtd.h>  // for JSProtoKey
 
 #include "gjs/jsapi-util-args.h"
+#include "gjs/jsapi-util.h"  // IWYU pragma: keep
 #include "modules/cairo-private.h"
 
 namespace JS {
 class CallArgs;
-// Avoid static_assert in MSVC builds
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
 }
 
 JSObject* CairoRadialGradient::new_proto(JSContext* cx, JSProtoKey) {
diff --git a/modules/cairo-solid-pattern.cpp b/modules/cairo-solid-pattern.cpp
index 664c290c..cc09ab3c 100644
--- a/modules/cairo-solid-pattern.cpp
+++ b/modules/cairo-solid-pattern.cpp
@@ -7,7 +7,6 @@
 #include <cairo.h>
 
 #include <js/CallArgs.h>
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -19,12 +18,6 @@
 #include "gjs/macros.h"
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 JSObject* CairoSolidPattern::new_proto(JSContext* cx, JSProtoKey) {
     JS::RootedObject parent_proto(cx, CairoPattern::prototype(cx));
     return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
diff --git a/modules/cairo-surface-pattern.cpp b/modules/cairo-surface-pattern.cpp
index 35557bca..a4361bbb 100644
--- a/modules/cairo-surface-pattern.cpp
+++ b/modules/cairo-surface-pattern.cpp
@@ -7,7 +7,6 @@
 #include <cairo.h>
 
 #include <js/CallArgs.h>
-#include <js/GCPolicyAPI.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -20,12 +19,6 @@
 #include "gjs/macros.h"
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 JSObject* CairoSurfacePattern::new_proto(JSContext* cx, JSProtoKey) {
     JS::RootedObject parent_proto(cx, CairoPattern::prototype(cx));
     return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
diff --git a/modules/cairo-svg-surface.cpp b/modules/cairo-svg-surface.cpp
index 53f7e585..cb57707e 100644
--- a/modules/cairo-svg-surface.cpp
+++ b/modules/cairo-svg-surface.cpp
@@ -8,7 +8,6 @@
 #include <cairo-features.h>  // for CAIRO_HAS_SVG_SURFACE
 #include <cairo.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/TypeDecls.h>
 
 #include "gjs/jsapi-util.h"
@@ -27,9 +26,6 @@
 
 namespace JS {
 class CallArgs;
-// Avoid static_assert in MSVC builds
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
 }
 
 JSObject* CairoSVGSurface::new_proto(JSContext* cx, JSProtoKey) {
diff --git a/modules/cairo.cpp b/modules/cairo.cpp
index 614c8ec5..7567b5d5 100644
--- a/modules/cairo.cpp
+++ b/modules/cairo.cpp
@@ -7,7 +7,6 @@
 #include <cairo-features.h>  // for CAIRO_HAS_PDF_SURFACE, CAIRO_HAS_PS_SURFA...
 #include <cairo.h>
 
-#include <js/GCPolicyAPI.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
 #include <jsapi.h>  // for JS_NewPlainObject
@@ -15,12 +14,6 @@
 #include "gjs/jsapi-util.h"
 #include "modules/cairo-private.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 #ifdef CAIRO_HAS_XLIB_SURFACE
 #    include <cairo-xlib.h>
 
diff --git a/modules/print.cpp b/modules/print.cpp
index cb0f1e3b..942fd0a1 100644
--- a/modules/print.cpp
+++ b/modules/print.cpp
@@ -12,7 +12,6 @@
 #include <js/CallArgs.h>
 #include <js/CharacterEncoding.h>  // for JS_EncodeStringToUTF8
 #include <js/Conversions.h>
-#include <js/GCPolicyAPI.h>
 #include <js/PropertySpec.h>  // for JS_FN, JSFunctionSpec, JS_FS_END
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
@@ -22,12 +21,6 @@
 #include "gjs/jsapi-util.h"
 #include "modules/print.h"
 
-// Avoid static_assert in MSVC builds
-namespace JS {
-template <>
-struct GCPolicy<void*> : public IgnoreGCPolicy<void*> {};
-}
-
 GJS_JSAPI_RETURN_CONVENTION
 static bool gjs_log(JSContext* cx, unsigned argc, JS::Value* vp) {
     JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);


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