summaryrefslogtreecommitdiff
path: root/gjs/module.cpp
diff options
context:
space:
mode:
authorMarco Trevisan (TreviƱo) <mail@3v1n0.net>2022-06-29 22:45:26 +0200
committerPhilip Chimento <philip.chimento@gmail.com>2022-11-19 12:03:46 -0800
commita075272bb538faa2c2d75d1994353216a67cc67f (patch)
tree578cc3615c42e8859fc26247607d82649061dc06 /gjs/module.cpp
parent8da51e7f4d64f43e3490ba02462b402c0d665ac7 (diff)
downloadgjs-a075272bb538faa2c2d75d1994353216a67cc67f.tar.gz
module: Use GjsAutoChar to hold the module name
Diffstat (limited to 'gjs/module.cpp')
-rw-r--r--gjs/module.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/gjs/module.cpp b/gjs/module.cpp
index c0422caf..2900fae3 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -59,20 +59,16 @@ union Utf8Unit;
}
class GjsScriptModule {
- char *m_name;
+ GjsAutoChar m_name;
// Reserved slots
static const size_t POINTER = 0;
- GjsScriptModule(const char* name) {
- m_name = g_strdup(name);
+ GjsScriptModule(const char* name) : m_name(g_strdup(name)) {
GJS_INC_COUNTER(module);
}
- ~GjsScriptModule() {
- g_free(m_name);
- GJS_DEC_COUNTER(module);
- }
+ ~GjsScriptModule() { GJS_DEC_COUNTER(module); }
GjsScriptModule(GjsScriptModule&) = delete;
GjsScriptModule& operator=(GjsScriptModule&) = delete;
@@ -103,7 +99,7 @@ class GjsScriptModule {
if (!JS_DefinePropertyById(cx, importer, name, module,
GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
gjs_debug(GJS_DEBUG_IMPORTER, "Failed to define '%s' in importer",
- m_name);
+ m_name.get());
return false;
}
@@ -144,7 +140,8 @@ class GjsScriptModule {
GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx);
gjs->schedule_gc_if_needed();
- gjs_debug(GJS_DEBUG_IMPORTER, "Importing module %s succeeded", m_name);
+ gjs_debug(GJS_DEBUG_IMPORTER, "Importing module %s succeeded",
+ m_name.get());
return true;
}
@@ -197,14 +194,14 @@ class GjsScriptModule {
* be supported according to ES6. For compatibility with earlier GJS,
* we treat it as if it were a real property, but warn about it. */
- g_warning("Some code accessed the property '%s' on the module '%s'. "
- "That property was defined with 'let' or 'const' inside the "
- "module. This was previously supported, but is not correct "
- "according to the ES6 standard. Any symbols to be exported "
- "from a module must be defined with 'var'. The property "
- "access will work as previously for the time being, but "
- "please fix your code anyway.",
- gjs_debug_id(id).c_str(), m_name);
+ g_warning(
+ "Some code accessed the property '%s' on the module '%s'. That "
+ "property was defined with 'let' or 'const' inside the module. "
+ "This was previously supported, but is not correct according to "
+ "the ES6 standard. Any symbols to be exported from a module must "
+ "be defined with 'var'. The property access will work as "
+ "previously for the time being, but please fix your code anyway.",
+ gjs_debug_id(id).c_str(), m_name.get());
JS::Rooted<JS::PropertyDescriptor> desc(cx, maybe_desc.value());
return JS_DefinePropertyById(cx, module, id, desc);