1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo)
2 
3 #pragma once
4 
5 #include <jsi/jsi.h>
6 
7 #include <memory>
8 
9 namespace expo {
10 
11 namespace jsi = facebook::jsi;
12 
13 class JavaScriptRuntime;
14 
15 /**
16  * A convenient class to access underlying jni::Runtime and hold a weak reference to expo::JavaScriptRuntime.
17  * It's working like std::weak_ptr but can have more helper methods.
18  */
19 class WeakRuntimeHolder : public std::weak_ptr<JavaScriptRuntime> {
20 public:
21   WeakRuntimeHolder() = default;
22 
23   WeakRuntimeHolder(WeakRuntimeHolder const &) = default;
24 
25   WeakRuntimeHolder(WeakRuntimeHolder &&) = default;
26 
27   WeakRuntimeHolder(std::weak_ptr<JavaScriptRuntime> runtime);
28 
29   /**
30    * @return an reference to the jsi::Runtime.
31    */
32   jsi::Runtime &getJSRuntime();
33 
34   void ensureRuntimeIsValid();
35 };
36 } // namespace expo
37