Skip to content

Commit 4e6b5f3

Browse files
edusperoniNathanWalker
authored andcommitted
chore: format Runtime files
1 parent 59ebb30 commit 4e6b5f3

File tree

2 files changed

+341
-312
lines changed

2 files changed

+341
-312
lines changed

NativeScript/runtime/Runtime.h

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,93 @@
11
#ifndef Runtime_h
22
#define Runtime_h
33

4-
#include "libplatform/libplatform.h"
4+
#include "Caches.h"
55
#include "Common.h"
6-
#include "ModuleInternal.h"
76
#include "MetadataBuilder.h"
7+
#include "ModuleInternal.h"
88
#include "SpinLock.h"
9-
#include "Caches.h"
9+
#include "libplatform/libplatform.h"
1010

1111
namespace tns {
1212

1313
class Runtime {
14-
public:
15-
Runtime();
16-
~Runtime();
17-
v8::Isolate* CreateIsolate();
18-
void Init(v8::Isolate* isolate, bool isWorker = false);
19-
void RunMainScript();
20-
v8::Isolate* GetIsolate();
21-
22-
const int WorkerId();
23-
24-
void SetWorkerId(int workerId);
25-
inline bool IsRuntimeWorker() {
26-
return workerId_ > 0;
27-
}
28-
29-
inline CFRunLoopRef RuntimeLoop() {
30-
return runtimeLoop_;
31-
}
14+
public:
15+
Runtime();
16+
~Runtime();
17+
v8::Isolate* CreateIsolate();
18+
void Init(v8::Isolate* isolate, bool isWorker = false);
19+
void RunMainScript();
20+
v8::Isolate* GetIsolate();
3221

33-
void RunModule(const std::string moduleName);
34-
35-
void RunScript(const std::string script);
22+
const int WorkerId();
3623

37-
static void Initialize();
24+
void SetWorkerId(int workerId);
25+
inline bool IsRuntimeWorker() { return workerId_ > 0; }
3826

39-
static Runtime* GetCurrentRuntime() {
40-
return currentRuntime_;
41-
}
42-
43-
static Runtime* GetRuntime(v8::Isolate* isolate);
27+
inline CFRunLoopRef RuntimeLoop() { return runtimeLoop_; }
4428

45-
static bool IsWorker() {
46-
if (currentRuntime_ == nullptr) {
47-
return false;
48-
}
29+
void RunModule(const std::string moduleName);
4930

50-
return currentRuntime_->IsRuntimeWorker();
51-
}
31+
void RunScript(const std::string script);
32+
33+
static void Initialize();
34+
35+
static Runtime* GetCurrentRuntime() { return currentRuntime_; }
36+
37+
static Runtime* GetRuntime(v8::Isolate* isolate);
5238

53-
static std::shared_ptr<v8::Platform> GetPlatform() {
54-
return platform_;
39+
static bool IsWorker() {
40+
if (currentRuntime_ == nullptr) {
41+
return false;
5542
}
5643

57-
static id GetAppConfigValue(std::string key);
58-
59-
static bool IsAlive(const v8::Isolate* isolate);
60-
private:
61-
static thread_local Runtime* currentRuntime_;
62-
static std::shared_ptr<v8::Platform> platform_;
63-
static std::vector<v8::Isolate*> isolates_;
64-
static SpinMutex isolatesMutex_;
65-
static bool v8Initialized_;
66-
static std::atomic<int> nextIsolateId;
67-
68-
void DefineGlobalObject(v8::Local<v8::Context> context, bool isWorker);
69-
void DefineCollectFunction(v8::Local<v8::Context> context);
70-
void DefineNativeScriptVersion(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
71-
void DefinePerformanceObject(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
72-
void DefineTimeMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
73-
void DefineDrainMicrotaskMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
74-
void DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
75-
76-
static void PerformanceNowCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
77-
v8::Isolate* isolate_;
78-
std::unique_ptr<ModuleInternal> moduleInternal_;
79-
int workerId_;
80-
CFRunLoopRef runtimeLoop_;
81-
// TODO: refactor this. This is only needed because, during program termination (UIApplicationMain not called)
82-
// the Cache::Workers is released (static initialization order fiasco https://en.cppreference.com/w/cpp/language/siof)
83-
// so it released the Cache::Workers shared_ptr and then releases the Runtime unique_ptr
84-
// eventually we just need to refactor so that Runtime::Initialize is responsible for its initalization
85-
// and lifecycle
86-
std::shared_ptr<ConcurrentMap<int, std::shared_ptr<Caches::WorkerState>>> workerCache_;
44+
return currentRuntime_->IsRuntimeWorker();
45+
}
46+
47+
static std::shared_ptr<v8::Platform> GetPlatform() { return platform_; }
48+
49+
static id GetAppConfigValue(std::string key);
50+
51+
static bool IsAlive(const v8::Isolate* isolate);
52+
53+
private:
54+
static thread_local Runtime* currentRuntime_;
55+
static std::shared_ptr<v8::Platform> platform_;
56+
static std::vector<v8::Isolate*> isolates_;
57+
static SpinMutex isolatesMutex_;
58+
static bool v8Initialized_;
59+
static std::atomic<int> nextIsolateId;
60+
61+
void DefineGlobalObject(v8::Local<v8::Context> context, bool isWorker);
62+
void DefineCollectFunction(v8::Local<v8::Context> context);
63+
void DefineNativeScriptVersion(v8::Isolate* isolate,
64+
v8::Local<v8::ObjectTemplate> globalTemplate);
65+
void DefinePerformanceObject(v8::Isolate* isolate,
66+
v8::Local<v8::ObjectTemplate> globalTemplate);
67+
void DefineTimeMethod(v8::Isolate* isolate,
68+
v8::Local<v8::ObjectTemplate> globalTemplate);
69+
void DefineDrainMicrotaskMethod(v8::Isolate* isolate,
70+
v8::Local<v8::ObjectTemplate> globalTemplate);
71+
void DefineDateTimeConfigurationChangeNotificationMethod(
72+
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
73+
74+
static void PerformanceNowCallback(
75+
const v8::FunctionCallbackInfo<v8::Value>& args);
76+
v8::Isolate* isolate_;
77+
std::unique_ptr<ModuleInternal> moduleInternal_;
78+
int workerId_;
79+
CFRunLoopRef runtimeLoop_;
80+
// TODO: refactor this. This is only needed because, during program
81+
// termination (UIApplicationMain not called) the Cache::Workers is released
82+
// (static initialization order fiasco
83+
// https://en.cppreference.com/w/cpp/language/siof) so it released the
84+
// Cache::Workers shared_ptr and then releases the Runtime unique_ptr
85+
// eventually we just need to refactor so that Runtime::Initialize is
86+
// responsible for its initalization and lifecycle
87+
std::shared_ptr<ConcurrentMap<int, std::shared_ptr<Caches::WorkerState>>>
88+
workerCache_;
8789
};
8890

89-
}
91+
} // namespace tns
9092

9193
#endif /* Runtime_h */

0 commit comments

Comments
 (0)