Skip to content

Commit

Permalink
Committing clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
openkraken-bot committed Dec 14, 2021
1 parent 6742dc1 commit f076f81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
10 changes: 5 additions & 5 deletions bridge/bindings/qjs/bom/timer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

#include "console.h"
#include "gtest/gtest.h"
#include "page.h"
#include "kraken_bridge.h"
#include "kraken_test_env.h"
#include "page.h"

TEST(Timer, setTimeout) {

initJSPagePool(1);
auto *bridge = static_cast<kraken::KrakenPage*>(getPage(0));
auto* bridge = static_cast<kraken::KrakenPage*>(getPage(0));

kraken::KrakenPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
static int logIdx = 0;
switch(logIdx) {
switch (logIdx) {
case 0:
EXPECT_STREQ(message.c_str(), "1234");
break;;
break;
;
case 1:
EXPECT_STREQ(message.c_str(), "789");
break;
Expand Down
12 changes: 6 additions & 6 deletions bridge/include/kraken_foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#define KRAKEN_EXPORT __attribute__((__visibility__("default")))

#if defined(__GNUC__) || defined(__clang__)
#define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#define FORCE_INLINE inline __attribute__((always_inline))
#define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#define FORCE_INLINE inline __attribute__((always_inline))
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#define FORCE_INLINE inline
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#define FORCE_INLINE inline
#endif

#define KRAKEN_DISALLOW_COPY(TypeName) TypeName(const TypeName&) = delete
Expand Down
48 changes: 23 additions & 25 deletions bridge/test/kraken_test_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
*/

#include "kraken_test_env.h"
#include <vector>
#include <sys/time.h>
#include <vector>

#if defined(__linux__) || defined(__APPLE__)
static int64_t get_time_ms(void)
{
static int64_t get_time_ms(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000 + (ts.tv_nsec / 1000000);
}
#else
/* more portable, but does not work if the date is updated */
static int64_t get_time_ms(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)tv.tv_sec * 1000 + (tv.tv_usec / 1000);
static int64_t get_time_ms(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)tv.tv_sec * 1000 + (tv.tv_usec / 1000);
}
#endif

typedef struct {
struct list_head link;
int64_t timeout;
void *callbackContext;
void* callbackContext;
int32_t contextId;
AsyncCallback func;
} JSOSTimer;
Expand All @@ -36,24 +34,23 @@ typedef struct JSThreadState {
struct list_head os_timers; /* list of timer.link */
} JSThreadState;

static void unlink_timer(JSRuntime *rt, JSOSTimer *th)
{
static void unlink_timer(JSRuntime* rt, JSOSTimer* th) {
if (th->link.prev) {
list_del(&th->link);
th->link.prev = th->link.next = NULL;
}
}

void TEST_init(PageJSContext *context) {
JSThreadState *th = new JSThreadState();
void TEST_init(PageJSContext* context) {
JSThreadState* th = new JSThreadState();
init_list_head(&th->os_timers);
JS_SetRuntimeOpaque(context->runtime(), th);
}

int32_t TEST_setTimeout(DOMTimerCallbackContext *callbackContext, int32_t contextId, AsyncCallback callback, int32_t timeout) {
JSRuntime *rt = JS_GetRuntime(callbackContext->context->ctx());
JSThreadState *ts = static_cast<JSThreadState*>(JS_GetRuntimeOpaque(rt));
JSOSTimer *th = static_cast<JSOSTimer*>(js_mallocz(callbackContext->context->ctx(), sizeof(*th)));
int32_t TEST_setTimeout(DOMTimerCallbackContext* callbackContext, int32_t contextId, AsyncCallback callback, int32_t timeout) {
JSRuntime* rt = JS_GetRuntime(callbackContext->context->ctx());
JSThreadState* ts = static_cast<JSThreadState*>(JS_GetRuntimeOpaque(rt));
JSOSTimer* th = static_cast<JSOSTimer*>(js_mallocz(callbackContext->context->ctx(), sizeof(*th)));
th->timeout = get_time_ms() + timeout;
th->func = callback;
th->callbackContext = callbackContext;
Expand All @@ -63,19 +60,19 @@ int32_t TEST_setTimeout(DOMTimerCallbackContext *callbackContext, int32_t contex
return 0;
}

static bool jsPool(PageJSContext *context) {
JSRuntime *rt = context->runtime();
JSThreadState *ts = static_cast<JSThreadState*>(JS_GetRuntimeOpaque(rt));
static bool jsPool(PageJSContext* context) {
JSRuntime* rt = context->runtime();
JSThreadState* ts = static_cast<JSThreadState*>(JS_GetRuntimeOpaque(rt));
int64_t cur_time, delay;
struct list_head *el;
struct list_head* el;

if (list_empty(&ts->os_timers))
return true; /* no more events */

if (!list_empty(&ts->os_timers)) {
cur_time = get_time_ms();
list_for_each(el, &ts->os_timers) {
JSOSTimer *th = list_entry(el, JSOSTimer, link);
JSOSTimer* th = list_entry(el, JSOSTimer, link);
delay = th->timeout - cur_time;
if (delay <= 0) {
AsyncCallback func;
Expand All @@ -92,9 +89,10 @@ static bool jsPool(PageJSContext *context) {
return false;
}

void TEST_runLoop(PageJSContext *context) {
for(;;) {
void TEST_runLoop(PageJSContext* context) {
for (;;) {
context->drainPendingPromiseJobs();
if (jsPool(context)) break;
if (jsPool(context))
break;
}
}
8 changes: 4 additions & 4 deletions bridge/test/kraken_test_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

using namespace kraken::binding::qjs;

void TEST_init(PageJSContext *context);
int32_t TEST_setTimeout(DOMTimerCallbackContext *context, int32_t contextId, AsyncCallback callback, int32_t timeout);
void TEST_runLoop(PageJSContext *context);
void TEST_init(PageJSContext* context);
int32_t TEST_setTimeout(DOMTimerCallbackContext* context, int32_t contextId, AsyncCallback callback, int32_t timeout);
void TEST_runLoop(PageJSContext* context);

#endif //KRAKENBRIDGE_TEST_KRAKEN_TEST_ENV_H_
#endif // KRAKENBRIDGE_TEST_KRAKEN_TEST_ENV_H_

0 comments on commit f076f81

Please sign in to comment.