[gjs: 4/10] atoms: Use more atoms to avoid converting strings



commit 5d5f82dfa7c0a4683d8363a19e5e97898f2706a7
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Nov 3 15:41:33 2018 -0400

    atoms: Use more atoms to avoid converting strings
    
    There are a number of places where we used JS_{Get,Set,Define}Property()
    or JS_DefineFunction() with a string literal. In these cases it would be
    better to use an atom so that the string doesn't have to be converted from
    UTF-8 internally each time.
    
    In some cases there was already an atom defined, and in others we add a
    new atom.

 gi/boxed.cpp             |  5 +++--
 gi/enumeration.cpp       | 10 ++++++----
 gi/fundamental.cpp       |  5 +++--
 gi/gtype.cpp             | 21 +++++++++++++--------
 gi/interface.cpp         |  5 +++--
 gi/object.cpp            |  5 +++--
 gi/param.cpp             |  9 +++++----
 gi/repo.cpp              | 12 ++++++------
 gi/union.cpp             |  5 +++--
 gjs/atoms.h              | 13 +++++++++++++
 gjs/byteArray.cpp        | 20 +++++++++++++++++---
 gjs/coverage.cpp         |  6 ++++--
 gjs/debugger.cpp         |  4 +++-
 gjs/global.cpp           |  6 +++---
 gjs/importer.cpp         | 17 +++++++++--------
 gjs/jsapi-class.h        | 13 ++++++++-----
 modules/cairo-region.cpp |  9 +++++----
 modules/console.cpp      |  6 ++++--
 modules/system.cpp       | 10 ++++++----
 19 files changed, 117 insertions(+), 64 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 9d6592a9..e430efb3 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -1184,8 +1184,9 @@ bool gjs_define_boxed_class(JSContext* context, JS::HandleObject in_object,
     if (!gtype_obj)
         return false;
 
-    return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
-                             JSPROP_PERMANENT);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return JS_DefinePropertyById(context, constructor, atoms.gtype(), gtype_obj,
+                                 JSPROP_PERMANENT);
 }
 
 JSObject* gjs_boxed_from_c_struct(JSContext* cx, GIStructInfo* info,
diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp
index 296e3ec1..4306bcfb 100644
--- a/gi/enumeration.cpp
+++ b/gi/enumeration.cpp
@@ -25,10 +25,11 @@
 
 #include <string.h>
 
+#include "function.h"
+#include "gjs/context-private.h"
 #include "gjs/jsapi-wrapper.h"
-#include "repo.h"
 #include "gtype.h"
-#include "function.h"
+#include "repo.h"
 
 #include <util/log.h>
 
@@ -110,8 +111,9 @@ gjs_define_enum_values(JSContext       *context,
     if (!gtype_obj)
         return false;
 
-    return JS_DefineProperty(context, in_object, "$gtype", gtype_obj,
-                             JSPROP_PERMANENT);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return JS_DefinePropertyById(context, in_object, atoms.gtype(), gtype_obj,
+                                 JSPROP_PERMANENT);
 }
 
 bool
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index b04e38b7..661ff545 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -725,8 +725,9 @@ gjs_define_fundamental_class(JSContext              *context,
     if (!gtype_obj)
         return false;
 
-    return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
-                             JSPROP_PERMANENT);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return JS_DefinePropertyById(context, constructor, atoms.gtype(), gtype_obj,
+                                 JSPROP_PERMANENT);
 }
 
 JSObject*
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 67bdad45..4f46f367 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -24,13 +24,15 @@
 
 #include <config.h>
 
+#include <girepository.h>
+
 #include <unordered_map>
 
-#include "gtype.h"
+#include "gi/gtype.h"
+#include "gjs/context-private.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include <util/log.h>
-#include <girepository.h>
+#include "util/log.h"
 
 static bool weak_pointer_callback = false;
 static std::unordered_map<GType, std::unique_ptr<JS::Heap<JSObject*>>>
@@ -177,6 +179,7 @@ gjs_gtype_create_gtype_wrapper (JSContext *context,
 
 GJS_JSAPI_RETURN_CONVENTION
 static bool _gjs_gtype_get_actual_gtype(JSContext* context,
+                                        const GjsAtoms& atoms,
                                         JS::HandleObject object,
                                         GType* gtype_out, int recurse) {
     if (JS_InstanceOf(context, object, &gjs_gtype_class, nullptr)) {
@@ -188,19 +191,20 @@ static bool _gjs_gtype_get_actual_gtype(JSContext* context,
 
     /* OK, we don't have a GType wrapper object -- grab the "$gtype"
      * property on that and hope it's a GType wrapper object */
-    if (!JS_GetProperty(context, object, "$gtype", &gtype_val))
+    if (!JS_GetPropertyById(context, object, atoms.gtype(), &gtype_val))
         return false;
     if (!gtype_val.isObject()) {
         /* OK, so we're not a class. But maybe we're an instance. Check
            for "constructor" and recurse on that. */
-        if (!JS_GetProperty(context, object, "constructor", &gtype_val))
+        if (!JS_GetPropertyById(context, object, atoms.constructor(),
+                                &gtype_val))
             return false;
     }
 
     if (recurse > 0 && gtype_val.isObject()) {
         JS::RootedObject gtype_obj(context, &gtype_val.toObject());
-        return _gjs_gtype_get_actual_gtype(context, gtype_obj, gtype_out,
-                                           recurse - 1);
+        return _gjs_gtype_get_actual_gtype(context, atoms, gtype_obj,
+                                           gtype_out, recurse - 1);
     }
 
     *gtype_out = G_TYPE_INVALID;
@@ -220,7 +224,8 @@ bool gjs_gtype_get_actual_gtype(JSContext* context, JS::HandleObject object,
        GType value.
      */
 
-    return _gjs_gtype_get_actual_gtype(context, object, gtype_out, 2);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return _gjs_gtype_get_actual_gtype(context, atoms, object, gtype_out, 2);
 }
 
 bool
diff --git a/gi/interface.cpp b/gi/interface.cpp
index f5c8e363..5378a439 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -262,8 +262,9 @@ gjs_define_interface_class(JSContext              *context,
     if (!gtype_obj)
         return false;
 
-    return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
-                             JSPROP_PERMANENT);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return JS_DefinePropertyById(context, constructor, atoms.gtype(), gtype_obj,
+                                 JSPROP_PERMANENT);
 }
 
 bool
diff --git a/gi/object.cpp b/gi/object.cpp
index ab39a329..9b081834 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -2270,8 +2270,9 @@ gjs_define_object_class(JSContext              *context,
     if (!gtype_obj)
         return false;
 
-    return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
-                             JSPROP_PERMANENT);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return JS_DefinePropertyById(context, constructor, atoms.gtype(), gtype_obj,
+                                 JSPROP_PERMANENT);
 }
 
 JSObject*
diff --git a/gi/param.cpp b/gi/param.cpp
index 3a68ad40..0d5c3277 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -170,8 +170,9 @@ gjs_lookup_param_prototype(JSContext    *context)
     if (G_UNLIKELY (!in_object))
         return NULL;
 
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
     JS::RootedValue value(context);
-    if (!JS_GetProperty(context, in_object, "ParamSpec", &value))
+    if (!JS_GetPropertyById(context, in_object, atoms.param_spec(), &value))
         return NULL;
 
     if (G_UNLIKELY (!value.isObject()))
@@ -180,7 +181,6 @@ gjs_lookup_param_prototype(JSContext    *context)
     JS::RootedObject constructor(context, &value.toObject());
     g_assert(constructor);
 
-    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
     if (!JS_GetPropertyById(context, constructor, atoms.prototype(), &value))
         return NULL;
 
@@ -217,9 +217,10 @@ gjs_define_param_class(JSContext       *context,
 
     JS::RootedObject gtype_obj(context,
         gjs_gtype_create_gtype_wrapper(context, G_TYPE_PARAM));
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
     if (!gtype_obj ||
-        !JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
-                           JSPROP_PERMANENT))
+        !JS_DefinePropertyById(context, constructor, atoms.gtype(), gtype_obj,
+                               JSPROP_PERMANENT))
         return false;
 
     GjsAutoObjectInfo info = g_irepository_find_by_gtype(nullptr, G_TYPE_PARAM);
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 404806ec..98aa3dbb 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -279,14 +279,14 @@ repo_new(JSContext *context)
      * internally.
      */
     JS::RootedString two_point_oh(context, JS_NewStringCopyZ(context, "2.0"));
-    if (!JS_DefineProperty(context, versions, "GLib", two_point_oh,
-                           JSPROP_PERMANENT))
+    if (!JS_DefinePropertyById(context, versions, atoms.glib(), two_point_oh,
+                               JSPROP_PERMANENT))
         return nullptr;
-    if (!JS_DefineProperty(context, versions, "GObject", two_point_oh,
-                           JSPROP_PERMANENT))
+    if (!JS_DefinePropertyById(context, versions, atoms.gobject(), two_point_oh,
+                               JSPROP_PERMANENT))
         return nullptr;
-    if (!JS_DefineProperty(context, versions, "Gio", two_point_oh,
-                           JSPROP_PERMANENT))
+    if (!JS_DefinePropertyById(context, versions, atoms.gio(), two_point_oh,
+                               JSPROP_PERMANENT))
         return nullptr;
 
     JS::RootedObject private_ns(context, JS_NewPlainObject(context));
diff --git a/gi/union.cpp b/gi/union.cpp
index 23d57aad..9cc5e2e7 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -359,13 +359,14 @@ gjs_define_union_class(JSContext       *context,
               constructor_name, prototype.get(), JS_GetClass(prototype),
               in_object.get());
 
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
     JS::RootedObject gtype_obj(context,
         gjs_gtype_create_gtype_wrapper(context, gtype));
     if (!gtype_obj)
         return false;
 
-    return JS_DefineProperty(context, constructor, "$gtype", gtype_obj,
-                             JSPROP_PERMANENT);
+    return JS_DefinePropertyById(context, constructor, atoms.gtype(), gtype_obj,
+                                 JSPROP_PERMANENT);
 }
 
 JSObject*
diff --git a/gjs/atoms.h b/gjs/atoms.h
index 7028e9b8..0e648e88 100644
--- a/gjs/atoms.h
+++ b/gjs/atoms.h
@@ -31,28 +31,41 @@
     macro(code, "code") \
     macro(column_number, "columnNumber") \
     macro(constructor, "constructor") \
+    macro(debuggee, "debuggee") \
+    macro(file, "__file__") \
     macro(file_name, "fileName") \
     macro(gi, "gi") \
+    macro(gio, "Gio") \
+    macro(glib, "GLib") \
+    macro(gobject, "GObject") \
+    macro(gtype, "$gtype") \
     macro(height, "height") \
     macro(imports, "imports") \
     macro(init, "_init") \
     macro(instance_init, "_instance_init") \
+    macro(interact, "interact") \
     macro(length, "length") \
     macro(line_number, "lineNumber") \
     macro(message, "message") \
     macro(module_init, "__init__") \
+    macro(module_name, "__moduleName__") \
     macro(module_path, "__modulePath__") \
     macro(name, "name") \
     macro(new_, "new") \
     macro(new_internal, "_new_internal") \
     macro(overrides, "overrides") \
+    macro(param_spec, "ParamSpec") \
     macro(parent_module, "__parentModule__") \
     macro(private_ns_marker, "__gjsPrivateNS") \
+    macro(program_invocation_name, "programInvocationName") \
     macro(prototype, "prototype") \
     macro(search_path, "searchPath") \
     macro(stack, "stack") \
+    macro(to_string, "toString") \
+    macro(version, "version") \
     macro(versions, "versions") \
     macro(width, "width") \
+    macro(window, "window") \
     macro(x, "x") \
     macro(y, "y")
 // clang-format on
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 2d2466d4..6130eb65 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -25,6 +25,7 @@
 
 #include "byteArray.h"
 #include "gi/boxed.h"
+#include "gjs/context-private.h"
 #include "gjs/deprecation.h"
 #include "jsapi-util-args.h"
 #include "jsapi-wrapper.h"
@@ -253,7 +254,12 @@ from_string_func(JSContext *context,
     if (!array_buffer)
         return false;
     obj = JS_NewUint8ArrayWithBuffer(context, array_buffer, 0, -1);
-    JS_DefineFunction(context, obj, "toString", instance_to_string_func, 1, 0);
+
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    if (!JS_DefineFunctionById(context, obj, atoms.to_string(),
+                               instance_to_string_func, 1, 0))
+        return false;
+
     argv.rval().setObject(*obj);
     return true;
 }
@@ -292,7 +298,11 @@ from_gbytes_func(JSContext *context,
         context, JS_NewUint8ArrayWithBuffer(context, array_buffer, 0, -1));
     if (!obj)
         return false;
-    JS_DefineFunction(context, obj, "toString", instance_to_string_func, 1, 0);
+
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    if (!JS_DefineFunctionById(context, obj, atoms.to_string(),
+                               instance_to_string_func, 1, 0))
+        return false;
 
     argv.rval().setObject(*obj);
     return true;
@@ -310,7 +320,11 @@ JSObject* gjs_byte_array_from_data(JSContext* cx, size_t nbytes, void* data) {
 
     JS::RootedObject array(cx,
                            JS_NewUint8ArrayWithBuffer(cx, array_buffer, 0, -1));
-    JS_DefineFunction(cx, array, "toString", instance_to_string_func, 1, 0);
+
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
+    if (!JS_DefineFunctionById(cx, array, atoms.to_string(),
+                               instance_to_string_func, 1, 0))
+        return nullptr;
     return array;
 }
 
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index b636b864..2e3055db 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -29,6 +29,7 @@
 #include <gjs/context.h>
 
 #include "coverage.h"
+#include "gjs/context-private.h"
 #include "global.h"
 #include "importer.h"
 #include "jsapi-util-args.h"
@@ -348,9 +349,10 @@ bootstrap_coverage(GjsCoverage *coverage)
         if (!JS_WrapObject(context, &debuggeeWrapper))
             return false;
 
+        const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
         JS::RootedValue debuggeeWrapperValue(context, JS::ObjectValue(*debuggeeWrapper));
-        if (!JS_SetProperty(context, debugger_compartment, "debuggee",
-                            debuggeeWrapperValue) ||
+        if (!JS_SetPropertyById(context, debugger_compartment, atoms.debuggee(),
+                                debuggeeWrapperValue) ||
             !gjs_define_global_properties(context, debugger_compartment,
                                           "coverage"))
             return false;
diff --git a/gjs/debugger.cpp b/gjs/debugger.cpp
index b83e0611..eb6c9f50 100644
--- a/gjs/debugger.cpp
+++ b/gjs/debugger.cpp
@@ -124,8 +124,10 @@ void gjs_context_setup_debugger_console(GjsContext* gjs) {
         return;
     }
 
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
     JS::RootedValue v_wrapper(cx, JS::ObjectValue(*debuggee_wrapper));
-    if (!JS_SetProperty(cx, debugger_compartment, "debuggee", v_wrapper) ||
+    if (!JS_SetPropertyById(cx, debugger_compartment, atoms.debuggee(),
+                            v_wrapper) ||
         !JS_DefineFunctions(cx, debugger_compartment, debugger_funcs) ||
         !gjs_define_global_properties(cx, debugger_compartment, "debugger"))
         gjs_log_exception(cx);
diff --git a/gjs/global.cpp b/gjs/global.cpp
index 8a1cd1d2..d6c858dc 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -261,8 +261,9 @@ class GjsGlobal {
                       JS::HandleObject global,
                       const char      *bootstrap_script)
     {
-        if (!JS_DefineProperty(cx, global, "window", global,
-                               JSPROP_READONLY | JSPROP_PERMANENT) ||
+        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))
             return false;
 
@@ -272,7 +273,6 @@ class GjsGlobal {
                   v_importer.isObject()));
         JS::RootedObject root_importer(cx, &v_importer.toObject());
 
-        const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
         /* Wrapping is a no-op if the importer is already in the same
          * compartment. */
         if (!JS_WrapObject(cx, &root_importer) ||
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 59b7c48a..d59a4480 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -103,6 +103,7 @@ define_meta_properties(JSContext       *context,
                        JS::HandleObject parent)
 {
     bool parent_is_module;
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
 
     /* For these meta-properties, don't set ENUMERATE since we wouldn't want to
      * copy these symbols to any other object for example. RESOLVING is used to
@@ -124,7 +125,8 @@ define_meta_properties(JSContext       *context,
         JS::RootedValue file(context);
         if (!gjs_string_from_utf8(context, parse_name, &file))
             return false;
-        if (!JS_DefineProperty(context, module_obj, "__file__", file, attrs))
+        if (!JS_DefinePropertyById(context, module_obj, atoms.file(), file,
+                                   attrs))
             return false;
     }
 
@@ -139,7 +141,6 @@ define_meta_properties(JSContext       *context,
             return false;
         parent_module_val.setObject(*parent);
 
-        const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
         JS::RootedValue parent_module_path(context);
         if (!JS_GetPropertyById(context, parent, atoms.module_path(),
                                 &parent_module_path))
@@ -165,16 +166,16 @@ define_meta_properties(JSContext       *context,
         to_string_tag.setString(JS_AtomizeString(context, "GjsModule"));
     }
 
-    if (!JS_DefineProperty(context, module_obj,
-                           "__moduleName__", module_name_val, attrs))
+    if (!JS_DefinePropertyById(context, module_obj, atoms.module_name(),
+                               module_name_val, attrs))
         return false;
 
-    if (!JS_DefineProperty(context, module_obj,
-                           "__parentModule__", parent_module_val, attrs))
+    if (!JS_DefinePropertyById(context, module_obj, atoms.parent_module(),
+                               parent_module_val, attrs))
         return false;
 
-    if (!JS_DefineProperty(context, module_obj, "__modulePath__", module_path,
-                           attrs))
+    if (!JS_DefinePropertyById(context, module_obj, atoms.module_path(),
+                               module_path, attrs))
         return false;
 
     JS::RootedId to_string_tag_name(context,
diff --git a/gjs/jsapi-class.h b/gjs/jsapi-class.h
index 9464191c..f765aeb7 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -24,6 +24,7 @@
 #ifndef GJS_JSAPI_CLASS_H
 #define GJS_JSAPI_CLASS_H
 
+#include "gjs/context-private.h"
 #include "global.h"
 #include "jsapi-util.h"
 #include "jsapi-wrapper.h"
@@ -216,7 +217,7 @@ GJS_DEFINE_PROTO_FUNCS_WITH_PARENT(cname, no_parent)
         return &v_proto.toObject();                                            \
     }
 
-#define _GJS_DEFINE_DEFINE_PROTO(cname, parent_cname, ctor, gtype)             \
+#define _GJS_DEFINE_DEFINE_PROTO(cname, parent_cname, ctor, type)              \
     GJS_JSAPI_RETURN_CONVENTION                                                \
     bool gjs_##cname##_define_proto(JSContext* cx, JS::HandleObject module,    \
                                     JS::MutableHandleObject proto) {           \
@@ -266,11 +267,13 @@ GJS_DEFINE_PROTO_FUNCS_WITH_PARENT(cname, no_parent)
         }                                                                      \
                                                                                \
         /* Define the GType value as a "$gtype" property on the constructor */ \
-        if (gtype != G_TYPE_NONE) {                                            \
+        if (type != G_TYPE_NONE) {                                             \
+            const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);              \
             JS::RootedObject gtype_obj(                                        \
-                cx, gjs_gtype_create_gtype_wrapper(cx, gtype));                \
-            if (!gtype_obj || !JS_DefineProperty(cx, ctor_obj, "$gtype",       \
-                                                 gtype_obj, JSPROP_PERMANENT)) \
+                cx, gjs_gtype_create_gtype_wrapper(cx, type));                 \
+            if (!gtype_obj ||                                                  \
+                !JS_DefinePropertyById(cx, ctor_obj, atoms.gtype(), gtype_obj, \
+                                       JSPROP_PERMANENT))                      \
                 return false;                                                  \
         }                                                                      \
         gjs_debug(GJS_DEBUG_CONTEXT, "Initialized class %s prototype %p",      \
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index 2a169049..cd9d31fa 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -153,25 +153,26 @@ static JSObject *
 make_rectangle(JSContext *context,
                cairo_rectangle_int_t *rect)
 {
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
     JS::RootedObject rect_obj(context, JS_NewPlainObject(context));
     if (!rect_obj)
         return nullptr;
     JS::RootedValue val(context);
 
     val = JS::Int32Value(rect->x);
-    if (!JS_SetProperty(context, rect_obj, "x", val))
+    if (!JS_SetPropertyById(context, rect_obj, atoms.x(), val))
         return nullptr;
 
     val = JS::Int32Value(rect->y);
-    if (!JS_SetProperty(context, rect_obj, "y", val))
+    if (!JS_SetPropertyById(context, rect_obj, atoms.y(), val))
         return nullptr;
 
     val = JS::Int32Value(rect->width);
-    if (!JS_SetProperty(context, rect_obj, "width", val))
+    if (!JS_SetPropertyById(context, rect_obj, atoms.width(), val))
         return nullptr;
 
     val = JS::Int32Value(rect->height);
-    if (!JS_SetProperty(context, rect_obj, "height", val))
+    if (!JS_SetPropertyById(context, rect_obj, atoms.height(), val))
         return nullptr;
 
     return rect_obj;
diff --git a/modules/console.cpp b/modules/console.cpp
index bcfd6d50..20d2f048 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -375,6 +375,8 @@ gjs_define_console_stuff(JSContext              *context,
                          JS::MutableHandleObject module)
 {
     module.set(JS_NewPlainObject(context));
-    return JS_DefineFunction(context, module, "interact", gjs_console_interact,
-                             1, GJS_MODULE_PROP_FLAGS);
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    return JS_DefineFunctionById(context, module, atoms.interact(),
+                                 gjs_console_interact, 1,
+                                 GJS_MODULE_PROP_FLAGS);
 }
diff --git a/modules/system.cpp b/modules/system.cpp
index dfaa574f..a5edd109 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -190,8 +190,10 @@ gjs_js_define_system_stuff(JSContext              *context,
     return gjs_string_from_utf8(context, program_name, &value) &&
            /* The name is modeled after program_invocation_name, part of glibc
             */
-           JS_DefineProperty(context, module, "programInvocationName", value,
-                             GJS_MODULE_PROP_FLAGS | JSPROP_READONLY) &&
-           JS_DefineProperty(context, module, "version", GJS_VERSION,
-                             GJS_MODULE_PROP_FLAGS | JSPROP_READONLY);
+           JS_DefinePropertyById(context, module,
+                                 gjs->atoms().program_invocation_name(), value,
+                                 GJS_MODULE_PROP_FLAGS | JSPROP_READONLY) &&
+           JS_DefinePropertyById(context, module, gjs->atoms().version(),
+                                 GJS_VERSION,
+                                 GJS_MODULE_PROP_FLAGS | JSPROP_READONLY);
 }


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