[gjs/mozjs102: 8/11] js: Replace JSFreeOp with JS::GCContext




commit 0fb10832f31a5767720f9dacd28757c8babf4f48
Author: Evan Welsh <contact evanwelsh com>
Date:   Fri Jul 22 10:49:35 2022 -0700

    js: Replace JSFreeOp with JS::GCContext
    
    In particular, in finalize operations.

 gi/cwrapper.h             |  6 +++---
 gi/function.cpp           |  4 ++--
 gi/gtype.cpp              |  2 +-
 gi/ns.cpp                 |  2 +-
 gi/object.cpp             |  4 ++--
 gi/object.h               |  2 +-
 gi/param.cpp              |  2 +-
 gi/wrapperutils.h         | 10 +++++-----
 gjs/engine.cpp            |  2 +-
 gjs/module.cpp            |  4 +++-
 modules/cairo-context.cpp |  2 +-
 modules/cairo-path.cpp    |  2 +-
 modules/cairo-pattern.cpp |  3 +--
 modules/cairo-private.h   | 28 ++++++++++++++--------------
 modules/cairo-region.cpp  |  2 +-
 modules/cairo-surface.cpp |  3 +--
 test/gjs-test-rooting.cpp |  2 +-
 tools/process_iwyu.py     |  2 +-
 18 files changed, 41 insertions(+), 41 deletions(-)
---
diff --git a/gi/cwrapper.h b/gi/cwrapper.h
index bbcd216c5..47c8e29ae 100644
--- a/gi/cwrapper.h
+++ b/gi/cwrapper.h
@@ -204,7 +204,7 @@ class CWrapperPointerOps {
  *    class_spec's flags member.
  *  - static constexpr unsigned constructor_nargs: number of arguments that the
  *    constructor takes. If you implement constructor_impl() then also add this.
- *  - void finalize_impl(JSFreeOp*, Wrapped*): called when the JS object is
+ *  - void finalize_impl(JS::GCContext*, Wrapped*): called when the JS object is
  *    garbage collected, use this to free the C pointer and do any other cleanup
  *
  * Add optional functionality by setting members of class_spec:
@@ -291,14 +291,14 @@ class CWrapper : public CWrapperPointerOps<Base, Wrapped> {
             debug_jsprop(message, gjs_debug_id(id).c_str(), obj);
     }
 
-    static void finalize(JSFreeOp* fop, JSObject* obj) {
+    static void finalize(JS::GCContext* gcx, JSObject* obj) {
         Wrapped* priv = Base::for_js_nocheck(obj);
 
         // Call only CWrapper's original method here, not any overrides; e.g.,
         // we don't want to deal with a read barrier.
         CWrapper::debug_lifecycle(priv, obj, "Finalize");
 
-        Base::finalize_impl(fop, priv);
+        Base::finalize_impl(gcx, priv);
 
         CWrapperPointerOps<Base, Wrapped>::unset_private(obj);
     }
diff --git a/gi/function.cpp b/gi/function.cpp
index 8cce6834a..08a0ea25f 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -109,7 +109,7 @@ class Function : public CWrapper<Function> {
     GJS_JSAPI_RETURN_CONVENTION
     static bool call(JSContext* cx, unsigned argc, JS::Value* vp);
 
-    static void finalize_impl(JSFreeOp*, Function* priv);
+    static void finalize_impl(JS::GCContext*, Function* priv);
 
     GJS_JSAPI_RETURN_CONVENTION
     static bool get_length(JSContext* cx, unsigned argc, JS::Value* vp);
@@ -1154,7 +1154,7 @@ Function::~Function() {
     GJS_DEC_COUNTER(function);
 }
 
-void Function::finalize_impl(JSFreeOp*, Function* priv) {
+void Function::finalize_impl(JS::GCContext*, Function* priv) {
     if (priv == NULL)
         return; /* we are the prototype, not a real instance, so constructor never called */
     delete priv;
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 58efef008..8f5bf38ae 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -48,7 +48,7 @@ class GTypeObj : public CWrapper<GTypeObj, void> {
 
     // No private data is allocated, it's stuffed directly in the private field
     // of JSObject, so nothing to free
-    static void finalize_impl(JSFreeOp*, void*) {}
+    static void finalize_impl(JS::GCContext*, void*) {}
 
     // Properties
 
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 1b546c3d3..3ba019baa 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -152,7 +152,7 @@ class Ns : private GjsAutoChar, public CWrapper<Ns> {
         return true;
     }
 
-    static void finalize_impl(JSFreeOp* fop [[maybe_unused]], Ns* priv) {
+    static void finalize_impl(JS::GCContext*, Ns* priv) {
         g_assert(priv && "Finalize called on wrong object");
         delete priv;
     }
diff --git a/gi/object.cpp b/gi/object.cpp
index ed98ac504..3ced434f9 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1902,14 +1902,14 @@ void ObjectPrototype::trace_impl(JSTracer* tracer) {
         Gjs::Closure::for_gclosure(closure)->trace(tracer);
 }
 
-void ObjectInstance::finalize_impl(JSFreeOp* fop, JSObject* obj) {
+void ObjectInstance::finalize_impl(JS::GCContext* gcx, JSObject* obj) {
     GTypeQuery query;
     type_query_dynamic_safe(&query);
     if (G_LIKELY(query.type))
         JS::RemoveAssociatedMemory(obj, query.instance_size,
                                    MemoryUse::GObjectInstanceStruct);
 
-    GIWrapperInstance::finalize_impl(fop, obj);
+    GIWrapperInstance::finalize_impl(gcx, obj);
 }
 
 ObjectInstance::~ObjectInstance() {
diff --git a/gi/object.h b/gi/object.h
index cb9af1716..e6016cb73 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -419,7 +419,7 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
     GJS_JSAPI_RETURN_CONVENTION
     bool add_property_impl(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
                            JS::HandleValue value);
-    void finalize_impl(JSFreeOp* fop, JSObject* obj);
+    void finalize_impl(JS::GCContext*, JSObject* obj);
     void trace_impl(JSTracer* trc);
 
     /* JS property getters/setters */
diff --git a/gi/param.cpp b/gi/param.cpp
index 0c4e04099..089b7572e 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -123,7 +123,7 @@ static bool gjs_param_constructor(JSContext* cx, unsigned argc, JS::Value* vp) {
     return true;
 }
 
-static void param_finalize(JSFreeOp*, JSObject* obj) {
+static void param_finalize(JS::GCContext*, JSObject* obj) {
     Param* priv = Gjs::maybe_get_private<Param>(obj, POINTER);
     gjs_debug_lifecycle(GJS_DEBUG_GPARAM, "finalize, obj %p priv %p", obj,
                         priv);
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 719a78ccf..16c55f115 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -395,7 +395,7 @@ class GIWrapperBase : public CWrapperPointerOps<Base> {
      * necessary to include a finalize_impl() function in Prototype or Instance.
      * Any needed finalization should be done in ~Prototype() and ~Instance().
      */
-    static void finalize(JSFreeOp* fop, JSObject* obj) {
+    static void finalize(JS::GCContext* gcx, JSObject* obj) {
         Base* priv = Base::for_js_nocheck(obj);
         if (!priv)
             return;  // construction didn't finish
@@ -405,9 +405,9 @@ class GIWrapperBase : public CWrapperPointerOps<Base> {
         static_cast<GIWrapperBase*>(priv)->debug_lifecycle(obj, "Finalize");
 
         if (priv->is_prototype())
-            priv->to_prototype()->finalize_impl(fop, obj);
+            priv->to_prototype()->finalize_impl(gcx, obj);
         else
-            priv->to_instance()->finalize_impl(fop, obj);
+            priv->to_instance()->finalize_impl(gcx, obj);
 
         Base::unset_private(obj);
     }
@@ -1013,7 +1013,7 @@ class GIWrapperPrototype : public Base {
     // JSClass operations
 
  protected:
-    void finalize_impl(JSFreeOp*, JSObject*) { release(); }
+    void finalize_impl(JS::GCContext*, JSObject*) { release(); }
 
     // Override if necessary
     void trace_impl(JSTracer*) {}
@@ -1108,7 +1108,7 @@ class GIWrapperInstance : public Base {
     // JSClass operations
 
  protected:
-    void finalize_impl(JSFreeOp*, JSObject*) {
+    void finalize_impl(JS::GCContext*, JSObject*) {
         delete static_cast<Instance*>(this);
     }
 
diff --git a/gjs/engine.cpp b/gjs/engine.cpp
index f67f99738..e7a53fb6e 100644
--- a/gjs/engine.cpp
+++ b/gjs/engine.cpp
@@ -33,7 +33,7 @@
 #include "gjs/jsapi-util.h"
 #include "util/log.h"
 
-static void gjs_finalize_callback(JSFreeOp*, JSFinalizeStatus status,
+static void gjs_finalize_callback(JS::GCContext*, JSFinalizeStatus status,
                                   void* data) {
     auto* gjs = static_cast<GjsContextPrivate*>(data);
     gjs->set_finalize_status(status);
diff --git a/gjs/module.cpp b/gjs/module.cpp
index cf9eaf372..ccf20374c 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -220,7 +220,9 @@ class GjsScriptModule {
         return priv(module)->resolve_impl(cx, module, id, resolved);
     }
 
-    static void finalize(JSFreeOp*, JSObject* module) { delete priv(module); }
+    static void finalize(JS::GCContext*, JSObject* module) {
+        delete priv(module);
+    }
 
     static constexpr JSClassOps class_ops = {
         nullptr,  // addProperty
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 2f59a6868..b777fb293 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -261,7 +261,7 @@ cairo_t* CairoContext::constructor_impl(JSContext* context,
     return cr;
 }
 
-void CairoContext::finalize_impl(JSFreeOp*, cairo_t* cr) {
+void CairoContext::finalize_impl(JS::GCContext*, cairo_t* cr) {
     if (!cr)
         return;
     cairo_destroy(cr);
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index 415fcf2ef..b2762f5f7 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -43,7 +43,7 @@ JSObject* CairoPath::take_c_ptr(JSContext* cx, cairo_path_t* ptr) {
     return wrapper;
 }
 
-void CairoPath::finalize_impl(JSFreeOp*, cairo_path_t* path) {
+void CairoPath::finalize_impl(JS::GCContext*, cairo_path_t* path) {
     if (!path)
         return;
     cairo_path_destroy(path);
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index a92541844..9d5a847ac 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -65,14 +65,13 @@ const JSFunctionSpec CairoPattern::proto_funcs[] = {
 
 /**
  * CairoPattern::finalize_impl:
- * @fop: the free op
  * @pattern: pointer to free
  *
  * Destroys the resources associated with a pattern wrapper.
  *
  * This is mainly used for subclasses.
  */
-void CairoPattern::finalize_impl(JSFreeOp*, cairo_pattern_t* pattern) {
+void CairoPattern::finalize_impl(JS::GCContext*, cairo_pattern_t* pattern) {
     if (!pattern)
         return;
     cairo_pattern_destroy(pattern);
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 8e17c83e4..75d111c52 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -55,7 +55,7 @@ class CairoRegion : public CWrapper<CairoRegion, cairo_region_t> {
     static cairo_region_t* constructor_impl(JSContext* cx,
                                             const JS::CallArgs& args);
 
-    static void finalize_impl(JSFreeOp* fop, cairo_region_t* cr);
+    static void finalize_impl(JS::GCContext*, cairo_region_t* cr);
 
     static const JSFunctionSpec proto_funcs[];
     static const JSPropertySpec proto_props[];
@@ -95,7 +95,7 @@ class CairoContext : public CWrapper<CairoContext, cairo_t> {
     GJS_JSAPI_RETURN_CONVENTION
     static cairo_t* constructor_impl(JSContext* cx, const JS::CallArgs& args);
 
-    static void finalize_impl(JSFreeOp* fop, cairo_t* cr);
+    static void finalize_impl(JS::GCContext*, cairo_t* cr);
 
     static const JSFunctionSpec proto_funcs[];
     static const JSPropertySpec proto_props[];
@@ -133,7 +133,7 @@ class CairoPath : public CWrapper<CairoPath, cairo_path_t> {
         GjsGlobalSlot::PROTOTYPE_cairo_path;
     static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
 
-    static void finalize_impl(JSFreeOp* fop, cairo_path_t* path);
+    static void finalize_impl(JS::GCContext*, cairo_path_t* path);
 
     static const JSPropertySpec proto_props[];
     static constexpr js::ClassSpec class_spec = {
@@ -174,7 +174,7 @@ class CairoSurface : public CWrapper<CairoSurface, cairo_surface_t> {
 
     static GType gtype() { return CAIRO_GOBJECT_TYPE_SURFACE; }
 
-    static void finalize_impl(JSFreeOp* fop, cairo_surface_t* surface);
+    static void finalize_impl(JS::GCContext*, cairo_surface_t* surface);
 
     static const JSFunctionSpec proto_funcs[];
     static const JSPropertySpec proto_props[];
@@ -240,7 +240,7 @@ class CairoImageSurface : public CWrapper<CairoImageSurface, cairo_surface_t> {
         return cairo_surface_reference(surface);
     }
 
-    static void finalize_impl(JSFreeOp*, cairo_surface_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
 
     GJS_JSAPI_RETURN_CONVENTION
     static cairo_surface_t* constructor_impl(JSContext* cx,
@@ -280,7 +280,7 @@ class CairoPSSurface : public CWrapper<CairoPSSurface, cairo_surface_t> {
         return cairo_surface_reference(surface);
     }
 
-    static void finalize_impl(JSFreeOp*, cairo_surface_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
 
     GJS_JSAPI_RETURN_CONVENTION
     static cairo_surface_t* constructor_impl(JSContext* cx,
@@ -326,7 +326,7 @@ class CairoPDFSurface : public CWrapper<CairoPDFSurface, cairo_surface_t> {
         return cairo_surface_reference(surface);
     }
 
-    static void finalize_impl(JSFreeOp*, cairo_surface_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
 
     GJS_JSAPI_RETURN_CONVENTION
     static cairo_surface_t* constructor_impl(JSContext* cx,
@@ -372,7 +372,7 @@ class CairoSVGSurface : public CWrapper<CairoSVGSurface, cairo_surface_t> {
         return cairo_surface_reference(surface);
     }
 
-    static void finalize_impl(JSFreeOp*, cairo_surface_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
 
     GJS_JSAPI_RETURN_CONVENTION
     static cairo_surface_t* constructor_impl(JSContext* cx,
@@ -430,7 +430,7 @@ class CairoPattern : public CWrapper<CairoPattern, cairo_pattern_t> {
     static bool getType_func(JSContext* context, unsigned argc, JS::Value* vp);
 
  protected:
-    static void finalize_impl(JSFreeOp* fop, cairo_pattern_t* pattern);
+    static void finalize_impl(JS::GCContext*, cairo_pattern_t* pattern);
 
  public:
     static cairo_pattern_t* for_js(JSContext* cx,
@@ -469,7 +469,7 @@ class CairoGradient : public CWrapper<CairoGradient, cairo_pattern_t> {
         "Gradient", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
         &CairoPattern::class_ops, &CairoGradient::class_spec};
 
-    static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
 };
 
 class CairoLinearGradient
@@ -509,7 +509,7 @@ class CairoLinearGradient
     static cairo_pattern_t* constructor_impl(JSContext* cx,
                                              const JS::CallArgs& args);
 
-    static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
 };
 
 class CairoRadialGradient
@@ -549,7 +549,7 @@ class CairoRadialGradient
     static cairo_pattern_t* constructor_impl(JSContext* cx,
                                              const JS::CallArgs& args);
 
-    static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
 };
 
 class CairoSurfacePattern
@@ -589,7 +589,7 @@ class CairoSurfacePattern
     static cairo_pattern_t* constructor_impl(JSContext* cx,
                                              const JS::CallArgs& args);
 
-    static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
 };
 
 class CairoSolidPattern : public CWrapper<CairoSolidPattern, cairo_pattern_t> {
@@ -623,7 +623,7 @@ class CairoSolidPattern : public CWrapper<CairoSolidPattern, cairo_pattern_t> {
         return cairo_pattern_reference(pattern);
     }
 
-    static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {}
+    static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
 };
 
 #endif  // MODULES_CAIRO_PRIVATE_H_
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index 84c449f40..2490dabc7 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -220,7 +220,7 @@ cairo_region_t* CairoRegion::constructor_impl(JSContext* context,
     return cairo_region_create();
 }
 
-void CairoRegion::finalize_impl(JSFreeOp*, cairo_region_t* region) {
+void CairoRegion::finalize_impl(JS::GCContext*, cairo_region_t* region) {
     if (!region)
         return;
 
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index 51661c3cd..abeca366b 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -207,14 +207,13 @@ const JSFunctionSpec CairoSurface::proto_funcs[] = {
 
 /**
  * CairoSurface::finalize_impl:
- * @fop: the free op
  * @surface: the pointer to finalize
  *
  * Destroys the resources associated with a surface wrapper.
  *
  * This is mainly used for subclasses.
  */
-void CairoSurface::finalize_impl(JSFreeOp*, cairo_surface_t* surface) {
+void CairoSurface::finalize_impl(JS::GCContext*, cairo_surface_t* surface) {
     if (!surface)
         return;
     cairo_surface_destroy(surface);
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index d8109754e..ecf79f453 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -44,7 +44,7 @@ struct GjsRootingFixture {
     GjsMaybeOwned<JSObject *> *obj;  /* only used in callback test cases */
 };
 
-static void test_obj_finalize(JSFreeOp*, JSObject* obj) {
+static void test_obj_finalize(JS::GCContext*, JSObject* obj) {
     bool* finalized_p = Gjs::maybe_get_private<bool>(obj, POINTER);
     g_assert_false(*finalized_p);
     *finalized_p = true;
diff --git a/tools/process_iwyu.py b/tools/process_iwyu.py
index 6699f4ece..8b70517c7 100755
--- a/tools/process_iwyu.py
+++ b/tools/process_iwyu.py
@@ -40,12 +40,12 @@ FWD_DECLS_IN_HEADER = (
     'struct JSContext;',
     'struct JSClass;',
     'class JSFunction;',
-    'class JSFreeOp;',
     'class JSObject;',
     'struct JSRuntime;',
     'class JSScript;',
     'class JSString;',
     'namespace js { class TempAllocPolicy; }',
+    'namespace JS { class GCContext; }',
     'namespace JS { struct PropertyKey; }',
     'namespace JS { class Symbol; }',
     'namespace JS { class BigInt; }',


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