Skip to content

Commit

Permalink
clang fmt github action (#13724)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Sep 7, 2024
1 parent 3f9ad7c commit e8c65a0
Show file tree
Hide file tree
Showing 79 changed files with 282 additions and 219 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/run-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ jobs:
sparse-checkout: |
.prettierrc-ci
.github
.vscode
src
scripts
packages
test
bench
package.json
bun.lockb
.vscode
.clang-format
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
Expand All @@ -46,6 +47,9 @@ jobs:
- name: Format Zig
run: |
bun fmt:zig
- name: Format Cpp
run: |
bun fmt:cpp
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"[h]": {
"editor.defaultFormatter": "xaver.clang-format",
},
"clangd.arguments": ["-header-insertion=never"],

// JavaScript
"prettier.enable": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
"fmt": "prettier --config=.prettierrc-ci --write --cache './{.vscode,src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
"fmt:zig": "zig fmt src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig",
"fmt:cpp": "clang-format -i src/bun.js/bindings/**/*.{cpp,h} --verbose",
"lint": "eslint './**/*.d.ts' --cache",
"lint:fix": "eslint './**/*.d.ts' --cache --fix",
"test": "node scripts/runner.node.mjs ./build/bun-debug",
Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.lut.h
sqlite/sqlite3_local.h
2 changes: 0 additions & 2 deletions src/bun.js/bindings/webcore/CallbackResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ template<> class CallbackResult<void> {
CallbackResultType m_type = CallbackResultType::Success;
};


template<typename ReturnType> inline CallbackResult<ReturnType>::CallbackResult(CallbackResultType type)
: m_value(makeUnexpected(type))
{
Expand All @@ -80,7 +79,6 @@ template<typename ReturnType> inline auto CallbackResult<ReturnType>::releaseRet
return WTFMove(m_value.value());
}


// Void specialization

inline CallbackResult<void>::CallbackResult(CallbackResultType type)
Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/webcore/CommonAtomStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@

namespace WebCore {

// clang-format off
#define DEFINE_COMMON_ATOM(atomName, atomValue) \
MainThreadLazyNeverDestroyed<const AtomString> atomName ## AtomData;
#define INITIALIZE_COMMON_ATOM(atomName, atomValue) \
atomName ## AtomData.constructWithoutAccessCheck(atomValue ## _s);

WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(DEFINE_COMMON_ATOM)
// clang-format on

void initializeCommonAtomStrings()
{
Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/webcore/CommonAtomStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

namespace WebCore {

// clang-format off
#define WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(macro) \
macro(alternative, "alternative") \
macro(auto, "auto") \
Expand Down Expand Up @@ -66,6 +67,7 @@ namespace WebCore {
WEBCORE_COMMON_ATOM_STRINGS_FOR_EACH_KEYWORD(DECLARE_COMMON_ATOM)

#undef DECLARE_COMMON_ATOM
// clang-format on

WEBCORE_EXPORT void initializeCommonAtomStrings();

Expand Down
6 changes: 4 additions & 2 deletions src/bun.js/bindings/webcore/DOMJITIDLConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

#include "IDLTypes.h"

namespace WebCore { namespace DOMJIT {
namespace WebCore {
namespace DOMJIT {

template<typename IDLType>
struct DirectConverter;
Expand Down Expand Up @@ -56,4 +57,5 @@ struct DirectConverter<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> {
}
};

} }
}
}
131 changes: 97 additions & 34 deletions src/bun.js/bindings/webcore/DOMJITIDLTypeFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,116 @@
#include "IDLTypes.h"
#include <JavaScriptCore/SpeculatedType.h>

namespace WebCore { namespace DOMJIT {
namespace WebCore {
namespace DOMJIT {

template<typename IDLType>
struct IDLArgumentTypeFilter;

template<> struct IDLArgumentTypeFilter<IDLBoolean> { static const constexpr JSC::SpeculatedType value = JSC::SpecBoolean; };
template<> struct IDLArgumentTypeFilter<IDLByte> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLArgumentTypeFilter<IDLOctet> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLArgumentTypeFilter<IDLShort> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLArgumentTypeFilter<IDLUnsignedShort> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLArgumentTypeFilter<IDLLong> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLArgumentTypeFilter<IDLDOMString> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLArgumentTypeFilter<IDLAtomStringAdaptor<IDLDOMString>> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLArgumentTypeFilter<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLArgumentTypeFilter<IDLUint8Array> { static const constexpr JSC::SpeculatedType value = JSC::SpecUint8Array; };
template<> struct IDLArgumentTypeFilter<IDLBoolean> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBoolean;
};
template<> struct IDLArgumentTypeFilter<IDLByte> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLArgumentTypeFilter<IDLOctet> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLArgumentTypeFilter<IDLShort> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLArgumentTypeFilter<IDLUnsignedShort> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLArgumentTypeFilter<IDLLong> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLArgumentTypeFilter<IDLDOMString> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLArgumentTypeFilter<IDLAtomStringAdaptor<IDLDOMString>> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLArgumentTypeFilter<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLArgumentTypeFilter<IDLUint8Array> {
static const constexpr JSC::SpeculatedType value = JSC::SpecUint8Array;
};

template<typename IDLType>
struct IDLResultTypeFilter {
static const constexpr JSC::SpeculatedType value = JSC::SpecFullTop;
};

template<> struct IDLResultTypeFilter<IDLAny> { static const constexpr JSC::SpeculatedType value = JSC::SpecHeapTop; };
template<> struct IDLResultTypeFilter<IDLBoolean> { static const constexpr JSC::SpeculatedType value = JSC::SpecBoolean; };
template<> struct IDLResultTypeFilter<IDLByte> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLResultTypeFilter<IDLOctet> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLResultTypeFilter<IDLShort> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLResultTypeFilter<IDLUnsignedShort> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLResultTypeFilter<IDLLong> { static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only; };
template<> struct IDLResultTypeFilter<IDLUnsignedLong> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLLongLong> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLUnsignedLongLong> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLFloat> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLUnrestrictedFloat> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLDouble> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLUnrestrictedDouble> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber; };
template<> struct IDLResultTypeFilter<IDLDOMString> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLResultTypeFilter<IDLByteString> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLResultTypeFilter<IDLUSVString> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLResultTypeFilter<IDLAtomStringAdaptor<IDLDOMString>> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLResultTypeFilter<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> { static const constexpr JSC::SpeculatedType value = JSC::SpecString; };
template<> struct IDLResultTypeFilter<IDLUint8Array> { static const constexpr JSC::SpeculatedType value = JSC::SpecUint8Array; };
template<> struct IDLResultTypeFilter<IDLObject> { static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeTop; };

template<> struct IDLResultTypeFilter<IDLAny> {
static const constexpr JSC::SpeculatedType value = JSC::SpecHeapTop;
};
template<> struct IDLResultTypeFilter<IDLBoolean> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBoolean;
};
template<> struct IDLResultTypeFilter<IDLByte> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLResultTypeFilter<IDLOctet> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLResultTypeFilter<IDLShort> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLResultTypeFilter<IDLUnsignedShort> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLResultTypeFilter<IDLLong> {
static const constexpr JSC::SpeculatedType value = JSC::SpecInt32Only;
};
template<> struct IDLResultTypeFilter<IDLUnsignedLong> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLLongLong> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLUnsignedLongLong> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLFloat> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLUnrestrictedFloat> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLDouble> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLUnrestrictedDouble> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeNumber;
};
template<> struct IDLResultTypeFilter<IDLDOMString> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLResultTypeFilter<IDLByteString> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLResultTypeFilter<IDLUSVString> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLResultTypeFilter<IDLAtomStringAdaptor<IDLDOMString>> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLResultTypeFilter<IDLRequiresExistingAtomStringAdaptor<IDLDOMString>> {
static const constexpr JSC::SpeculatedType value = JSC::SpecString;
};
template<> struct IDLResultTypeFilter<IDLUint8Array> {
static const constexpr JSC::SpeculatedType value = JSC::SpecUint8Array;
};
template<> struct IDLResultTypeFilter<IDLObject> {
static const constexpr JSC::SpeculatedType value = JSC::SpecBytecodeTop;
};

template<typename T>
struct IDLResultTypeFilter<IDLNullable<T>> {
static const constexpr JSC::SpeculatedType value = JSC::SpecOther | IDLResultTypeFilter<T>::value;
};

} }
}
}
18 changes: 10 additions & 8 deletions src/bun.js/bindings/webcore/DOMPromiseProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace WebCore {
template<typename IDLType>
class DOMPromiseProxy {
WTF_MAKE_FAST_ALLOCATED;

public:
using Value = typename IDLType::StorageType;

Expand All @@ -51,7 +52,7 @@ class DOMPromiseProxy {
void resolve(typename IDLType::StorageType);
void resolveWithNewlyCreated(typename IDLType::StorageType);
void reject(Exception, RejectAsHandled = RejectAsHandled::No);

private:
JSC::JSValue resolvePromise(JSC::JSGlobalObject&, JSDOMGlobalObject&, const Function<void(DeferredPromise&)>&);

Expand All @@ -62,6 +63,7 @@ class DOMPromiseProxy {
template<>
class DOMPromiseProxy<IDLUndefined> {
WTF_MAKE_FAST_ALLOCATED;

public:
DOMPromiseProxy() = default;
~DOMPromiseProxy() = default;
Expand All @@ -87,10 +89,11 @@ class DOMPromiseProxy<IDLUndefined> {
template<typename IDLType>
class DOMPromiseProxyWithResolveCallback {
WTF_MAKE_FAST_ALLOCATED;

public:
using ResolveCallback = Function<typename IDLType::ParameterType()>;

template <typename Class, typename BaseClass>
template<typename Class, typename BaseClass>
DOMPromiseProxyWithResolveCallback(Class&, typename IDLType::ParameterType (BaseClass::*)());
DOMPromiseProxyWithResolveCallback(ResolveCallback&&);
~DOMPromiseProxyWithResolveCallback() = default;
Expand All @@ -104,7 +107,7 @@ class DOMPromiseProxyWithResolveCallback {
void resolve(typename IDLType::ParameterType);
void resolveWithNewlyCreated(typename IDLType::ParameterType);
void reject(Exception, RejectAsHandled = RejectAsHandled::No);

private:
ResolveCallback m_resolveCallback;
std::optional<ExceptionOr<void>> m_valueOrException;
Expand Down Expand Up @@ -208,7 +211,6 @@ inline void DOMPromiseProxy<IDLType>::reject(Exception exception, RejectAsHandle
deferredPromise->reject(m_valueOrException->exception(), rejectAsHandled);
}


// MARK: - DOMPromiseProxy<IDLUndefined> specialization

inline JSC::JSValue DOMPromiseProxy<IDLUndefined>::promise(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject)
Expand Down Expand Up @@ -250,7 +252,7 @@ inline bool DOMPromiseProxy<IDLUndefined>::isFulfilled() const
inline void DOMPromiseProxy<IDLUndefined>::resolve()
{
ASSERT(!m_valueOrException);
m_valueOrException = ExceptionOr<void> { };
m_valueOrException = ExceptionOr<void> {};
for (auto& deferredPromise : m_deferredPromises)
deferredPromise->resolve();
}
Expand All @@ -266,7 +268,7 @@ inline void DOMPromiseProxy<IDLUndefined>::reject(Exception exception, RejectAsH
// MARK: - DOMPromiseProxyWithResolveCallback<IDLType> implementation

template<typename IDLType>
template <typename Class, typename BaseClass>
template<typename Class, typename BaseClass>
inline DOMPromiseProxyWithResolveCallback<IDLType>::DOMPromiseProxyWithResolveCallback(Class& object, typename IDLType::ParameterType (BaseClass::*function)())
: m_resolveCallback(std::bind(function, &object))
{
Expand Down Expand Up @@ -322,7 +324,7 @@ inline void DOMPromiseProxyWithResolveCallback<IDLType>::resolve(typename IDLTyp
{
ASSERT(!m_valueOrException);

m_valueOrException = ExceptionOr<void> { };
m_valueOrException = ExceptionOr<void> {};
for (auto& deferredPromise : m_deferredPromises)
deferredPromise->template resolve<IDLType>(value);
}
Expand All @@ -332,7 +334,7 @@ inline void DOMPromiseProxyWithResolveCallback<IDLType>::resolveWithNewlyCreated
{
ASSERT(!m_valueOrException);

m_valueOrException = ExceptionOr<void> { };
m_valueOrException = ExceptionOr<void> {};
for (auto& deferredPromise : m_deferredPromises)
deferredPromise->template resolveWithNewlyCreated<IDLType>(value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/webcore/ErrorCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace WebCore {

void ErrorCallback::scheduleCallback(ScriptExecutionContext& context, Ref<DOMException>&& exception)
{
context.postTask([protectedThis = Ref { *this }, exception = WTFMove(exception)] (ScriptExecutionContext&) {
context.postTask([protectedThis = Ref { *this }, exception = WTFMove(exception)](ScriptExecutionContext&) {
protectedThis->handleEvent(exception);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/bindings/webcore/EventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class EventListener : public RefCounted<EventListener>, public CanMakeWeakPtr<Ev
virtual bool operator==(const EventListener&) const = 0;
virtual void handleEvent(ScriptExecutionContext&, Event&) = 0;

virtual void visitJSFunction(JSC::AbstractSlotVisitor&) { }
virtual void visitJSFunction(JSC::SlotVisitor&) { }
virtual void visitJSFunction(JSC::AbstractSlotVisitor&) {}
virtual void visitJSFunction(JSC::SlotVisitor&) {}

virtual bool isAttribute() const { return false; }
Type type() const { return m_type; }

#if ASSERT_ENABLED
virtual void checkValidityForEventTarget(EventTarget&) { }
virtual void checkValidityForEventTarget(EventTarget&) {}
#endif

virtual JSC::JSObject* jsFunction() const { return nullptr; }
Expand Down
3 changes: 2 additions & 1 deletion src/bun.js/bindings/webcore/EventListenerOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace WebCore {
struct EventListenerOptions {
EventListenerOptions(bool capture = false)
: capture(capture)
{ }
{
}

bool capture { false };
};
Expand Down
Loading

0 comments on commit e8c65a0

Please sign in to comment.