[gjs: 16/21] context: Destroy atoms before destroying context



commit dd8efa265c4eb9572848cf0ce834fb8395e20d94
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Jun 1 12:30:53 2019 -0700

    context: Destroy atoms before destroying context
    
    In SpiderMonkey 68, the destructor of JS::Heap<jsid> can no longer be
    run after the context has shut down. So it seems to be good practice to
    decouple the lifetime of GjsAtoms (which contains JS::Heap<jsid>) from
    that of the GjsContext.

 gjs/context-private.h | 8 +++++---
 gjs/context.cpp       | 7 +++++--
 2 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/gjs/context-private.h b/gjs/context-private.h
index f3a528c9..d73b627f 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -80,7 +80,7 @@ class GjsContextPrivate {
 
     unsigned m_auto_gc_id;
 
-    GjsAtoms m_atoms;
+    GjsAtoms* m_atoms;
 
     JobQueue m_job_queue;
     unsigned m_idle_drain_handler;
@@ -152,7 +152,7 @@ class GjsContextPrivate {
     GJS_USE JSContext* context(void) const { return m_cx; }
     GJS_USE JSObject* global(void) const { return m_global.get(); }
     GJS_USE GjsProfiler* profiler(void) const { return m_profiler; }
-    GJS_USE const GjsAtoms& atoms(void) const { return m_atoms; }
+    GJS_USE const GjsAtoms& atoms(void) const { return *m_atoms; }
     GJS_USE bool destroying(void) const { return m_destroying; }
     GJS_USE bool sweeping(void) const { return m_in_gc_sweep; }
     GJS_USE const char* program_name(void) const { return m_program_name; }
@@ -175,7 +175,9 @@ class GjsContextPrivate {
         return m_object_init_list;
     }
     GJS_USE
-    static const GjsAtoms& atoms(JSContext* cx) { return from_cx(cx)->m_atoms; }
+    static const GjsAtoms& atoms(JSContext* cx) {
+        return *(from_cx(cx)->m_atoms);
+    }
 
     GJS_JSAPI_RETURN_CONVENTION
     bool eval(const char* script, ssize_t script_len, const char* filename,
diff --git a/gjs/context.cpp b/gjs/context.cpp
index f14846d5..d9812728 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -300,7 +300,7 @@ gjs_context_class_init(GjsContextClass *klass)
 void GjsContextPrivate::trace(JSTracer* trc, void* data) {
     auto* gjs = static_cast<GjsContextPrivate*>(data);
     JS::TraceEdge<JSObject*>(trc, &gjs->m_global, "GJS global object");
-    gjs->m_atoms.trace(trc);
+    gjs->m_atoms->trace(trc);
     gjs->m_job_queue.trace(trc);
     gjs->m_object_init_list.trace(trc);
 }
@@ -393,6 +393,7 @@ void GjsContextPrivate::dispose(void) {
         gjs_debug(GJS_DEBUG_CONTEXT, "Freeing allocated resources");
         delete m_fundamental_table;
         delete m_gtype_table;
+        delete m_atoms;
 
         /* Tear down JS */
         JS_DestroyContext(m_cx);
@@ -476,6 +477,8 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
     if (!m_gtype_table->init())
         g_error("Failed to initialize GType objects table");
 
+    m_atoms = new GjsAtoms();
+
     JS_BeginRequest(m_cx);
 
     JS::RootedObject global(m_cx, gjs_create_global_object(m_cx));
@@ -489,7 +492,7 @@ GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
     m_global = global;
     JS_AddExtraGCRootsTracer(m_cx, &GjsContextPrivate::trace, this);
 
-    if (!m_atoms.init_atoms(m_cx)) {
+    if (!m_atoms->init_atoms(m_cx)) {
         gjs_log_exception(m_cx);
         g_error("Failed to initialize global strings");
     }


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