summaryrefslogtreecommitdiff
path: root/modules/cairo-linear-gradient.cpp
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2017-04-09 16:19:48 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2017-04-17 19:57:52 -0700
commit8807af7ac36a9ae5de58b480d6c4ff8946dab01c (patch)
tree7fd5c889731772d7c9e3d80fdd00e86ccc69f737 /modules/cairo-linear-gradient.cpp
parentdcc82c3d5561a893323aeb47e133f3d88eb60487 (diff)
downloadgjs-8807af7ac36a9ae5de58b480d6c4ff8946dab01c.tar.gz
jsapi-class: GJS_DEFINE_PROTO stores protos in global slots
This refactors the GJS_DEFINE_PROTO family of macros to store the created prototype objects in slots on the global object. We split up the gjs_WHATEVER_create_proto() function into two functions: one that must be called at least once for each type to define the class, store the prototype in a global slot, and define the constructor as a property on a passed-in module or global object, gjs_WHATEVER_define_proto(); and one that retrieves the prototype from its global slot, gjs_WHATEVER_get_proto(). We also add two macros, GJS_DEFINE_PROTO_WITH_PARENT and GJS_DEFINE_PROTO_ABSTRACT_WITH_PARENT, which also move the definition of the parent to compile time rather than runtime, and keep it in the same place as the rest of each class's macro definition. Similarly, previously we had to pass the parent prototype object to gjs_WHATEVER_create_proto(). This mostly affects the cairo module. https://bugzilla.gnome.org/show_bug.cgi?id=614413
Diffstat (limited to 'modules/cairo-linear-gradient.cpp')
-rw-r--r--modules/cairo-linear-gradient.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/cairo-linear-gradient.cpp b/modules/cairo-linear-gradient.cpp
index 7bbcff0e..cbe6be7f 100644
--- a/modules/cairo-linear-gradient.cpp
+++ b/modules/cairo-linear-gradient.cpp
@@ -28,8 +28,10 @@
#include <cairo.h>
#include "cairo-private.h"
-GJS_DEFINE_PROTO("LinearGradient", cairo_linear_gradient,
- JSCLASS_BACKGROUND_FINALIZE)
+static JSObject *gjs_cairo_linear_gradient_get_proto(JSContext *);
+
+GJS_DEFINE_PROTO_WITH_PARENT("LinearGradient", cairo_linear_gradient,
+ cairo_gradient, JSCLASS_BACKGROUND_FINALIZE)
GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_linear_gradient)
{
@@ -83,9 +85,11 @@ gjs_cairo_linear_gradient_from_pattern(JSContext *context,
g_return_val_if_fail(pattern != NULL, NULL);
g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_LINEAR, NULL);
+ JS::RootedObject proto(context,
+ gjs_cairo_linear_gradient_get_proto(context));
JS::RootedObject object(context,
JS_NewObjectWithGivenProto(context, &gjs_cairo_linear_gradient_class,
- gjs_cairo_linear_gradient_prototype));
+ proto));
if (!object) {
gjs_throw(context, "failed to create linear gradient pattern");
return NULL;