| 161 | } |
| 162 | |
| 163 | bool Closure::invoke(JS::HandleObject this_obj, |
| 164 | const JS::HandleValueArray& args, |
| 165 | JS::MutableHandleValue retval) { |
| 166 | if (!m_callable) { |
| 167 | // We were destroyed; become a no-op |
| 168 | reset(); |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | JSAutoRealm ar{m_cx, m_callable.get()}; |
| 173 | |
| 174 | if (gjs_log_exception(m_cx)) { |
| 175 | gjs_debug_closure( |
| 176 | "Exception was pending before invoking callback??? " |
| 177 | "Not expected - closure %p", |
| 178 | this); |
| 179 | } |
| 180 | |
| 181 | JS::RootedValue v_callable{m_cx, JS::ObjectValue(*m_callable.get())}; |
| 182 | if (!JS::Call(m_cx, this_obj, v_callable, args, retval)) { |
| 183 | gjs_debug_closure( |
| 184 | "Closure invocation failed (exception should have been thrown) " |
| 185 | "closure %p callable %p", |
| 186 | this, m_callable.debug_addr()); |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | if (gjs_log_exception_uncaught(m_cx)) { |
| 191 | gjs_debug_closure( |
| 192 | "Closure invocation succeeded but an exception was set" |
| 193 | " - closure %p", |
| 194 | m_cx); |
| 195 | } |
| 196 | |
| 197 | GjsContextPrivate* gjs = GjsContextPrivate::from_cx(m_cx); |
| 198 | gjs->schedule_gc_if_needed(); |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | } // namespace Gjs |
no test coverage detected