diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2018-10-28 20:16:43 -0400 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2018-10-30 09:31:44 -0400 |
commit | 425b94d663e400b6dee9ed2ebd1c92738970b054 (patch) | |
tree | 4518de06c80d37cf6ecf3f1262c4ece1b3839871 /gi/param.h | |
parent | f8672ea2670373171addebd459784a839e08e3ec (diff) | |
download | gjs-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 'gi/param.h')
-rw-r--r-- | gi/param.h | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -27,19 +27,25 @@ #include <stdbool.h> #include <glib.h> #include <girepository.h> + #include "gjs/jsapi-util.h" +#include "gjs/macros.h" G_BEGIN_DECLS +GJS_JSAPI_RETURN_CONVENTION bool gjs_define_param_class(JSContext *context, JS::HandleObject in_object); +GJS_JSAPI_RETURN_CONVENTION GParamSpec *gjs_g_param_from_param (JSContext *context, JS::HandleObject obj); +GJS_JSAPI_RETURN_CONVENTION JSObject* gjs_param_from_g_param (JSContext *context, GParamSpec *param); +GJS_USE bool gjs_typecheck_param(JSContext *context, JS::HandleObject obj, GType expected_type, |