-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAppRuntime_QuickJS.cpp
More file actions
46 lines (39 loc) · 1.01 KB
/
AppRuntime_QuickJS.cpp
File metadata and controls
46 lines (39 loc) · 1.01 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
#include "AppRuntime.h"
#include <napi/env.h>
#ifdef _WIN32
#pragma warning(push)
// cast from int64 to int32
#pragma warning(disable : 4244)
#endif
#include <quickjs.h>
#ifdef _WIN32
#pragma warning(pop)
#endif
namespace Babylon
{
void AppRuntime::RunEnvironmentTier(const char* /*executablePath*/)
{
// Create the runtime.
JSRuntime* runtime = JS_NewRuntime();
if (!runtime)
{
throw std::runtime_error{"Failed to create QuickJS runtime"};
}
// Create the context.
JSContext* context = JS_NewContext(runtime);
if (!context)
{
JS_FreeRuntime(runtime);
throw std::runtime_error{"Failed to create QuickJS context"};
}
// Use the context within a scope.
{
Napi::Env env = Napi::Attach(context);
Run(env);
Napi::Detach(env);
}
// Destroy the context and runtime.
JS_FreeContext(context);
JS_FreeRuntime(runtime);
}
}