summaryrefslogtreecommitdiff
path: root/gjs/jsapi-class.h
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2019-10-26 22:52:35 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2019-10-30 21:29:48 -0700
commite7ca4d37ed3446ede0daa0a99d5488b5c37d0f20 (patch)
treef9aebf6741df8654416c99e32cbb56daa44bdb97 /gjs/jsapi-class.h
parent85ebaae84234c82379236272f80782338cef4aae (diff)
downloadgjs-e7ca4d37ed3446ede0daa0a99d5488b5c37d0f20.tar.gz
cairo: Add type checking to Path, Pattern, and Surface
Previously, passing the wrong kind of object where a Cairo.Path, Cairo.Pattern (subclass), or Cairo.Surface (subclass) was expected, would crash. This adds type checking to avoid these crashes. The normal way to do this would be with JS_HasInstance(), but since Cairo.Pattern and Cairo.Surface are abstract classes, that won't work. JS_HasInstance() takes a constructor, and abstract classes don't have a constructor. Instead, we have to check the passed-in object's prototype chain. It turns out there isn't a JSAPI function to do that, so we add gjs_object_in_prototype_chain() for this purpose. In addition we add missing error checking in a few places. Closes: #49.
Diffstat (limited to 'gjs/jsapi-class.h')
-rw-r--r--gjs/jsapi-class.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/gjs/jsapi-class.h b/gjs/jsapi-class.h
index c090336f..757a65dd 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -325,4 +325,9 @@ GJS_DEFINE_PROTO_FUNCS_WITH_PARENT(cname, no_parent)
GJS_USE
JS::Value gjs_dynamic_property_private_slot(JSObject *accessor_obj);
+GJS_JSAPI_RETURN_CONVENTION
+bool gjs_object_in_prototype_chain(JSContext* cx, JS::HandleObject proto,
+ JS::HandleObject check_obj,
+ bool* is_in_chain);
+
#endif // GJS_JSAPI_CLASS_H_