summaryrefslogtreecommitdiff
path: root/modules/cairo-surface.cpp
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2018-10-28 20:16:43 -0400
committerPhilip Chimento <philip.chimento@gmail.com>2018-10-30 09:31:44 -0400
commit425b94d663e400b6dee9ed2ebd1c92738970b054 (patch)
tree4518de06c80d37cf6ecf3f1262c4ece1b3839871 /modules/cairo-surface.cpp
parentf8672ea2670373171addebd459784a839e08e3ec (diff)
downloadgjs-425b94d663e400b6dee9ed2ebd1c92738970b054.tar.gz
js: Introduce annotations for using return values
This introduces two annotations to functions. GJS_USE is a macro for GCC and Clang's "warn_unused_result" annotation, meaning that the return value of a function must not be ignored. This allows us to catch some cases where we are neglecting to do error checking. The second annotation is GJS_JSAPI_RETURN_CONVENTION which for now is identical to GJS_USE, but could be made into a custom annotation in the future which a static analyzer plugin could use to enforce further checks at compile time. The "JSAPI return convention" is valid on functions that return bool or a pointer type, and whose first parameter is JSContext*. If false or nullptr is returned, then an exception must be pending at return time on the passed-in JSContext. If true or a non-nullptr value is returned, then no exception must be pending. This commit only has the addition of the attributes, and a few fixes mandated by the autoformatter, so it can be reviewed "lightly".
Diffstat (limited to 'modules/cairo-surface.cpp')
-rw-r--r--modules/cairo-surface.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index d14e03a8..6b671ba5 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -60,6 +60,7 @@ JSPropertySpec gjs_cairo_surface_proto_props[] = {
};
/* Methods */
+GJS_JSAPI_RETURN_CONVENTION
static bool
writeToPNG_func(JSContext *context,
unsigned argc,
@@ -85,6 +86,7 @@ writeToPNG_func(JSContext *context,
return true;
}
+GJS_JSAPI_RETURN_CONVENTION
static bool
getType_func(JSContext *context,
unsigned argc,
@@ -243,6 +245,7 @@ gjs_cairo_surface_get_surface(JSContext *context,
return priv->surface;
}
+GJS_USE
static bool
surface_to_g_argument(JSContext *context,
JS::Value value,
@@ -266,6 +269,7 @@ surface_to_g_argument(JSContext *context,
return true;
}
+GJS_JSAPI_RETURN_CONVENTION
static bool
surface_from_g_argument(JSContext *context,
JS::MutableHandleValue value_p,