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

Method RunEnvironmentTier

Core/AppRuntime/Source/AppRuntimeChakra.cpp:21–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 }
20
21 void AppRuntime::RunEnvironmentTier(const char*)
22 {
23 using DispatchFunction = std::function<void(std::function<void()>)>;
24 DispatchFunction dispatchFunction{
25 [this](std::function<void()> action) {
26 Dispatch([action = std::move(action)](Napi::Env) {
27 action();
28 });
29 }};
30
31 JsRuntimeHandle jsRuntime;
32 ThrowIfFailed(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &jsRuntime));
33 JsContextRef context;
34 ThrowIfFailed(JsCreateContext(jsRuntime, &context));
35 ThrowIfFailed(JsSetCurrentContext(context));
36 ThrowIfFailed(JsSetPromiseContinuationCallback([](JsValueRef task, void* callbackState) {
37 ThrowIfFailed(JsAddRef(task, nullptr));
38 auto* dispatch = reinterpret_cast<DispatchFunction*>(callbackState);
39 dispatch->operator()([task]() {
40 JsValueRef undefined;
41 ThrowIfFailed(JsGetUndefinedValue(&undefined));
42 ThrowIfFailed(JsCallFunction(task, &undefined, 1, nullptr));
43 ThrowIfFailed(JsRelease(task, nullptr));
44 });
45 },
46 &dispatchFunction));
47 ThrowIfFailed(JsProjectWinRTNamespace(L"Windows"));
48
49#ifdef _DEBUG
50 // Put Chakra in debug mode.
51 ThrowIfFailed(JsStartDebugging());
52#endif
53
54 Napi::Env env = Napi::Attach();
55 Run(env);
56 Napi::Detach(env);
57
58 ThrowIfFailed(JsSetCurrentContext(JS_INVALID_REFERENCE));
59 ThrowIfFailed(JsDisposeRuntime(jsRuntime));
60 }
61}

Callers

nothing calls this directly

Calls 4

AttachFunction · 0.85
ThrowIfFailedFunction · 0.70
DetachFunction · 0.50
operator()Method · 0.45

Tested by

no test coverage detected