| 89 | void ObjectBox::destroy_impl(ObjectBox::impl* impl) { delete impl; } |
| 90 | |
| 91 | ObjectBox::Ptr ObjectBox::boxed(JSContext* cx, JSObject* obj) { |
| 92 | ObjectBox::Ptr box; |
| 93 | |
| 94 | ObjectBox** found = |
| 95 | std::find_if(m_wrappers.begin(), m_wrappers.end(), |
| 96 | [obj](ObjectBox* b) { return b->m_impl->m_root == obj; }); |
| 97 | if (found != m_wrappers.end()) { |
| 98 | box = *found; |
| 99 | box->m_impl->ref(); |
| 100 | box->m_impl->debug("Reusing box"); |
| 101 | } else { |
| 102 | box = new ObjectBox(obj); |
| 103 | if (!box->m_impl->init(cx)) |
| 104 | return nullptr; |
| 105 | } |
| 106 | |
| 107 | return box; |
| 108 | } |
| 109 | |
| 110 | JSObject* ObjectBox::object_for_c_ptr(JSContext* cx, ObjectBox* box) { |
| 111 | if (!box) { |