summaryrefslogtreecommitdiff
path: root/modules/cairo-surface.cpp
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2016-10-06 21:25:38 -0700
committerPhilip Chimento <philip@endlessm.com>2016-10-19 09:21:16 -0700
commitb98cf0b7b10b03f7b0c44906642fbbb243df7ba1 (patch)
tree5cc8971cabb1437c942ef8cd4db1ec2d86145545 /modules/cairo-surface.cpp
parenta0f22fbcf26c346588268d3566fdeaa1949eac92 (diff)
downloadgjs-b98cf0b7b10b03f7b0c44906642fbbb243df7ba1.tar.gz
js: Add macros for 'this' and private data
This adds two macros, GJS_GET_THIS() to get a function's 'this' value as a rooted object (and if it was not an object, to box it into one), and GJS_GET_PRIV() to get our private C data from the 'this' object. This operation is done over and over again inside most JSNative functions, and SpiderMonkey code often uses convenience macros like this. These will come in handy even more when we switch to JSNative property accessors in a following commit. At the same time we make things more typesafe by doing a typecheck on each 'this' object in the native methods as part of GJS_GET_PRIV() and throwing an error if it is not the correct type. This gets rid of the args.thisv().toObjectOrNull() idiom which I'm pretty sure is wrong. https://bugzilla.gnome.org/show_bug.cgi?id=742249
Diffstat (limited to 'modules/cairo-surface.cpp')
-rw-r--r--modules/cairo-surface.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index 7d2dc674..2b055286 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -61,9 +61,7 @@ writeToPNG_func(JSContext *context,
unsigned argc,
JS::Value *vp)
{
- JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
- JSObject *obj = argv.thisv().toObjectOrNull();
-
+ GJS_GET_THIS(context, argc, vp, argv, obj);
char *filename;
cairo_surface_t *surface;
@@ -90,9 +88,7 @@ getType_func(JSContext *context,
unsigned argc,
JS::Value *vp)
{
- JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
- JSObject *obj = rec.thisv().toObjectOrNull();
-
+ GJS_GET_THIS(context, argc, vp, rec, obj);
cairo_surface_t *surface;
cairo_surface_type_t type;