| 1757 | /// other references to the value. |
| 1758 | template <typename T> |
| 1759 | class Reference { |
| 1760 | public: |
| 1761 | static Reference<T> New(const T& value, uint32_t initialRefcount = 0); |
| 1762 | |
| 1763 | Reference(); |
| 1764 | Reference(napi_env env, napi_ref ref); |
| 1765 | ~Reference(); |
| 1766 | |
| 1767 | // A reference can be moved but cannot be copied. |
| 1768 | Reference(Reference<T>&& other); |
| 1769 | Reference<T>& operator=(Reference<T>&& other); |
| 1770 | NAPI_DISALLOW_ASSIGN(Reference<T>) |
| 1771 | |
| 1772 | operator napi_ref() const; |
| 1773 | bool operator==(const Reference<T>& other) const; |
| 1774 | bool operator!=(const Reference<T>& other) const; |
| 1775 | |
| 1776 | Napi::Env Env() const; |
| 1777 | bool IsEmpty() const; |
| 1778 | |
| 1779 | // Note when getting the value of a Reference it is usually correct to do so |
| 1780 | // within a HandleScope so that the value handle gets cleaned up efficiently. |
| 1781 | T Value() const; |
| 1782 | |
| 1783 | uint32_t Ref() const; |
| 1784 | uint32_t Unref() const; |
| 1785 | void Reset(); |
| 1786 | void Reset(const T& value, uint32_t refcount = 0); |
| 1787 | |
| 1788 | // Call this on a reference that is declared as static data, to prevent its |
| 1789 | // destructor from running at program shutdown time, which would attempt to |
| 1790 | // reset the reference when the environment is no longer valid. Avoid using |
| 1791 | // this if at all possible. If you do need to use static data, MAKE SURE to |
| 1792 | // warn your users that your addon is NOT threadsafe. |
| 1793 | void SuppressDestruct(); |
| 1794 | |
| 1795 | protected: |
| 1796 | Reference(const Reference<T>&); |
| 1797 | |
| 1798 | /// !cond INTERNAL |
| 1799 | napi_env _env; |
| 1800 | napi_ref _ref; |
| 1801 | /// !endcond |
| 1802 | |
| 1803 | private: |
| 1804 | bool _suppressDestruct; |
| 1805 | }; |
| 1806 | |
| 1807 | class ObjectReference : public Reference<Object> { |
| 1808 | public: |
nothing calls this directly
no outgoing calls
no test coverage detected