forked from BabylonJS/JsRuntimeHost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppRuntime_JSI.cpp
More file actions
53 lines (43 loc) · 1.32 KB
/
Copy pathAppRuntime_JSI.cpp
File metadata and controls
53 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "AppRuntime.h"
#include <napi/env.h>
#include <V8JsiRuntime.h>
#include <ScriptStore.h>
namespace
{
class TaskRunnerAdapter : public v8runtime::JSITaskRunner
{
public:
TaskRunnerAdapter(Babylon::AppRuntime& runtime)
: m_runtime(runtime)
{
}
void postTask(std::unique_ptr<v8runtime::JSITask> task) override
{
std::shared_ptr<v8runtime::JSITask> shared_task(std::move(task));
m_runtime.Dispatch([shared_task2 = std::move(shared_task)](Napi::Env) {
shared_task2->run();
});
}
private:
TaskRunnerAdapter(const TaskRunnerAdapter&) = delete;
TaskRunnerAdapter& operator=(const TaskRunnerAdapter&) = delete;
Babylon::AppRuntime& m_runtime;
};
}
namespace Babylon
{
void AppRuntime::RunEnvironmentTier(const char*)
{
v8runtime::V8RuntimeArgs args{};
args.inspectorPort = 5643;
args.foreground_task_runner = std::make_shared<TaskRunnerAdapter>(*this);
const auto runtime = v8runtime::makeV8Runtime(std::move(args));
const auto env = Napi::Attach(*runtime);
Run(env);
Napi::Detach(env);
}
void AppRuntime::DrainMicrotasks(Napi::Env)
{
// JSI/V8 backed JSI auto-drains microtasks per scope.
}
}