| 2222 | } |
| 2223 | |
| 2224 | void ObjectInstance::toggle_up() { |
| 2225 | if (G_UNLIKELY(!m_ptr || m_gobj_disposed || m_gobj_finalized)) { |
| 2226 | gjs_debug_lifecycle( |
| 2227 | GJS_DEBUG_GOBJECT, |
| 2228 | "Avoid toggling up a wrapper for a %s object: %p (%s)", |
| 2229 | m_ptr ? (m_gobj_finalized ? "finalized" : "disposed") : "released", |
| 2230 | m_ptr ? m_ptr.as<void>() : this, g_type_name(gtype())); |
| 2231 | return; |
| 2232 | } |
| 2233 | |
| 2234 | /* We need to root the JSObject associated with the passed in GObject so it |
| 2235 | * doesn't get garbage collected (and lose any associated javascript state |
| 2236 | * such as custom properties). |
| 2237 | */ |
| 2238 | if (!has_wrapper()) // Object already GC'd |
| 2239 | return; |
| 2240 | |
| 2241 | debug_lifecycle("Toggle notify UP"); |
| 2242 | |
| 2243 | /* Change to strong ref so the wrappee keeps the wrapper alive in case the |
| 2244 | * wrapper has data in it that the app cares about |
| 2245 | */ |
| 2246 | if (!wrapper_is_rooted()) { |
| 2247 | // FIXME: thread the context through somehow. Maybe by looking up the |
| 2248 | // realm that obj belongs to. |
| 2249 | debug_lifecycle("Rooting wrapper"); |
| 2250 | JSContext* cx = GjsContextPrivate::from_current_context()->context(); |
| 2251 | switch_to_rooted(cx); |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | static void toggle_handler(ObjectInstance* self, |
| 2256 | ToggleQueue::Direction direction) { |
no test coverage detected