Skip to content

Commit

Permalink
Added Clang Format Checks to CI (#490)
Browse files Browse the repository at this point in the history
* Added C++ Format Checking to CI

Signed-off-by: Redfire <redfire75369@hotmail.com>

* Fixed C++ Formatting

Signed-off-by: Redfire <redfire75369@hotmail.com>

---------

Signed-off-by: Redfire <redfire75369@hotmail.com>
  • Loading branch information
Redfire75369 authored Aug 6, 2024
1 parent 9e070eb commit a57a4a7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Check formatting
- name: Check Rust formatting
run: cargo fmt --check
- name: Check C++ formatting
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: "18"
exclude-regex: mozjs-sys\/mozjs
- name: Get mozjs
run: |
bash ./mozjs-sys/etc/get_mozjs.sh
Expand Down
72 changes: 39 additions & 33 deletions mozjs-sys/src/jsglue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "assert.h"
#include "js/BuildId.h"
#include "js/Class.h"
#include "js/ColumnNumber.h"
#include "js/Id.h"
#include "js/MemoryMetrics.h"
#include "js/Modules.h" // include for JS::GetModulePrivate
Expand All @@ -28,14 +29,13 @@
#include "js/Stream.h"
#include "js/StructuredClone.h"
#include "js/Wrapper.h"
#include "js/experimental/JitInfo.h"
#include "js/experimental/JSStencil.h"
#include "js/experimental/JitInfo.h"
#include "js/experimental/TypedData.h"
#include "js/friend/ErrorMessages.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "mozilla/Unused.h"
#include "js/ColumnNumber.h"

typedef bool (*WantToMeasure)(JSObject* obj);
typedef size_t (*GetSize)(JSObject* obj);
Expand Down Expand Up @@ -87,11 +87,12 @@ class RustJobQueue : public JS::JobQueue {
};

struct ReadableStreamUnderlyingSourceTraps {
void (*requestData)(const void* source, JSContext* cx, JS::HandleObject stream,
size_t desiredSize);
void (*requestData)(const void* source, JSContext* cx,
JS::HandleObject stream, size_t desiredSize);
void (*writeIntoReadRequestBuffer)(const void* source, JSContext* cx,
JS::HandleObject stream, JS::HandleObject chunk,
size_t length, size_t* bytesWritten);
JS::HandleObject stream,
JS::HandleObject chunk, size_t length,
size_t* bytesWritten);
void (*cancel)(const void* source, JSContext* cx, JS::HandleObject stream,
JS::HandleValue reason, JS::Value* resolve_to);
void (*onClosed)(const void* source, JSContext* cx, JS::HandleObject stream);
Expand All @@ -116,10 +117,11 @@ class RustReadableStreamUnderlyingSource
}

virtual void writeIntoReadRequestBuffer(JSContext* cx,
JS::HandleObject stream, JS::HandleObject chunk,
size_t length, size_t* bytesWritten) {
return mTraps.writeIntoReadRequestBuffer(mSource, cx, stream, chunk,
length, bytesWritten);
JS::HandleObject stream,
JS::HandleObject chunk, size_t length,
size_t* bytesWritten) {
return mTraps.writeIntoReadRequestBuffer(mSource, cx, stream, chunk, length,
bytesWritten);
}

virtual JS::Value cancel(JSContext* cx, JS::HandleObject stream,
Expand Down Expand Up @@ -166,12 +168,16 @@ class RustJSExternalStringCallbacks final : public JSExternalStringCallbacks {
}

void finalize(JS::Latin1Char* chars) const override {
MOZ_ASSERT(false, "Latin1Char is not implemented for RustJSExternalStringCallbacks");
MOZ_ASSERT(
false,
"Latin1Char is not implemented for RustJSExternalStringCallbacks");
}

size_t sizeOfBuffer(const JS::Latin1Char* chars,
mozilla::MallocSizeOf mallocSizeOf) const override {
MOZ_ASSERT(false, "Latin1Char is not implemented for RustJSExternalStringCallbacks");
MOZ_ASSERT(
false,
"Latin1Char is not implemented for RustJSExternalStringCallbacks");
}
};

Expand All @@ -181,7 +187,7 @@ struct ProxyTraps {

bool (*getOwnPropertyDescriptor)(
JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc, bool *isNone);
JS::MutableHandle<JS::PropertyDescriptor> desc, bool* isNone);
bool (*defineProperty)(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
JS::Handle<JS::PropertyDescriptor> desc,
JS::ObjectOpResult& result);
Expand Down Expand Up @@ -237,7 +243,7 @@ struct ProxyTraps {
bool (*defaultValue)(JSContext* cx, JS::HandleObject obj, JSType hint,
JS::MutableHandleValue vp);
void (*trace)(JSTracer* trc, JSObject* proxy);
void (*finalize)(JS::GCContext *cx, JSObject* proxy);
void (*finalize)(JS::GCContext* cx, JSObject* proxy);
size_t (*objectMoved)(JSObject* proxy, JSObject* old);

bool (*isCallable)(JSObject* obj);
Expand Down Expand Up @@ -336,7 +342,8 @@ static int HandlerFamily;
mTraps.trace ? mTraps.trace(trc, proxy) : _base::trace(trc, proxy); \
} \
\
virtual void finalize(JS::GCContext* context, JSObject* proxy) const override { \
virtual void finalize(JS::GCContext* context, JSObject* proxy) \
const override { \
mTraps.finalize ? mTraps.finalize(context, proxy) \
: _base::finalize(context, proxy); \
} \
Expand Down Expand Up @@ -392,11 +399,13 @@ class WrapperProxyHandler : public js::Wrapper {

virtual bool getOwnPropertyDescriptor(
JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) const override {
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc)
const override {
if (mTraps.getOwnPropertyDescriptor) {
JS::Rooted<JS::PropertyDescriptor> pd(cx);
bool isNone = true;
bool result = mTraps.getOwnPropertyDescriptor(cx, proxy, id, &pd, &isNone);
bool result =
mTraps.getOwnPropertyDescriptor(cx, proxy, id, &pd, &isNone);
if (isNone) {
desc.set(mozilla::Nothing());
} else {
Expand Down Expand Up @@ -462,7 +471,8 @@ class ForwardingProxyHandler : public js::BaseProxyHandler {

virtual bool getOwnPropertyDescriptor(
JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) const override {
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc)
const override {
JS::Rooted<JS::PropertyDescriptor> pd(cx);
bool isNone = true;
bool result = mTraps.getOwnPropertyDescriptor(cx, proxy, id, &pd, &isNone);
Expand Down Expand Up @@ -586,10 +596,10 @@ void* GetRustJSPrincipalsPrivate(JSPrincipals* principals) {

bool InvokeGetOwnPropertyDescriptor(
const void* handler, JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc, bool *isNone) {
JS::MutableHandle<JS::PropertyDescriptor> desc, bool* isNone) {
JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> mpd(cx);
bool result = static_cast<const ForwardingProxyHandler*>(handler)
->getOwnPropertyDescriptor(cx, proxy, id, &mpd);
->getOwnPropertyDescriptor(cx, proxy, id, &mpd);
*isNone = mpd.isNothing();
if (!*isNone) {
desc.set(*mpd);
Expand Down Expand Up @@ -796,7 +806,8 @@ JSObject* UnwrapObjectStatic(JSObject* obj) {
return js::CheckedUnwrapStatic(obj);
}

JSObject* UnwrapObjectDynamic(JSObject* obj, JSContext* cx, bool stopAtWindowProxy) {
JSObject* UnwrapObjectDynamic(JSObject* obj, JSContext* cx,
bool stopAtWindowProxy) {
return js::CheckedUnwrapDynamic(obj, cx, stopAtWindowProxy);
}

Expand Down Expand Up @@ -996,7 +1007,7 @@ bool WriteBytesToJSStructuredCloneData(const uint8_t* src, size_t len,

// MSVC uses a different calling convention for functions
// that return non-POD values. Unfortunately, this includes anything
// with a constructor, such as JS::Value and JS::RegExpFlags, so we
// with a constructor, such as JS::Value and JS::RegExpFlags, so we
// can't call these from Rust. These wrapper functions are only here
// to ensure the calling convention is right.
// https://web.archive.org/web/20180929193700/https://mozilla.logbot.info/jsapi/20180622#c14918658
Expand Down Expand Up @@ -1036,7 +1047,8 @@ void JS_GetReservedSlot(JSObject* obj, uint32_t index, JS::Value* dest) {
*dest = JS::GetReservedSlot(obj, index);
}

void JS_GetRegExpFlags(JSContext* cx, JS::HandleObject obj, JS::RegExpFlags* flags) {
void JS_GetRegExpFlags(JSContext* cx, JS::HandleObject obj,
JS::RegExpFlags* flags) {
*flags = JS::GetRegExpFlags(cx, obj);
}

Expand Down Expand Up @@ -1112,20 +1124,14 @@ bool DescribeScriptedCaller(JSContext* cx, char* buffer, size_t buflen,
return true;
}

void SetDataPropertyDescriptor(
JS::MutableHandle<JS::PropertyDescriptor> desc,
JS::HandleValue value,
uint32_t attrs
) {
void SetDataPropertyDescriptor(JS::MutableHandle<JS::PropertyDescriptor> desc,
JS::HandleValue value, uint32_t attrs) {
desc.set(JS::PropertyDescriptor::Data(value, attrs));
}

void SetAccessorPropertyDescriptor(
JS::MutableHandle<JS::PropertyDescriptor> desc,
JS::HandleObject getter,
JS::HandleObject setter,
uint32_t attrs
) {
JS::MutableHandle<JS::PropertyDescriptor> desc, JS::HandleObject getter,
JS::HandleObject setter, uint32_t attrs) {
desc.set(JS::PropertyDescriptor::Accessor(getter, setter, attrs));
}

Expand Down

0 comments on commit a57a4a7

Please sign in to comment.