[gjs/wip/ptomato/mozjs45prep: 11/39] jsapi-util: Add static function spec to GJS_DEFINE_PROTO
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs45prep: 11/39] jsapi-util: Add static function spec to GJS_DEFINE_PROTO
- Date: Wed, 12 Apr 2017 06:45:36 +0000 (UTC)
commit d12f94411344a6cb419aadf6a8bc958f1812638f
Author: Philip Chimento <philip chimento gmail com>
Date: Mon Apr 10 22:09:53 2017 -0700
jsapi-util: Add static function spec to GJS_DEFINE_PROTO
This allows the GJS_DEFINE_PROTO_* family of macros to have a JSFunctionSpec
array for functions defined on the constructor, rather than on the
prototype: i.e. static functions.
We clean up an incongruity in cairo-image-surface.cpp where you had to pass
the constructor into gjs_cairo_image_surface_init() in order to get the
static functions defined.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
gi/gtype.cpp | 2 ++
gjs/jsapi-util.h | 4 +++-
modules/cairo-context.cpp | 2 ++
modules/cairo-gradient.cpp | 2 ++
modules/cairo-image-surface.cpp | 13 +++++--------
modules/cairo-linear-gradient.cpp | 2 ++
modules/cairo-path.cpp | 2 ++
modules/cairo-pattern.cpp | 2 ++
modules/cairo-pdf-surface.cpp | 2 ++
modules/cairo-ps-surface.cpp | 2 ++
modules/cairo-radial-gradient.cpp | 2 ++
modules/cairo-region.cpp | 2 ++
modules/cairo-solid-pattern.cpp | 2 ++
modules/cairo-surface-pattern.cpp | 2 ++
modules/cairo-surface.cpp | 2 ++
modules/cairo-svg-surface.cpp | 2 ++
modules/cairo.cpp | 8 +-------
17 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 4e4b428..62d2b15 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -142,6 +142,8 @@ JSFunctionSpec gjs_gtype_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_gtype_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_gtype_create_gtype_wrapper (JSContext *context,
GType gtype)
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index b1058a2..ba92bb0 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -233,6 +233,7 @@ _GJS_DEFINE_PROTO_FULL(tn, cn, parent_cn, nullptr, G_TYPE_NONE, flags)
#define _GJS_DEFINE_PROTO_FULL(type_name, cname, parent_cname, ctor, gtype, jsclass_flags) \
extern JSPropertySpec gjs_##cname##_proto_props[]; \
extern JSFunctionSpec gjs_##cname##_proto_funcs[]; \
+extern JSFunctionSpec gjs_##cname##_static_funcs[]; \
static void gjs_##cname##_finalize(JSFreeOp *fop, JSObject *obj); \
static struct JSClass gjs_##cname##_class = { \
type_name, \
@@ -264,7 +265,8 @@ gjs_##cname##_ensure_proto(JSContext *cx, \
JS::RootedObject global(cx, gjs_get_import_global(cx)); \
proto.set(JS_InitClass(cx, global, parent_proto, &gjs_##cname##_class, \
ctor, 0, gjs_##cname##_proto_props, \
- gjs_##cname##_proto_funcs, nullptr, nullptr)); \
+ gjs_##cname##_proto_funcs, nullptr, \
+ gjs_##cname##_static_funcs)); \
if (!proto) \
return false; \
gjs_set_global_slot(cx, GJS_GLOBAL_SLOT_PROTOTYPE_##cname, \
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 717c8c8..8bb4682 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -923,6 +923,8 @@ JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_context_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_context_from_context(JSContext *context,
cairo_t *cr)
diff --git a/modules/cairo-gradient.cpp b/modules/cairo-gradient.cpp
index c259735..9a84b8b 100644
--- a/modules/cairo-gradient.cpp
+++ b/modules/cairo-gradient.cpp
@@ -107,3 +107,5 @@ JSFunctionSpec gjs_cairo_gradient_proto_funcs[] = {
// getColorStopRGBA
JS_FS_END
};
+
+JSFunctionSpec gjs_cairo_gradient_static_funcs[] = { JS_FS_END };
diff --git a/modules/cairo-image-surface.cpp b/modules/cairo-image-surface.cpp
index 97f3fc9..57c5014 100644
--- a/modules/cairo-image-surface.cpp
+++ b/modules/cairo-image-surface.cpp
@@ -214,6 +214,11 @@ JSFunctionSpec gjs_cairo_image_surface_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_image_surface_static_funcs[] = {
+ JS_FS("createFromPNG", createFromPNG_func, 1, GJS_MODULE_PROP_FLAGS),
+ JS_FS_END
+};
+
JSObject *
gjs_cairo_image_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
@@ -238,11 +243,3 @@ gjs_cairo_image_surface_from_surface(JSContext *context,
return object;
}
-void
-gjs_cairo_image_surface_init(JSContext *cx,
- JS::HandleObject ctor)
-{
- if (!JS_DefineFunction(cx, ctor, "createFromPNG", createFromPNG_func,
- 1, GJS_MODULE_PROP_FLAGS))
- return;
-}
diff --git a/modules/cairo-linear-gradient.cpp b/modules/cairo-linear-gradient.cpp
index f35571e..20abaee 100644
--- a/modules/cairo-linear-gradient.cpp
+++ b/modules/cairo-linear-gradient.cpp
@@ -77,6 +77,8 @@ JSFunctionSpec gjs_cairo_linear_gradient_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_linear_gradient_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_linear_gradient_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index aed5d81..ab5146c 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -59,6 +59,8 @@ JSFunctionSpec gjs_cairo_path_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_path_static_funcs[] = { JS_FS_END };
+
/**
* gjs_cairo_path_from_path:
* @context: the context
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index 8d816dc..95ea103 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -91,6 +91,8 @@ JSFunctionSpec gjs_cairo_pattern_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_pattern_static_funcs[] = { JS_FS_END };
+
/* Public API */
/**
diff --git a/modules/cairo-pdf-surface.cpp b/modules/cairo-pdf-surface.cpp
index 890954f..f9730a3 100644
--- a/modules/cairo-pdf-surface.cpp
+++ b/modules/cairo-pdf-surface.cpp
@@ -83,6 +83,8 @@ JSFunctionSpec gjs_cairo_pdf_surface_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_pdf_surface_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_pdf_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
diff --git a/modules/cairo-ps-surface.cpp b/modules/cairo-ps-surface.cpp
index 16df958..a8893a3 100644
--- a/modules/cairo-ps-surface.cpp
+++ b/modules/cairo-ps-surface.cpp
@@ -92,6 +92,8 @@ JSFunctionSpec gjs_cairo_ps_surface_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_ps_surface_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_ps_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
diff --git a/modules/cairo-radial-gradient.cpp b/modules/cairo-radial-gradient.cpp
index 49811e5..4bcd5e7 100644
--- a/modules/cairo-radial-gradient.cpp
+++ b/modules/cairo-radial-gradient.cpp
@@ -79,6 +79,8 @@ JSFunctionSpec gjs_cairo_radial_gradient_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_radial_gradient_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_radial_gradient_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index e91f909..72ecc7e 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -227,6 +227,8 @@ JSFunctionSpec gjs_cairo_region_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_region_static_funcs[] = { JS_FS_END };
+
static void
_gjs_cairo_region_construct_internal(JSContext *context,
JS::HandleObject obj,
diff --git a/modules/cairo-solid-pattern.cpp b/modules/cairo-solid-pattern.cpp
index 6a99ecf..793c45c 100644
--- a/modules/cairo-solid-pattern.cpp
+++ b/modules/cairo-solid-pattern.cpp
@@ -108,6 +108,8 @@ JSFunctionSpec gjs_cairo_solid_pattern_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_solid_pattern_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_solid_pattern_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
diff --git a/modules/cairo-surface-pattern.cpp b/modules/cairo-surface-pattern.cpp
index 5cc729f..a6e5ffb 100644
--- a/modules/cairo-surface-pattern.cpp
+++ b/modules/cairo-surface-pattern.cpp
@@ -182,6 +182,8 @@ JSFunctionSpec gjs_cairo_surface_pattern_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_surface_pattern_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_surface_pattern_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index e9479d1..9b85619 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -129,6 +129,8 @@ JSFunctionSpec gjs_cairo_surface_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_surface_static_funcs[] = { JS_FS_END };
+
/* Public API */
/**
diff --git a/modules/cairo-svg-surface.cpp b/modules/cairo-svg-surface.cpp
index 6e9bfa3..4e55e7d 100644
--- a/modules/cairo-svg-surface.cpp
+++ b/modules/cairo-svg-surface.cpp
@@ -83,6 +83,8 @@ JSFunctionSpec gjs_cairo_svg_surface_proto_funcs[] = {
JS_FS_END
};
+JSFunctionSpec gjs_cairo_svg_surface_static_funcs[] = { JS_FS_END };
+
JSObject *
gjs_cairo_svg_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
diff --git a/modules/cairo.cpp b/modules/cairo.cpp
index 82ca6a3..295bebd 100644
--- a/modules/cairo.cpp
+++ b/modules/cairo.cpp
@@ -73,13 +73,7 @@ gjs_js_define_cairo_stuff(JSContext *cx,
return false;
gjs_cairo_surface_init(cx);
- JS::RootedObject image_surface_ctor(cx,
- gjs_cairo_image_surface_define_constructor(cx, module));
- if (!image_surface_ctor)
- return false;
- gjs_cairo_image_surface_init(cx, image_surface_ctor);
-
- return
+ return gjs_cairo_image_surface_define_constructor(cx, module) &&
#if CAIRO_HAS_PS_SURFACE
gjs_cairo_ps_surface_define_constructor(cx, module) &&
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]