Skip to content

cairo: Add type checking to Path, Pattern, and Surface

Philip Chimento requested to merge ptomato/gjs:49-cairo-typechecks into master

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 (closed).

Merge request reports