[gjs: 2/6] JSID_* macros have been replaced with a class-based API




commit 745238c9edccaec21e7697a5f7649e34ca223db8
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Jul 10 20:49:11 2021 -0700

    JSID_* macros have been replaced with a class-based API
    
    See https://bugzilla.mozilla.org/show_bug.cgi?id=1717279
    See https://bugzilla.mozilla.org/show_bug.cgi?id=1695736
    
    (Philip: Replaced ATOM stuff with String, as all atom IDs are string IDs
    and vice versa)

 gi/boxed.cpp              | 4 ++--
 gi/ns.cpp                 | 4 ++--
 gi/object.cpp             | 8 ++++----
 gi/object.h               | 9 ++++-----
 gi/private.cpp            | 3 +--
 gi/repo.cpp               | 4 ++--
 gjs/importer.cpp          | 6 +++---
 gjs/jsapi-util-string.cpp | 6 +++---
 8 files changed, 21 insertions(+), 23 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index d39a7a53..531544df 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -230,13 +230,13 @@ bool BoxedInstance::init_from_props(JSContext* context, JS::Value props_value) {
 
     JS::RootedValue value(context);
     for (ix = 0, length = ids.length(); ix < length; ix++) {
-        if (!JSID_IS_STRING(ids[ix])) {
+        if (!ids[ix].isString()) {
             gjs_throw(context, "Fields hash contained a non-string field");
             return false;
         }
 
         GIFieldInfo* field_info =
-            get_prototype()->lookup_field(context, JSID_TO_STRING(ids[ix]));
+            get_prototype()->lookup_field(context, ids[ix].toString());
         if (!field_info)
             return false;
 
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 54ab994d..552afe0b 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -10,7 +10,7 @@
 #include <js/CallArgs.h>
 #include <js/Class.h>
 #include <js/ComparisonOperators.h>
-#include <js/Id.h>  // for JSID_IS_STRING
+#include <js/Id.h>
 #include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -80,7 +80,7 @@ class Ns : private GjsAutoChar, public CWrapper<Ns> {
     GJS_JSAPI_RETURN_CONVENTION
     bool resolve_impl(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
                       bool* resolved) {
-        if (!JSID_IS_STRING(id)) {
+        if (!id.isString()) {
             *resolved = false;
             return true;  // not resolved, but no error
         }
diff --git a/gi/object.cpp b/gi/object.cpp
index 3b1a1bd0..593fa7cb 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -627,7 +627,7 @@ bool ObjectPrototype::lazy_define_gobject_property(JSContext* cx,
 
     debug_jsprop("Defining lazy GObject property", id, obj);
 
-    JS::RootedValue private_id(cx, JS::StringValue(JSID_TO_STRING(id)));
+    JS::RootedValue private_id(cx, JS::StringValue(id.toString()));
     if (!gjs_define_property_dynamic(
             cx, obj, name, "gobject_prop", &ObjectBase::prop_getter,
             &ObjectBase::prop_setter, private_id,
@@ -849,7 +849,7 @@ bool ObjectPrototype::uncached_resolve(JSContext* context, JS::HandleObject obj,
         if (!(g_field_info_get_flags(field_info) & GI_FIELD_IS_WRITABLE))
             flags |= JSPROP_READONLY;
 
-        JS::RootedString key(context, JSID_TO_STRING(id));
+        JS::RootedString key(context, id.toString());
         if (!m_field_cache.putNew(key, field_info.release())) {
             JS_ReportOutOfMemory(context);
             return false;
@@ -1023,11 +1023,11 @@ bool ObjectPrototype::props_to_g_parameters(JSContext* context,
          * doesn't know that */
         prop_id = ids[ix];
 
-        if (!JSID_IS_STRING(prop_id))
+        if (!prop_id.isString())
             return gjs_wrapper_throw_nonexistent_field(
                 context, m_gtype, gjs_debug_id(prop_id).c_str());
 
-        JS::RootedString js_prop_name(context, JSID_TO_STRING(prop_id));
+        JS::RootedString js_prop_name(context, prop_id.toString());
         GParamSpec *param_spec = find_param_spec_from_id(context, js_prop_name);
         if (!param_spec)
             return false;
diff --git a/gi/object.h b/gi/object.h
index c3fbad2f..8bd88957 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -24,7 +24,6 @@
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
-#include <jsfriendapi.h>            // for JSID_IS_ATOM, JSID_TO_ATOM
 #include <mozilla/HashFunctions.h>  // for HashGeneric, HashNumber
 #include <mozilla/Likely.h>         // for MOZ_LIKELY
 
@@ -170,10 +169,10 @@ class ObjectBase
 struct IdHasher {
     typedef jsid Lookup;
     static mozilla::HashNumber hash(jsid id) {
-        if (MOZ_LIKELY(JSID_IS_ATOM(id)))
-            return js::DefaultHasher<JSAtom*>::hash(JSID_TO_ATOM(id));
-        if (JSID_IS_SYMBOL(id))
-            return js::DefaultHasher<JS::Symbol*>::hash(JSID_TO_SYMBOL(id));
+        if (MOZ_LIKELY(id.isString()))
+            return js::DefaultHasher<JSString*>::hash(id.toString());
+        if (id.isSymbol())
+            return js::DefaultHasher<JS::Symbol*>::hash(id.toSymbol());
         return mozilla::HashGeneric(JSID_BITS(id));
     }
     static bool match(jsid id1, jsid id2) { return id1 == id2; }
diff --git a/gi/private.cpp b/gi/private.cpp
index 33e9ff00..4a07afb1 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -12,7 +12,6 @@
 
 #include <js/Array.h>  // for JS::GetArrayLength,
 #include <js/CallArgs.h>
-#include <js/Id.h>  // for JSID_TO_SYMBOL
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
@@ -400,7 +399,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool symbol_getter(JSContext* cx,
                                                       JS::Value* vp) {
     JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
-    args.rval().setSymbol(JSID_TO_SYMBOL((atoms.*member)()));
+    args.rval().setSymbol((atoms.*member)().toSymbol());
     return true;
 }
 
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 70564e5c..34ebedde 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -17,7 +17,7 @@
 
 #include <js/Class.h>
 #include <js/ComparisonOperators.h>
-#include <js/Id.h>                  // for JSID_IS_STRING, JSID_VOID
+#include <js/Id.h>                  // for JSID_VOID
 #include <js/PropertyDescriptor.h>  // for JSPROP_PERMANENT, JSPROP_RESOLVING
 #include <js/RootingAPI.h>
 #include <js/TypeDecls.h>
@@ -156,7 +156,7 @@ repo_resolve(JSContext       *context,
              JS::HandleId     id,
              bool            *resolved)
 {
-    if (!JSID_IS_STRING(id)) {
+    if (!id.isString()) {
         *resolved = false;
         return true; /* not resolved, but no error */
     }
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index b7dfba95..0dbb2b6e 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -23,7 +23,7 @@
 #include <js/CharacterEncoding.h>
 #include <js/Class.h>
 #include <js/ComparisonOperators.h>
-#include <js/Id.h>        // for PropertyKey, JSID_IS_STRING
+#include <js/Id.h>  // for PropertyKey
 #include <js/PropertyDescriptor.h>
 #include <js/PropertySpec.h>
 #include <js/RootingAPI.h>
@@ -714,7 +714,7 @@ importer_resolve(JSContext        *context,
                  JS::HandleId      id,
                  bool             *resolved)
 {
-    if (!JSID_IS_STRING(id)) {
+    if (!id.isString()) {
         *resolved = false;
         return true;
     }
@@ -729,7 +729,7 @@ importer_resolve(JSContext        *context,
     gjs_debug_jsprop(GJS_DEBUG_IMPORTER, "Resolve prop '%s' hook, obj %s",
                      gjs_debug_id(id).c_str(), gjs_debug_object(obj).c_str());
 
-    if (!JSID_IS_STRING(id)) {
+    if (!id.isString()) {
         *resolved = false;
         return true;
     }
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 692a719d..1d510058 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -20,7 +20,7 @@
 #include <js/CharacterEncoding.h>
 #include <js/Class.h>
 #include <js/GCAPI.h>  // for AutoCheckCannotGC
-#include <js/Id.h>     // for JSID_IS_STRING...
+#include <js/Id.h>
 #include <js/Promise.h>
 #include <js/RootingAPI.h>
 #include <js/Symbol.h>
@@ -430,7 +430,7 @@ gjs_string_from_ucs4(JSContext             *cx,
  * Returns: false on error, otherwise true
  **/
 bool gjs_get_string_id(JSContext* cx, jsid id, JS::UniqueChars* name_p) {
-    if (!JSID_IS_STRING(id)) {
+    if (!id.isString()) {
         name_p->reset();
         return true;
     }
@@ -653,7 +653,7 @@ gjs_debug_value(JS::Value v)
 std::string
 gjs_debug_id(jsid id)
 {
-    if (JSID_IS_STRING(id))
+    if (id.isString())
         return gjs_debug_linear_string(JSID_TO_LINEAR_STRING(id), NoQuotes);
     return gjs_debug_value(js::IdToValue(id));
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]