Skip to content

Commit 09c5acc

Browse files
authored
Add clang-format configuration (#16)
Formatted `Core` and `Polyfills` folders.
1 parent c4e0fdb commit 09c5acc

File tree

17 files changed

+116
-83
lines changed

17 files changed

+116
-83
lines changed

.clang-format

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
5+
AccessModifierOffset: -4
6+
AlignAfterOpenBracket: DontAlign
7+
AlignEscapedNewlines: Left
8+
BraceWrapping:
9+
AfterCaseLabel: true
10+
AfterClass: true
11+
AfterControlStatement: Always
12+
AfterEnum: true
13+
AfterFunction: true
14+
AfterNamespace: true
15+
AfterObjCDeclaration: true
16+
AfterStruct: true
17+
AfterUnion: true
18+
AfterExternBlock: true
19+
BeforeCatch: true
20+
BeforeElse: true
21+
BeforeWhile: true
22+
BreakBeforeBraces: Custom
23+
BreakConstructorInitializers: BeforeComma
24+
BreakStringLiterals: false
25+
ColumnLimit: 0
26+
FixNamespaceComments: false
27+
IndentCaseLabels: true
28+
IndentWidth: 4
29+
KeepEmptyLinesAtTheStartOfBlocks: false
30+
NamespaceIndentation: All
31+
ReflowComments: false
32+
PackConstructorInitializers: Never
33+
PointerAlignment: Left
34+
SortIncludes: Never
35+
SortUsingDeclarations: false
36+
SpaceAfterTemplateKeyword: false

Core/AppRuntime/Include/Babylon/Dispatchable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Babylon
2929
{
3030
public:
3131
DispatchableImpl(DispatchableImpl<CallableT, ReturnT(ArgsT...)>&& other) = default;
32-
32+
3333
DispatchableImpl(CallableT&& callable)
3434
: m_callable{std::forward<CallableT>(callable)}
3535
{

Core/AppRuntime/Source/AppRuntime_JSI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Babylon
3838
v8runtime::V8RuntimeArgs args{};
3939
args.inspectorPort = 5643;
4040
args.foreground_task_runner = std::make_shared<TaskRunnerAdapter>(*m_workQueue);
41-
41+
4242
const auto runtime{v8runtime::makeV8Runtime(std::move(args))};
4343
const auto env{Napi::Attach<facebook::jsi::Runtime&>(*runtime)};
4444
Dispatch([&runtime](Napi::Env env) {

Core/AppRuntime/Source/WorkQueue.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ namespace Babylon
2323
// copyable callable if necessary.
2424
if constexpr (std::is_copy_constructible<CallableT>::value)
2525
{
26-
m_dispatcher.queue([this, callable = std::move(callable)]()
27-
{ Invoke(callable); });
26+
m_dispatcher.queue([this, callable = std::move(callable)]() {
27+
Invoke(callable);
28+
});
2829
}
2930
else
3031
{
31-
m_dispatcher.queue([this, callablePtr = std::make_shared<CallableT>(std::move(callable))]()
32-
{ Invoke(*callablePtr); });
32+
m_dispatcher.queue([this, callablePtr = std::make_shared<CallableT>(std::move(callable))]() {
33+
Invoke(*callablePtr);
34+
});
3335
}
3436
}
3537

Core/JsRuntime/Include/Babylon/JsRuntime.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Babylon
1414
{
1515
friend class JsRuntime;
1616
static constexpr auto JS_NATIVE_NAME = "_native";
17-
17+
1818
public:
1919
static Napi::Object GetFromJavaScript(Napi::Env env)
2020
{

Core/JsRuntime/Include/Babylon/JsRuntimeScheduler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Babylon
1919
template<typename CallableT>
2020
void operator()(CallableT&& callable) const
2121
{
22-
m_runtime.Dispatch([callable{std::forward<CallableT>(callable)}](Napi::Env){
22+
m_runtime.Dispatch([callable{std::forward<CallableT>(callable)}](Napi::Env) {
2323
callable();
2424
});
2525
}

Core/Node-API/.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

Core/ScriptLoader/Source/ScriptLoader.cpp

+16-23
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ namespace Babylon
1818
UrlLib::UrlRequest request;
1919
request.Open(UrlLib::UrlMethod::Get, url);
2020
request.ResponseType(UrlLib::UrlResponseType::String);
21-
m_task = arcana::when_all(m_task, request.SendAsync()).then(arcana::inline_scheduler, arcana::cancellation::none(),
22-
[dispatchFunction = m_dispatchFunction, request = std::move(request), url = std::move(url)](auto) mutable
23-
{
21+
m_task = arcana::when_all(m_task, request.SendAsync()).then(arcana::inline_scheduler, arcana::cancellation::none(), [dispatchFunction = m_dispatchFunction, request = std::move(request), url = std::move(url)](auto) mutable {
2422
arcana::task_completion_source<void, std::exception_ptr> taskCompletionSource{};
25-
dispatchFunction([taskCompletionSource, request = std::move(request), url = std::move(url)](Napi::Env env) mutable
26-
{
23+
dispatchFunction([taskCompletionSource, request = std::move(request), url = std::move(url)](Napi::Env env) mutable {
2724
Napi::Eval(env, request.ResponseString().data(), url.data());
2825
taskCompletionSource.complete();
2926
});
@@ -34,31 +31,27 @@ namespace Babylon
3431
void Eval(std::string source, std::string url)
3532
{
3633
m_task = m_task.then(arcana::inline_scheduler, arcana::cancellation::none(),
37-
[dispatchFunction = m_dispatchFunction, source = std::move(source), url = std::move(url)](auto) mutable
38-
{
39-
arcana::task_completion_source<void, std::exception_ptr> taskCompletionSource{};
40-
dispatchFunction([taskCompletionSource, source = std::move(source), url = std::move(url)](Napi::Env env) mutable
41-
{
42-
Napi::Eval(env, source.data(), url.data());
43-
taskCompletionSource.complete();
34+
[dispatchFunction = m_dispatchFunction, source = std::move(source), url = std::move(url)](auto) mutable {
35+
arcana::task_completion_source<void, std::exception_ptr> taskCompletionSource{};
36+
dispatchFunction([taskCompletionSource, source = std::move(source), url = std::move(url)](Napi::Env env) mutable {
37+
Napi::Eval(env, source.data(), url.data());
38+
taskCompletionSource.complete();
39+
});
40+
return taskCompletionSource.as_task();
4441
});
45-
return taskCompletionSource.as_task();
46-
});
4742
}
4843

4944
void Dispatch(std::function<void(Napi::Env)> callback)
5045
{
5146
m_task = m_task.then(arcana::inline_scheduler, arcana::cancellation::none(),
52-
[dispatchFunction = m_dispatchFunction, callback = std::move(callback)](auto) mutable
53-
{
54-
arcana::task_completion_source<void, std::exception_ptr> taskCompletionSource{};
55-
dispatchFunction([taskCompletionSource, callback = std::move(callback)](Napi::Env env) mutable
56-
{
57-
callback(env);
58-
taskCompletionSource.complete();
47+
[dispatchFunction = m_dispatchFunction, callback = std::move(callback)](auto) mutable {
48+
arcana::task_completion_source<void, std::exception_ptr> taskCompletionSource{};
49+
dispatchFunction([taskCompletionSource, callback = std::move(callback)](Napi::Env env) mutable {
50+
callback(env);
51+
taskCompletionSource.complete();
52+
});
53+
return taskCompletionSource.as_task();
5954
});
60-
return taskCompletionSource.as_task();
61-
});
6255
}
6356

6457
private:

Polyfills/AbortController/Source/AbortController.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "AbortController.h"
22

3-
43
namespace Babylon::Polyfills::Internal
54
{
65
void AbortController::Initialize(Napi::Env env)
@@ -25,12 +24,12 @@ namespace Babylon::Polyfills::Internal
2524
JsRuntime::NativeObject::GetFromJavaScript(env).Set(JS_ABORT_CONTROLLER_CONSTRUCTOR_NAME, func);
2625
}
2726

28-
Napi::Value AbortController::GetSignal(const Napi::CallbackInfo& )
27+
Napi::Value AbortController::GetSignal(const Napi::CallbackInfo&)
2928
{
3029
return m_signal.Value();
3130
}
3231

33-
void AbortController::Abort(const Napi::CallbackInfo& )
32+
void AbortController::Abort(const Napi::CallbackInfo&)
3433
{
3534
m_signal.Set("aborted", true);
3635
m_signal.Get("onabort").As<Napi::Function>().Call({});

Polyfills/AbortController/Source/AbortSignal.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Babylon::Polyfills::Internal
4646
{
4747
return Napi::Value::From(Env(), Env().Null());
4848
}
49-
49+
5050
return Napi::Value::From(Env(), m_onabort.Value());
5151
}
5252

Polyfills/AbortController/Source/AbortSignal.h

-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ namespace Babylon::Polyfills::Internal
1313
class AbortSignal final : public Napi::ObjectWrap<AbortSignal>
1414
{
1515
public:
16-
1716
static constexpr auto JS_ABORT_SIGNAL_CONSTRUCTOR_NAME = "AbortSignal";
1817

1918
static void Initialize(Napi::Env env);
2019

2120
explicit AbortSignal(const Napi::CallbackInfo& info);
2221

2322
private:
24-
2523
Napi::Value GetAborted(const Napi::CallbackInfo& info);
2624
void SetAborted(const Napi::CallbackInfo&, const Napi::Value& value);
2725

Polyfills/Console/Source/Console.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@ namespace
5353
void AddMethod(Napi::Object& console, const char* functionName, Babylon::Polyfills::Console::LogLevel logLevel, Babylon::Polyfills::Console::CallbackT callback)
5454
{
5555
auto existingFunction = std::make_shared<Napi::FunctionReference>(Napi::Persistent(console.Get(functionName).As<Napi::Function>()));
56-
console.Set(functionName, Napi::Function::New(console.Env(), [callback, existingFunction = std::move(existingFunction), logLevel](const Napi::CallbackInfo& info)
57-
{
58-
InvokeCallback(callback, info, logLevel);
56+
console.Set(functionName,
57+
Napi::Function::New(
58+
console.Env(), [callback, existingFunction = std::move(existingFunction), logLevel](const Napi::CallbackInfo& info) {
59+
InvokeCallback(callback, info, logLevel);
5960

60-
if (!existingFunction->Value().IsUndefined())
61-
{
62-
Call(existingFunction->Value(), info);
63-
}
64-
}, functionName));
61+
if (!existingFunction->Value().IsUndefined())
62+
{
63+
Call(existingFunction->Value(), info);
64+
}
65+
},
66+
functionName));
6567
}
6668
}
6769

Polyfills/Scheduling/Source/Scheduling.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ namespace
77

88
Napi::Value SetTimeout(const Napi::CallbackInfo& info, Babylon::Polyfills::Internal::TimeoutDispatcher& timeoutDispatcher)
99
{
10-
auto function = info[0].IsFunction()
11-
? std::make_shared<Napi::FunctionReference>(Napi::Persistent(info[0].As<Napi::Function>()))
12-
: std::shared_ptr<Napi::FunctionReference>{};
10+
auto function =
11+
info[0].IsFunction()
12+
? std::make_shared<Napi::FunctionReference>(Napi::Persistent(info[0].As<Napi::Function>()))
13+
: std::shared_ptr<Napi::FunctionReference>{};
1314

1415
auto delay = std::chrono::milliseconds{info[1].ToNumber().Int32Value()};
1516

@@ -36,15 +37,19 @@ namespace Babylon::Polyfills::Scheduling
3637
{
3738
auto timeoutDispatcher = std::make_shared<Internal::TimeoutDispatcher>(JsRuntime::GetFromJavaScript(env));
3839

39-
global.Set(JS_SET_TIMEOUT_NAME, Napi::Function::New(env, [timeoutDispatcher](const Napi::CallbackInfo& info)
40-
{
41-
return SetTimeout(info, *timeoutDispatcher);
42-
}, JS_SET_TIMEOUT_NAME));
43-
44-
global.Set(JS_CLEAR_TIMEOUT_NAME, Napi::Function::New(env, [timeoutDispatcher](const Napi::CallbackInfo& info)
45-
{
46-
ClearTimeout(info, *timeoutDispatcher);
47-
}, JS_CLEAR_TIMEOUT_NAME));
40+
global.Set(JS_SET_TIMEOUT_NAME,
41+
Napi::Function::New(
42+
env, [timeoutDispatcher](const Napi::CallbackInfo& info) {
43+
return SetTimeout(info, *timeoutDispatcher);
44+
},
45+
JS_SET_TIMEOUT_NAME));
46+
47+
global.Set(JS_CLEAR_TIMEOUT_NAME,
48+
Napi::Function::New(
49+
env, [timeoutDispatcher](const Napi::CallbackInfo& info) {
50+
ClearTimeout(info, *timeoutDispatcher);
51+
},
52+
JS_CLEAR_TIMEOUT_NAME));
4853
}
4954
}
5055
}

Polyfills/Scheduling/Source/TimeoutDispatcher.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace Babylon::Polyfills::Internal
6868
const auto time = Now() + delay;
6969
const auto result = m_idMap.insert({id, std::make_unique<Timeout>(id, std::move(function), time)});
7070
m_timeMap.insert({time, result.first->second.get()});
71-
71+
7272
if (time <= earliestTime)
7373
{
7474
m_runtime.Dispatch([this](Napi::Env) {
@@ -159,8 +159,9 @@ namespace Babylon::Polyfills::Internal
159159
{
160160
if (function)
161161
{
162-
m_runtime.Dispatch([function = std::move(function)](Napi::Env)
163-
{ function->Call({}); });
162+
m_runtime.Dispatch([function = std::move(function)](Napi::Env) {
163+
function->Call({});
164+
});
164165
}
165166
}
166167
}

Polyfills/URL/Source/URL.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace Babylon::Polyfills::Internal
4949
resultHref << m_origin;
5050
resultHref << m_pathname;
5151

52-
std::string allParams = GetSearchQuery();
52+
std::string allParams = GetSearchQuery();
5353
resultHref << allParams;
5454

5555
return Napi::Value::From(Env(), resultHref.str());
@@ -79,7 +79,7 @@ namespace Babylon::Polyfills::Internal
7979
std::string URL::GetSearchQuery()
8080
{
8181
auto searchParamsObj = URLSearchParams::Unwrap(m_searchParamsReference.Value());
82-
return searchParamsObj->GetAllParams();
82+
return searchParamsObj->GetAllParams();
8383
}
8484

8585
Napi::Value URL::GetSearchParams(const Napi::CallbackInfo&)
@@ -88,7 +88,7 @@ namespace Babylon::Polyfills::Internal
8888
}
8989

9090
// TODO current URL constructor is incomplete, it only supports one argument
91-
// and the url parsing is limited, this logic should be moved to UrlLib and use platform
91+
// and the url parsing is limited, this logic should be moved to UrlLib and use platform
9292
// specific functions to parse the URL and get the parts
9393
URL::URL(const Napi::CallbackInfo& info)
9494
: Napi::ObjectWrap<URL>{info}
@@ -103,15 +103,14 @@ namespace Babylon::Polyfills::Internal
103103

104104
// Get Position of ? to store search var
105105
const size_t qIndex = m_href.find_last_of('?');
106-
107-
if (qIndex != std::string::npos)
106+
107+
if (qIndex != std::string::npos)
108108
{
109109
m_search = m_href.substr(qIndex, m_href.size() - qIndex);
110110
}
111111

112-
113-
// get UrlSearchParams object
114-
const Napi::Object searchParams = info.Env().Global().Get(URLSearchParams::JS_URL_SEARCH_PARAMS_CONSTRUCTOR_NAME).As<Napi::Function>().New({Napi::Value::From(info.Env(), m_search) });
112+
// get UrlSearchParams object
113+
const Napi::Object searchParams = info.Env().Global().Get(URLSearchParams::JS_URL_SEARCH_PARAMS_CONSTRUCTOR_NAME).As<Napi::Function>().New({Napi::Value::From(info.Env(), m_search)});
115114
m_searchParamsReference = Napi::Persistent(searchParams);
116115

117116
// Get URL Domain

0 commit comments

Comments
 (0)