1 // Copyright 2022-present 650 Industries. All rights reserved. 2 3 #ifdef __cplusplus 4 5 #import <jsi/jsi.h> 6 7 namespace jsi = facebook::jsi; 8 9 namespace expo::common { 10 11 class JSI_EXPORT ObjectDeallocator : public jsi::HostObject { 12 public: 13 typedef std::function<void()> Block; 14 ObjectDeallocator(const Block deallocator)15 ObjectDeallocator(const Block deallocator) : deallocator(deallocator) {}; 16 ~ObjectDeallocator()17 virtual ~ObjectDeallocator() { 18 deallocator(); 19 } 20 21 const Block deallocator; 22 23 }; // class ObjectDeallocator 24 25 /** 26 Sets the deallocator block on a given object, which is called when the object is being deallocated. 27 */ 28 void setDeallocator( 29 jsi::Runtime &runtime, 30 const std::shared_ptr<jsi::Object> &jsThis, 31 ObjectDeallocator::Block deallocatorBlock, 32 const std::string &key = "__expo_object_deallocator__" 33 ); 34 35 } // namespace expo::common 36 37 #endif 38