MCPcopy Create free account
hub / github.com/BabylonJS/BabylonNative / JsRuntime

Class JsRuntime

Core/JsRuntime/Include/Babylon/JsRuntime.h:10–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace Babylon
9{
10 class JsRuntime
11 {
12 public:
13 static constexpr auto JS_NATIVE_NAME = "_native";
14 using DispatchFunctionT = std::function<void(std::function<void(Napi::Env)>)>;
15
16 // Note: It is the contract of JsRuntime that its dispatch function must be usable
17 // at the moment of construction. JsRuntime cannot be built with dispatch function
18 // that captures a refence to a not-yet-completed object that will be completed
19 // later -- an instance of an inheriting type, for example. The dispatch function
20 // must be safely callable as soon as it is passed to the JsRuntime constructor.
21 static JsRuntime& CreateForJavaScript(Napi::Env, DispatchFunctionT);
22 static JsRuntime& GetFromJavaScript(Napi::Env);
23 void Dispatch(std::function<void(Napi::Env)>);
24
25 protected:
26 JsRuntime(const JsRuntime&) = delete;
27 JsRuntime(JsRuntime&&) = delete;
28
29 private:
30 JsRuntime(Napi::Env, DispatchFunctionT);
31
32 DispatchFunctionT m_dispatchFunction{};
33 std::mutex m_mutex{};
34 };
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected