summaryrefslogtreecommitdiff
path: root/modules/cairo-linear-gradient.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-linear-gradient.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-linear-gradient.cpp')
-rw-r--r--modules/cairo-linear-gradient.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/modules/cairo-linear-gradient.cpp b/modules/cairo-linear-gradient.cpp
index 65717796..53e3a02a 100644
--- a/modules/cairo-linear-gradient.cpp
+++ b/modules/cairo-linear-gradient.cpp
@@ -23,6 +23,7 @@
#include <config.h>
#include "gjs/compat.h"
+#include "gjs/jsapi-util-args.h"
#include <cairo.h>
#include "cairo-private.h"
@@ -36,11 +37,11 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_linear_gradient)
GJS_NATIVE_CONSTRUCTOR_PRELUDE(cairo_linear_gradient);
- if (!gjs_parse_call_args(context, "LinearGradient", "ffff", argv,
- "x0", &x0,
- "y0", &y0,
- "x1", &x1,
- "y1", &y1))
+ if (!gjs_parse_call_args(context, "LinearGradient", argv, "ffff",
+ "x0", &x0,
+ "y0", &y0,
+ "x1", &x1,
+ "y1", &y1))
return false;
pattern = cairo_pattern_create_linear(x0, y0, x1, y1);