diff options
author | Evan Welsh <noreply@evanwelsh.com> | 2020-07-05 18:58:44 -0500 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2020-07-27 21:32:26 -0700 |
commit | 065df98260317e2e8c4b9ec843e16b9d931e22b3 (patch) | |
tree | bc2b7f7dbaf67e443e2332cbaafd4c7d8dd65247 /gi | |
parent | 143f24459634186e3f3871911cbe6bb7c2b88fe1 (diff) | |
download | gjs-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
Diffstat (limited to 'gi')
-rw-r--r-- | gi/function.cpp | 4 | ||||
-rw-r--r-- | gi/gtype.cpp | 1 | ||||
-rw-r--r-- | gi/ns.cpp | 1 | ||||
-rw-r--r-- | gi/object.cpp | 4 | ||||
-rw-r--r-- | gi/object.h | 1 | ||||
-rw-r--r-- | gi/repo.cpp | 11 | ||||
-rw-r--r-- | gi/wrapperutils.h | 5 |
7 files changed, 19 insertions, 8 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, }; @@ -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, |