summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Welsh <noreply@evanwelsh.com>2020-07-05 18:58:44 -0500
committerPhilip Chimento <philip.chimento@gmail.com>2020-07-27 21:32:26 -0700
commit065df98260317e2e8c4b9ec843e16b9d931e22b3 (patch)
treebc2b7f7dbaf67e443e2332cbaafd4c7d8dd65247
parent143f24459634186e3f3871911cbe6bb7c2b88fe1 (diff)
downloadgjs-065df98260317e2e8c4b9ec843e16b9d931e22b3.tar.gz
js: Define Symbol.toStringTag names on all our custom classes
SpiderMonkey 78 will stop using the JSClass.name string as the string tag. For backwards compatibility, we should make sure the string tag doesn't change. See: GNOME/gjs#329
-rw-r--r--gi/function.cpp4
-rw-r--r--gi/gtype.cpp1
-rw-r--r--gi/ns.cpp1
-rw-r--r--gi/object.cpp4
-rw-r--r--gi/object.h1
-rw-r--r--gi/repo.cpp11
-rw-r--r--gi/wrapperutils.h5
-rw-r--r--gjs/global.cpp10
-rw-r--r--gjs/importer.cpp5
-rw-r--r--modules/cairo-context.cpp7
-rw-r--r--modules/cairo-gradient.cpp7
-rw-r--r--modules/cairo-image-surface.cpp7
-rw-r--r--modules/cairo-linear-gradient.cpp5
-rw-r--r--modules/cairo-path.cpp7
-rw-r--r--modules/cairo-pattern.cpp4
-rw-r--r--modules/cairo-pdf-surface.cpp7
-rw-r--r--modules/cairo-ps-surface.cpp7
-rw-r--r--modules/cairo-radial-gradient.cpp5
-rw-r--r--modules/cairo-region.cpp7
-rw-r--r--modules/cairo-solid-pattern.cpp7
-rw-r--r--modules/cairo-surface-pattern.cpp5
-rw-r--r--modules/cairo-surface.cpp7
-rw-r--r--modules/cairo-svg-surface.cpp7
23 files changed, 93 insertions, 38 deletions
diff --git a/gi/function.cpp b/gi/function.cpp
index 9706e84e..2ec76a17 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1596,8 +1596,8 @@ struct JSClass gjs_function_class = {
static JSPropertySpec gjs_function_proto_props[] = {
JS_PSG("length", get_num_arguments, JSPROP_PERMANENT),
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "GIRepositoryFunction", JSPROP_READONLY),
+ JS_PS_END};
/* The original Function.prototype.toString complains when
given a GIRepository function as an argument */
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 70cbe245..b17d2419 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -106,6 +106,7 @@ get_name_func (JSContext *context,
/* Properties */
JSPropertySpec gjs_gtype_proto_props[] = {
JS_PSG("name", get_name_func, JSPROP_PERMANENT),
+ JS_STRING_SYM_PS(toStringTag, "GIRepositoryGType", JSPROP_READONLY),
JS_PS_END,
};
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 4f6f4f0f..79681f7e 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -200,6 +200,7 @@ struct JSClass gjs_ns_class = {
};
static JSPropertySpec gjs_ns_proto_props[] = {
+ JS_STRING_SYM_PS(toStringTag, "GIRepositoryNamespace", JSPROP_READONLY),
JS_PSG("__name__", get_name, GJS_MODULE_PROP_FLAGS),
JS_PS_END
};
diff --git a/gi/object.cpp b/gi/object.cpp
index 6cd83ed8..f71ebde6 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2242,6 +2242,10 @@ JSFunctionSpec ObjectBase::proto_methods[] = {
JS_FN("emit", &ObjectBase::emit, 0, 0),
JS_FS_END
};
+
+JSPropertySpec ObjectBase::proto_properties[] = {
+ JS_STRING_SYM_PS(toStringTag, "GObject_Object", JSPROP_READONLY),
+ JS_PS_END};
// clang-format on
// Override of GIWrapperPrototype::get_parent_proto()
diff --git a/gi/object.h b/gi/object.h
index ff8de37c..b90b4221 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -111,6 +111,7 @@ class ObjectBase
static const struct JSClassOps class_ops;
static const struct JSClass klass;
static JSFunctionSpec proto_methods[];
+ static JSPropertySpec proto_properties[];
static GObject* to_c_ptr(JSContext* cx, JS::HandleObject obj) = delete;
GJS_JSAPI_RETURN_CONVENTION
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 25b4369d..af9a7234 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -33,6 +33,7 @@
#include <js/Class.h>
#include <js/Id.h> // for JSID_IS_STRING, JSID_VOID
#include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT, JSPROP_RESOLVING
+#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <js/Utility.h> // for UniqueChars
@@ -60,9 +61,6 @@
#include "gjs/mem-private.h"
#include "util/log.h"
-struct JSFunctionSpec;
-struct JSPropertySpec;
-
typedef struct {
void *dummy;
@@ -250,7 +248,12 @@ struct JSClass gjs_repo_class = {
&gjs_repo_class_ops,
};
-static JSPropertySpec *gjs_repo_proto_props = nullptr;
+// clang-format off
+static const JSPropertySpec gjs_repo_proto_props[] = {
+ JS_STRING_SYM_PS(toStringTag, "GIRepository", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
+
static JSFunctionSpec *gjs_repo_proto_funcs = nullptr;
static JSFunctionSpec *gjs_repo_static_funcs = nullptr;
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index a83bce5a..a0025057 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -160,6 +160,7 @@ class GIWrapperBase {
// These three can be overridden in subclasses. See define_jsclass().
static constexpr JSPropertySpec* proto_properties = nullptr;
+ static constexpr JSPropertySpec* static_properties = nullptr;
static constexpr JSFunctionSpec* proto_methods = nullptr;
static constexpr JSFunctionSpec* static_methods = nullptr;
@@ -868,8 +869,8 @@ class GIWrapperPrototype : public Base {
cx, in_object, parent_proto, gi_namespace, Base::name(),
&Base::klass, &Base::constructor, nargs, Base::proto_properties,
parent_proto ? nullptr : Base::proto_methods,
- nullptr, // static properties, MyClass.myprop; not yet needed
- Base::static_methods, prototype, constructor))
+ Base::static_properties, Base::static_methods, prototype,
+ constructor))
return false;
gjs_debug(Base::debug_topic,
diff --git a/gjs/global.cpp b/gjs/global.cpp
index f8973340..aaf6a7df 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -170,6 +170,12 @@ class GjsGlobal : GjsBaseGlobal {
&defaultclassops,
};
+ // clang-format off
+ static constexpr JSPropertySpec static_props[] = {
+ JS_STRING_SYM_PS(toStringTag, "GjsGlobal", JSPROP_READONLY),
+ JS_PS_END};
+ // clang-format on
+
static constexpr JSFunctionSpec static_funcs[] = {
JS_FS_END};
@@ -192,7 +198,8 @@ class GjsGlobal : GjsBaseGlobal {
const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
if (!JS_DefinePropertyById(cx, global, atoms.window(), global,
JSPROP_READONLY | JSPROP_PERMANENT) ||
- !JS_DefineFunctions(cx, global, GjsGlobal::static_funcs))
+ !JS_DefineFunctions(cx, global, GjsGlobal::static_funcs) ||
+ !JS_DefineProperties(cx, global, GjsGlobal::static_props))
return false;
JS::Realm* realm = JS::GetObjectRealmOrNull(global);
@@ -379,6 +386,7 @@ JS::Value detail::get_global_slot(JSObject* global, uint32_t slot) {
decltype(GjsGlobal::klass) constexpr GjsGlobal::klass;
decltype(GjsGlobal::static_funcs) constexpr GjsGlobal::static_funcs;
+decltype(GjsGlobal::static_props) constexpr GjsGlobal::static_props;
decltype(GjsDebuggerGlobal::klass) constexpr GjsDebuggerGlobal::klass;
decltype(
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 804c71ed..58192d97 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -810,7 +810,10 @@ const JSClass gjs_importer_class = {
&gjs_importer_class_ops,
};
-static JSPropertySpec *gjs_importer_proto_props = nullptr;
+static const JSPropertySpec gjs_importer_proto_props[] = {
+ JS_STRING_SYM_PS(toStringTag, "GjsFileImporter", JSPROP_READONLY),
+ JS_PS_END};
+
static JSFunctionSpec *gjs_importer_static_funcs = nullptr;
JSFunctionSpec gjs_importer_proto_funcs[] = {
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 52b7734c..8c440686 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -32,6 +32,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/Conversions.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -294,9 +295,11 @@ static void gjs_cairo_context_finalize(JSFreeOp*, JSObject* obj) {
}
/* Properties */
+// clang-format off
JSPropertySpec gjs_cairo_context_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "Context", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
/* Methods */
diff --git a/modules/cairo-gradient.cpp b/modules/cairo-gradient.cpp
index 183725ff..ca5ca89e 100644
--- a/modules/cairo-gradient.cpp
+++ b/modules/cairo-gradient.cpp
@@ -26,6 +26,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -48,9 +49,11 @@ gjs_cairo_gradient_finalize(JSFreeOp *fop,
}
/* Properties */
+// clang-format off
JSPropertySpec gjs_cairo_gradient_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "Gradient", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
/* Methods */
diff --git a/modules/cairo-image-surface.cpp b/modules/cairo-image-surface.cpp
index 407b9a7e..0e48a9e4 100644
--- a/modules/cairo-image-surface.cpp
+++ b/modules/cairo-image-surface.cpp
@@ -27,6 +27,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -79,9 +80,11 @@ gjs_cairo_image_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
+// clang-format off
JSPropertySpec gjs_cairo_image_surface_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "ImageSurface", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
GJS_JSAPI_RETURN_CONVENTION
static bool
diff --git a/modules/cairo-linear-gradient.cpp b/modules/cairo-linear-gradient.cpp
index 3b50011b..1994a541 100644
--- a/modules/cairo-linear-gradient.cpp
+++ b/modules/cairo-linear-gradient.cpp
@@ -26,6 +26,7 @@
#include <glib.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -79,8 +80,8 @@ gjs_cairo_linear_gradient_finalize(JSFreeOp *fop,
}
JSPropertySpec gjs_cairo_linear_gradient_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "LinearGradient", JSPROP_READONLY),
+ JS_PS_END};
JSFunctionSpec gjs_cairo_linear_gradient_proto_funcs[] = {
// getLinearPoints
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index 2d95318f..dce55685 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -26,6 +26,7 @@
#include <glib.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -48,9 +49,11 @@ static void gjs_cairo_path_finalize(JSFreeOp*, JSObject* obj) {
}
/* Properties */
+// clang-format off
JSPropertySpec gjs_cairo_path_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "Path", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
JSFunctionSpec gjs_cairo_path_proto_funcs[] = {
JS_FS_END
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index 8669a338..f661ea00 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -28,6 +28,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -51,8 +52,7 @@ static void gjs_cairo_pattern_finalize(JSFreeOp*, JSObject* obj) {
/* Properties */
JSPropertySpec gjs_cairo_pattern_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "Pattern", JSPROP_READONLY), JS_PS_END};
/* Methods */
diff --git a/modules/cairo-pdf-surface.cpp b/modules/cairo-pdf-surface.cpp
index 546509a0..cc6db374 100644
--- a/modules/cairo-pdf-surface.cpp
+++ b/modules/cairo-pdf-surface.cpp
@@ -34,6 +34,7 @@
# include <glib.h>
# include <js/Class.h>
+# include <js/PropertyDescriptor.h> // for JSPROP_READONLY
# include <js/PropertySpec.h>
# include <js/RootingAPI.h>
# include <jsapi.h> // for JS_NewObjectWithGivenProto
@@ -85,9 +86,11 @@ gjs_cairo_pdf_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
+// clang-format off
JSPropertySpec gjs_cairo_pdf_surface_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "PDFSurface", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
JSFunctionSpec gjs_cairo_pdf_surface_proto_funcs[] = {
JS_FS_END
diff --git a/modules/cairo-ps-surface.cpp b/modules/cairo-ps-surface.cpp
index a83e7fc8..1d3ae811 100644
--- a/modules/cairo-ps-surface.cpp
+++ b/modules/cairo-ps-surface.cpp
@@ -34,6 +34,7 @@
# include <glib.h>
# include <js/Class.h>
+# include <js/PropertyDescriptor.h> // for JSPROP_READONLY
# include <js/PropertySpec.h>
# include <js/RootingAPI.h>
# include <jsapi.h> // for JS_NewObjectWithGivenProto
@@ -85,9 +86,11 @@ gjs_cairo_ps_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
+// clang-format off
JSPropertySpec gjs_cairo_ps_surface_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "PSSurface", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
JSFunctionSpec gjs_cairo_ps_surface_proto_funcs[] = {
// restrictToLevel
diff --git a/modules/cairo-radial-gradient.cpp b/modules/cairo-radial-gradient.cpp
index 3d0e71fc..2fcc4437 100644
--- a/modules/cairo-radial-gradient.cpp
+++ b/modules/cairo-radial-gradient.cpp
@@ -26,6 +26,7 @@
#include <glib.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -81,8 +82,8 @@ gjs_cairo_radial_gradient_finalize(JSFreeOp *fop,
}
JSPropertySpec gjs_cairo_radial_gradient_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "RadialGradient", JSPROP_READONLY),
+ JS_PS_END};
JSFunctionSpec gjs_cairo_radial_gradient_proto_funcs[] = {
// getRadialCircles
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index f291732a..1d72ff21 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -30,6 +30,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/Conversions.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -222,9 +223,11 @@ get_rectangle_func(JSContext *context,
RETURN_STATUS;
}
+// clang-format off
JSPropertySpec gjs_cairo_region_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "Region", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
JSFunctionSpec gjs_cairo_region_proto_funcs[] = {
JS_FN("union", union_func, 0, 0),
diff --git a/modules/cairo-solid-pattern.cpp b/modules/cairo-solid-pattern.cpp
index e03e420a..ae43e489 100644
--- a/modules/cairo-solid-pattern.cpp
+++ b/modules/cairo-solid-pattern.cpp
@@ -27,6 +27,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -52,9 +53,11 @@ gjs_cairo_solid_pattern_finalize(JSFreeOp *fop,
gjs_cairo_pattern_finalize_pattern(fop, obj);
}
+// clang-format off
JSPropertySpec gjs_cairo_solid_pattern_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "SolidPattern", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
GJS_JSAPI_RETURN_CONVENTION
static bool
diff --git a/modules/cairo-surface-pattern.cpp b/modules/cairo-surface-pattern.cpp
index 5c522d7d..0be9a9f0 100644
--- a/modules/cairo-surface-pattern.cpp
+++ b/modules/cairo-surface-pattern.cpp
@@ -27,6 +27,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -83,8 +84,8 @@ gjs_cairo_surface_pattern_finalize(JSFreeOp *fop,
}
JSPropertySpec gjs_cairo_surface_pattern_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "SurfacePattern", JSPROP_READONLY),
+ JS_PS_END};
GJS_JSAPI_RETURN_CONVENTION
static bool
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index 4f7560b4..c95357d5 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -29,6 +29,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
+#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -55,9 +56,11 @@ static void gjs_cairo_surface_finalize(JSFreeOp*, JSObject* obj) {
}
/* Properties */
+// clang-format off
JSPropertySpec gjs_cairo_surface_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "Surface", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
/* Methods */
GJS_JSAPI_RETURN_CONVENTION
diff --git a/modules/cairo-svg-surface.cpp b/modules/cairo-svg-surface.cpp
index e620bfdb..450ebd73 100644
--- a/modules/cairo-svg-surface.cpp
+++ b/modules/cairo-svg-surface.cpp
@@ -34,6 +34,7 @@
# include <glib.h>
# include <js/Class.h>
+# include <js/PropertyDescriptor.h> // for JSPROP_READONLY
# include <js/PropertySpec.h>
# include <js/RootingAPI.h>
# include <jsapi.h> // for JS_NewObjectWithGivenProto
@@ -85,9 +86,11 @@ gjs_cairo_svg_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
+// clang-format off
JSPropertySpec gjs_cairo_svg_surface_proto_props[] = {
- JS_PS_END
-};
+ JS_STRING_SYM_PS(toStringTag, "SVGSurface", JSPROP_READONLY),
+ JS_PS_END};
+// clang-format on
JSFunctionSpec gjs_cairo_svg_surface_proto_funcs[] = {
JS_FS_END