22#include " Console.h"
33#include " Performance.h"
44#include " Require.h"
5+ #include " Timers.h"
56#include " js_native_api.h"
6- #include < iostream>
77#include < CoreFoundation/CFRunLoop.h>
8+ #include < iostream>
89
910// #include <NativeScript/NativeScript.h>
1011
1112extern " C" {
12- void objc_bridge_init (napi_env env, const char *metadata_path);
13+ void objc_bridge_init (napi_env env, const char *metadata_path);
1314}
1415
1516namespace charon {
@@ -28,9 +29,11 @@ class BytecodeBuffer : public facebook::jsi::Buffer {
2829};
2930
3031Runtime::Runtime (std::string &mainPath) : mainPath(mainPath) {
31- hermes::vm::RuntimeConfig config = hermes::vm::RuntimeConfig::Builder ().withMicrotaskQueue (true ).build ();
32+ hermes::vm::RuntimeConfig config =
33+ hermes::vm::RuntimeConfig::Builder ().withMicrotaskQueue (true ).build ();
3234 threadSafeRuntime = facebook::hermes::makeThreadSafeHermesRuntime (config);
33- runtime = (facebook::hermes::HermesRuntime *) &threadSafeRuntime->getUnsafeRuntime ();
35+ runtime =
36+ (facebook::hermes::HermesRuntime *)&threadSafeRuntime->getUnsafeRuntime ();
3437
3538 runtime->createNapiEnv (&env);
3639
@@ -40,6 +43,9 @@ Runtime::Runtime(std::string &mainPath) : mainPath(mainPath) {
4043
4144 Console::init (env);
4245 Performance::init (env);
46+ #ifdef __APPLE__
47+ Timers::init (env);
48+ #endif // __APPLE__
4349
4450 require = Require::init (env, mainPath, mainPath);
4551
@@ -84,31 +90,32 @@ int Runtime::executeBytecode(const uint8_t *data, size_t size) {
8490 return 0 ;
8591}
8692
87- bool Runtime::eventLoopStep () {
88- return !runtime->drainMicrotasks ();
89- }
93+ bool Runtime::eventLoopStep () { return !runtime->drainMicrotasks (); }
9094
9195void Runtime::addEventLoopToRunLoop (bool exitOnEmpty) {
92- auto handler = ^void (CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
93- if (activity == kCFRunLoopBeforeWaiting ){
94- bool moreWork = this ->eventLoopStep ();
95- if (moreWork) {
96- CFRunLoopWakeUp (CFRunLoopGetMain ());
97- } else if (exitOnEmpty) {
98- CFRunLoopStop (CFRunLoopGetMain ());
99- }
100- }
101- };
102-
103- CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler (kCFAllocatorDefault , kCFRunLoopAllActivities , true , 0 , handler);
96+ auto handler =
97+ ^void (CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
98+ if (activity == kCFRunLoopBeforeWaiting ) {
99+ bool moreWork = this ->eventLoopStep ();
100+ if (moreWork) {
101+ CFRunLoopWakeUp (CFRunLoopGetMain ());
102+ } else if (exitOnEmpty) {
103+ CFRunLoopStop (CFRunLoopGetMain ());
104+ }
105+ }
106+ };
107+
108+ CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler (
109+ kCFAllocatorDefault , kCFRunLoopAllActivities , true , 0 , handler);
104110 CFRunLoopAddObserver (CFRunLoopGetMain (), observer, kCFRunLoopDefaultMode );
105111}
106112
107113void Runtime::runRunLoop () {
108114 // Why does this not stop?
109115 // while (true) {
110- // CFRunLoopRunResult result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
111- // if (result == kCFRunLoopRunFinished || result == kCFRunLoopRunStopped) {
116+ // CFRunLoopRunResult result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0,
117+ // true); if (result == kCFRunLoopRunFinished || result ==
118+ // kCFRunLoopRunStopped) {
112119 // break;
113120 // }
114121 // }
0 commit comments