[gjs/mozjs102: 57/59] js: Replace JSFreeOp with JS::GCContext
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/mozjs102: 57/59] js: Replace JSFreeOp with JS::GCContext
- Date: Sat, 23 Jul 2022 20:58:06 +0000 (UTC)
commit 18b4c47d265bffbd21e8e9579706d015d16b81f8
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 | 1 -
18 files changed, 40 insertions(+), 41 deletions(-)
---
diff --git a/gi/cwrapper.h b/gi/cwrapper.h
index 3cf031e46..dfafd6479 100644
--- a/gi/cwrapper.h
+++ b/gi/cwrapper.h
@@ -162,7 +162,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:
@@ -249,14 +249,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);
// Remove the pointer from the JSObject
JS::SetPrivate(obj, nullptr);
diff --git a/gi/function.cpp b/gi/function.cpp
index 5c4fa4a28..b3d2ac58a 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);
@@ -1162,7 +1162,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 d6589250d..accfd649b 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -47,7 +47,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 5d59b948e..97f5925e1 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -153,7 +153,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 75950938d..9bf644080 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1900,14 +1900,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 31ee50ebe..cde004b09 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -422,7 +422,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 7a3f88174..75de894b7 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -113,7 +113,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 = static_cast<Param*>(JS::GetPrivate(obj));
gjs_debug_lifecycle(GJS_DEBUG_GPARAM, "finalize, obj %p priv %p", obj,
priv);
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index aa50cdd05..dc088281d 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -394,7 +394,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
@@ -404,9 +404,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);
// Remove the pointer from the JSObject
JS::SetPrivate(obj, nullptr);
@@ -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*) {}
@@ -1110,7 +1110,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 332d5064c..35ac265dd 100644
--- a/gjs/engine.cpp
+++ b/gjs/engine.cpp
@@ -32,7 +32,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 3b54a3fca..d22a35670 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -210,7 +210,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 c2396a96d..09414f1bc 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -262,7 +262,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 76a879dfa..b6b3945b2 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -46,7 +46,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 1a6d07da3..3280d0316 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -64,14 +64,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 a470a94a5..9c14afe16 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[];
@@ -130,7 +130,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 = {
@@ -171,7 +171,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[];
@@ -236,7 +236,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,
@@ -275,7 +275,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,
@@ -320,7 +320,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,
@@ -365,7 +365,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,
@@ -423,7 +423,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,
@@ -462,7 +462,7 @@ class CairoGradient : public CWrapper<CairoGradient, cairo_pattern_t> {
"Gradient", JSCLASS_HAS_PRIVATE | 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
@@ -501,7 +501,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
@@ -540,7 +540,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
@@ -579,7 +579,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> {
@@ -612,7 +612,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 a6333f777..99f04b679 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -219,7 +219,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 710e8c1bf..c4e1932e0 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 a7fec3db0..37946e855 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -37,7 +37,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 = static_cast<bool*>(JS::GetPrivate(obj));
g_assert_false(*finalized_p);
*finalized_p = true;
diff --git a/tools/process_iwyu.py b/tools/process_iwyu.py
index 56bd230f1..36f1ab919 100755
--- a/tools/process_iwyu.py
+++ b/tools/process_iwyu.py
@@ -40,7 +40,6 @@ FWD_DECLS_IN_HEADER = (
'struct JSContext;',
'struct JSClass;',
'class JSFunction;',
- 'class JSFreeOp;',
'class JSObject;',
'struct JSRuntime;',
'class JSScript;',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]