[gjs/burninate-macros: 10/13] cairo: Remove JSClass macros from CairoPath
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/burninate-macros: 10/13] cairo: Remove JSClass macros from CairoPath
- Date: Wed, 3 Jun 2020 15:17:34 +0000 (UTC)
commit e7aff1f0cdbaa45c6945446bc4b4de9449e47802
Author: Philip Chimento <philip chimento gmail com>
Date: Mon May 11 11:56:05 2020 -0700
cairo: Remove JSClass macros from CairoPath
FIXME: Need commit message
modules/cairo-context.cpp | 16 ++++++---
modules/cairo-path.cpp | 86 +++++------------------------------------------
modules/cairo-private.h | 28 +++++++++------
modules/cairo.cpp | 2 +-
4 files changed, 40 insertions(+), 92 deletions(-)
---
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 7f62dcaa..0b85d5cd 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -401,8 +401,8 @@ appendPath_func(JSContext *context,
"path", &path_wrapper))
return false;
- cairo_path_t* path = gjs_cairo_path_get_path(context, path_wrapper);
- if (!path)
+ cairo_path_t* path;
+ if (!CairoPath::for_js_typecheck(context, path_wrapper, &path, &argv))
return false;
cairo_append_path(cr, path);
@@ -427,7 +427,11 @@ copyPath_func(JSContext *context,
return false;
path = cairo_copy_path(cr);
- argv.rval().setObjectOrNull(gjs_cairo_path_from_path(context, path));
+ JSObject* retval = CairoPath::from_c_ptr(context, path);
+ if (!retval)
+ return false;
+
+ argv.rval().setObject(*retval);
return true;
}
@@ -448,7 +452,11 @@ copyPathFlat_func(JSContext *context,
return false;
path = cairo_copy_path_flat(cr);
- argv.rval().setObjectOrNull(gjs_cairo_path_from_path(context, path));
+ JSObject* retval = CairoPath::from_c_ptr(context, path);
+ if (!retval)
+ return false;
+
+ argv.rval().setObject(*retval);
return true;
}
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index 2d95318f..42a334eb 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -23,89 +23,21 @@
#include <config.h>
#include <cairo.h>
-#include <glib.h>
#include <js/Class.h>
-#include <js/PropertySpec.h>
-#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
-#include <jsapi.h> // for JS_GetClass, JS_GetInstancePrivate
#include "gjs/jsapi-class.h"
-#include "gjs/jsapi-util.h"
-#include "gjs/macros.h"
+#include "modules/cairo-private.h"
-GJS_USE
-static JSObject *gjs_cairo_path_get_proto(JSContext *);
+const js::ClassSpec CairoPath::class_spec = {/* all nullptr */};
-GJS_DEFINE_PROTO_ABSTRACT("Path", cairo_path, JSCLASS_BACKGROUND_FINALIZE)
+const JSClass CairoPath::klass = {
+ "Path", JSCLASS_HAS_PRIVATE | JSCLASS_BACKGROUND_FINALIZE,
+ &CairoPath::class_ops};
-static void gjs_cairo_path_finalize(JSFreeOp*, JSObject* obj) {
- using AutoCairoPath =
- GjsAutoPointer<cairo_path_t, cairo_path_t, cairo_path_destroy>;
- AutoCairoPath path = static_cast<cairo_path_t*>(JS_GetPrivate(obj));
- JS_SetPrivate(obj, nullptr);
-}
-
-/* Properties */
-JSPropertySpec gjs_cairo_path_proto_props[] = {
- JS_PS_END
-};
-
-JSFunctionSpec gjs_cairo_path_proto_funcs[] = {
- JS_FS_END
-};
-
-JSFunctionSpec gjs_cairo_path_static_funcs[] = { JS_FS_END };
-
-/**
- * gjs_cairo_path_from_path:
- * @context: the context
- * @path: cairo_path_t to attach to the object
- *
- * Constructs a pattern wrapper given cairo pattern.
- * NOTE: This function takes ownership of the path.
- */
-JSObject *
-gjs_cairo_path_from_path(JSContext *context,
- cairo_path_t *path)
-{
- g_return_val_if_fail(context, nullptr);
- g_return_val_if_fail(path, nullptr);
-
- JS::RootedObject proto(context, gjs_cairo_path_get_proto(context));
- JS::RootedObject object(context,
- JS_NewObjectWithGivenProto(context, &gjs_cairo_path_class, proto));
- if (!object) {
- gjs_throw(context, "failed to create path");
- return nullptr;
- }
-
- g_assert(!JS_GetPrivate(object));
- JS_SetPrivate(object, path);
-
- return object;
-}
-
-/**
- * gjs_cairo_path_get_path:
- * @cx: the context
- * @path_wrapper: path wrapper
- *
- * Returns: the path attached to the wrapper.
- */
-cairo_path_t* gjs_cairo_path_get_path(JSContext* cx,
- JS::HandleObject path_wrapper) {
- g_return_val_if_fail(cx, nullptr);
- g_return_val_if_fail(path_wrapper, nullptr);
-
- auto* path = static_cast<cairo_path_t*>(JS_GetInstancePrivate(
- cx, path_wrapper, &gjs_cairo_path_class, nullptr));
- if (!path) {
- gjs_throw(cx, "Expected Cairo.Path but got %s",
- JS_GetClass(path_wrapper)->name);
- return nullptr;
- }
-
- return path;
+void CairoPath::finalize_impl(JSFreeOp*, cairo_path_t* path) {
+ if (!path)
+ return;
+ cairo_path_destroy(path);
}
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 5f1d5db5..d4a81500 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -87,17 +87,25 @@ void gjs_cairo_context_init(void);
void gjs_cairo_surface_init(void);
/* path */
-GJS_JSAPI_RETURN_CONVENTION
-bool gjs_cairo_path_define_proto(JSContext *cx,
- JS::HandleObject module,
- JS::MutableHandleObject proto);
-GJS_JSAPI_RETURN_CONVENTION
-JSObject * gjs_cairo_path_from_path (JSContext *context,
- cairo_path_t *path);
-GJS_JSAPI_RETURN_CONVENTION
-cairo_path_t* gjs_cairo_path_get_path(JSContext* cx,
- JS::HandleObject path_wrapper);
+class CairoPath;
+using CairoPathBase =
+ NativeObject<CairoPath, cairo_path_t, GJS_GLOBAL_SLOT_PROTOTYPE_cairo_path>;
+
+class CairoPath : public CairoPathBase {
+ friend CairoPathBase;
+
+ CairoPath() = delete;
+ CairoPath(CairoPath&) = delete;
+ CairoPath(CairoPath&&) = delete;
+
+ static cairo_path_t* copy_ptr(cairo_path_t* path) { return path; }
+
+ static void finalize_impl(JSFreeOp* fop, cairo_path_t* path);
+
+ static const js::ClassSpec class_spec;
+ static const JSClass klass;
+};
/* surface */
GJS_USE
diff --git a/modules/cairo.cpp b/modules/cairo.cpp
index cdcc59a1..f12d21b6 100644
--- a/modules/cairo.cpp
+++ b/modules/cairo.cpp
@@ -82,7 +82,7 @@ gjs_js_define_cairo_stuff(JSContext *context,
return
gjs_cairo_image_surface_define_proto(context, module, &proto) &&
- gjs_cairo_path_define_proto(context, module, &proto) &&
+ CairoPath::create_prototype(context, module) &&
#if CAIRO_HAS_PS_SURFACE
gjs_cairo_ps_surface_define_proto(context, module, &proto) &&
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]