summaryrefslogtreecommitdiff
path: root/modules/cairo-surface.cpp
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2016-10-16 22:11:32 -0700
committerPhilip Chimento <philip@endlessm.com>2016-10-20 14:21:11 -0700
commit11d96aa95f12a9d1604770a227436099dd4722ee (patch)
treedb015763b7af6c3682704f25b6b51117f1edb5d3 /modules/cairo-surface.cpp
parent16c6e144a269b16126e897aaa50486a021ba1ec2 (diff)
downloadgjs-11d96aa95f12a9d1604770a227436099dd4722ee.tar.gz
jsapi-util: Rooting-safe gjs_parse_call_args()
This removes the old unused gjs_parse_args(), and moves gjs_parse_call_args() into new files jsapi-util-args.cpp and jsapi-util-args.h. In order to ensure that JSObjects unpacked from gjs_parse_call_args() land in GC roots, we need to add some type safety to its variable arguments. Instead of accepting a JSObject** pointer for the "o" format character, it must accept a JS::MutableHandleObject. We can do this (and make the whole thing type safe as well) by using C++ templates instead of C varargs. Now we can issue a compile-time error when an unknown type is passed in as a return location for an argument, in particular JSObject**. This also fixes some undefined behaviour: the old signature of gjs_parse_call_args() placed the varargs parameter right after the JS::CallArgs& parameter, and using a reference parameter in va_start() is undefined. Here's a good explanation of what can go wrong: http://stackoverflow.com/a/222288/172999 https://bugzilla.gnome.org/show_bug.cgi?id=742249
Diffstat (limited to 'modules/cairo-surface.cpp')
-rw-r--r--modules/cairo-surface.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index df288245..e5635957 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -24,6 +24,7 @@
#include "gjs/compat.h"
#include "gi/foreign.h"
+#include "gjs/jsapi-util-args.h"
#include <cairo.h>
#include <cairo-gobject.h>
#include "cairo-private.h"
@@ -65,8 +66,8 @@ writeToPNG_func(JSContext *context,
char *filename;
cairo_surface_t *surface;
- if (!gjs_parse_call_args(context, "writeToPNG", "s", argv,
- "filename", &filename))
+ if (!gjs_parse_call_args(context, "writeToPNG", argv, "F",
+ "filename", &filename))
return false;
surface = gjs_cairo_surface_get_surface(context, obj);