From a337c2e2c930b779d2ef0fe9963e3f2e93597d0e Mon Sep 17 00:00:00 2001 From: openkraken-bot Date: Mon, 24 Jan 2022 10:08:04 +0000 Subject: [PATCH] Committing clang-format changes --- bridge/bindings/qjs/bom/blob.cc | 6 +- bridge/bindings/qjs/bom/blob.h | 14 +- .../bindings/qjs/bom/dom_timer_coordinator.h | 2 +- bridge/bindings/qjs/bom/location.h | 8 +- bridge/bindings/qjs/bom/window.h | 3 +- bridge/bindings/qjs/dom/comment_node.cc | 7 +- bridge/bindings/qjs/dom/comment_node.h | 22 ++-- bridge/bindings/qjs/dom/custom_event.cc | 8 +- bridge/bindings/qjs/dom/custom_event.h | 14 +- bridge/bindings/qjs/dom/document.cc | 122 +++++++++--------- bridge/bindings/qjs/dom/document.h | 16 +-- bridge/bindings/qjs/dom/document_fragment.cc | 2 +- bridge/bindings/qjs/dom/document_fragment.h | 6 +- bridge/bindings/qjs/dom/element.cc | 16 +-- bridge/bindings/qjs/dom/element.h | 17 +-- bridge/bindings/qjs/dom/event.cc | 12 +- bridge/bindings/qjs/dom/event.h | 9 +- bridge/bindings/qjs/dom/event_target.cc | 12 +- bridge/bindings/qjs/dom/event_target.h | 3 +- bridge/bindings/qjs/dom/node.h | 15 +-- bridge/bindings/qjs/dom/text_node.h | 6 +- bridge/bindings/qjs/executing_context.cc | 1 - bridge/bindings/qjs/executing_context.h | 7 +- bridge/bindings/qjs/executing_context_data.cc | 3 +- bridge/bindings/qjs/executing_context_data.h | 5 +- bridge/bindings/qjs/garbage_collected.h | 12 +- bridge/bindings/qjs/js_context_macros.h | 18 +-- bridge/bindings/qjs/wrapper_type_info.h | 7 +- bridge/page.cc | 2 +- 29 files changed, 158 insertions(+), 217 deletions(-) diff --git a/bridge/bindings/qjs/bom/blob.cc b/bridge/bindings/qjs/bom/blob.cc index d83c449739..3fe0fb6e28 100644 --- a/bridge/bindings/qjs/bom/blob.cc +++ b/bridge/bindings/qjs/bom/blob.cc @@ -35,7 +35,6 @@ Blob* Blob::create(JSContext* ctx) { // Let eventTarget instance inherit EventTarget prototype methods. JS_SetPrototype(ctx, blob->toQuickJS(), prototype); return blob; - } Blob* Blob::create(JSContext* ctx, std::vector&& data) { return create(ctx); @@ -259,9 +258,6 @@ uint8_t* Blob::bytes() { } void Blob::trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const {} -void Blob::dispose() const { - -} - +void Blob::dispose() const {} } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/bom/blob.h b/bridge/bindings/qjs/bom/blob.h index e34fafe7fc..cd1710c833 100644 --- a/bridge/bindings/qjs/bom/blob.h +++ b/bridge/bindings/qjs/bom/blob.h @@ -24,9 +24,9 @@ class Blob : public GarbageCollected { static JSValue constructor(ExecutionContext* context); static JSValue prototype(ExecutionContext* context); - Blob() {}; - Blob(std::vector&& data): _size(data.size()), _data(std::move(data)) {}; - Blob(std::vector&& data, std::string& mime): mimeType(mime), _size(data.size()), _data(std::move(data)) {}; + Blob(){}; + Blob(std::vector&& data) : _size(data.size()), _data(std::move(data)){}; + Blob(std::vector&& data, std::string& mime) : mimeType(mime), _size(data.size()), _data(std::move(data)){}; DEFINE_FUNCTION(arrayBuffer); DEFINE_FUNCTION(slice); @@ -40,7 +40,7 @@ class Blob : public GarbageCollected { DEFINE_PROTOTYPE_READONLY_PROPERTY(type); DEFINE_PROTOTYPE_READONLY_PROPERTY(size); - void trace(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) const override; + void trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const override; void dispose() const override; private: @@ -110,11 +110,7 @@ auto blobCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_v return blob->toQuickJS(); }; -const WrapperTypeInfo blobTypeInfo = { - "Blob", - nullptr, - blobCreator -}; +const WrapperTypeInfo blobTypeInfo = {"Blob", nullptr, blobCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/bom/dom_timer_coordinator.h b/bridge/bindings/qjs/bom/dom_timer_coordinator.h index e736fcb38c..e09e5a6a11 100644 --- a/bridge/bindings/qjs/bom/dom_timer_coordinator.h +++ b/bridge/bindings/qjs/bom/dom_timer_coordinator.h @@ -8,8 +8,8 @@ #include #include -#include "bindings/qjs/executing_context.h" #include +#include "bindings/qjs/executing_context.h" namespace kraken::binding::qjs { diff --git a/bridge/bindings/qjs/bom/location.h b/bridge/bindings/qjs/bom/location.h index 50e1a99890..277d7186e5 100644 --- a/bridge/bindings/qjs/bom/location.h +++ b/bridge/bindings/qjs/bom/location.h @@ -20,7 +20,7 @@ class Location : public GarbageCollected { static Location* create(JSContext* ctx); static JSValue reload(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); - void trace(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) const override; + void trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const override; void dispose() const override; }; @@ -35,11 +35,7 @@ auto locationCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst th return location->toQuickJS(); }; -const WrapperTypeInfo locationTypeInfo = { - "Location", - nullptr, - locationCreator -}; +const WrapperTypeInfo locationTypeInfo = {"Location", nullptr, locationCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/bom/window.h b/bridge/bindings/qjs/bom/window.h index 2d5fe54e7e..2e01be49b1 100644 --- a/bridge/bindings/qjs/bom/window.h +++ b/bridge/bindings/qjs/bom/window.h @@ -17,7 +17,6 @@ void bindWindow(std::unique_ptr& context); class Window : public EventTarget { public: - Window(); static JSClassID classId; @@ -42,7 +41,7 @@ class Window : public EventTarget { DEFINE_PROTOTYPE_PROPERTY(onerror); - void trace(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) const override; + void trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const override; private: Document* document(); diff --git a/bridge/bindings/qjs/dom/comment_node.cc b/bridge/bindings/qjs/dom/comment_node.cc index c2c7cf26f3..6af1bef852 100644 --- a/bridge/bindings/qjs/dom/comment_node.cc +++ b/bridge/bindings/qjs/dom/comment_node.cc @@ -10,8 +10,8 @@ namespace kraken::binding::qjs { void bindCommentNode(std::unique_ptr& context) { -// auto* constructor = Comment::instance(context.get()); -// context->defineGlobalProperty("Comment", constructor->jsObject); + // auto* constructor = Comment::instance(context.get()); + // context->defineGlobalProperty("Comment", constructor->jsObject); } JSClassID Comment::classId{0}; @@ -26,10 +26,9 @@ Comment* Comment::create(JSContext* ctx) { JS_SetPrototype(ctx, comment->toQuickJS(), prototype); return comment; - } -//Comment::Comment(ExecutionContext* context) : Node(context, "Comment") { +// Comment::Comment(ExecutionContext* context) : Node(context, "Comment") { // std::call_once(kCommentInitFlag, []() { JS_NewClassID(&kCommentClassId); }); // JS_SetPrototype(m_ctx, m_prototypeObject, Node::instance(m_context)->prototype()); //} diff --git a/bridge/bindings/qjs/dom/comment_node.h b/bridge/bindings/qjs/dom/comment_node.h index 7be7e31737..eed74f4e8f 100644 --- a/bridge/bindings/qjs/dom/comment_node.h +++ b/bridge/bindings/qjs/dom/comment_node.h @@ -21,12 +21,12 @@ class Comment : public Node { static JSValue constructor(ExecutionContext* context); static JSValue prototype(ExecutionContext* context); -// static JSClassID kCommentClassId; -// static JSClassID classId(); -// Comment() = delete; -// explicit Comment(ExecutionContext* context); + // static JSClassID kCommentClassId; + // static JSClassID classId(); + // Comment() = delete; + // explicit Comment(ExecutionContext* context); -// JSValue instanceConstructor(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) override; + // JSValue instanceConstructor(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) override; private: DEFINE_PROTOTYPE_READONLY_PROPERTY(data); @@ -36,18 +36,12 @@ class Comment : public Node { friend CommentInstance; }; -auto commentCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags) -> JSValue { -}; - +auto commentCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags) -> JSValue {}; -const WrapperTypeInfo commentTypeInfo = { - "Comment", - &nodeTypeInfo, - commentCreator -}; +const WrapperTypeInfo commentTypeInfo = {"Comment", &nodeTypeInfo, commentCreator}; // -//class CommentInstance : public NodeInstance { +// class CommentInstance : public NodeInstance { // public: // CommentInstance() = delete; // explicit CommentInstance(Comment* comment); diff --git a/bridge/bindings/qjs/dom/custom_event.cc b/bridge/bindings/qjs/dom/custom_event.cc index 705e7cccdb..84e02ec36b 100644 --- a/bridge/bindings/qjs/dom/custom_event.cc +++ b/bridge/bindings/qjs/dom/custom_event.cc @@ -12,8 +12,8 @@ namespace kraken::binding::qjs { void bindCustomEvent(std::unique_ptr& context) { -// auto* constructor = CustomEvent::instance(context.get()); -// context->defineGlobalProperty("CustomEvent", constructor->jsObject); + // auto* constructor = CustomEvent::instance(context.get()); + // context->defineGlobalProperty("CustomEvent", constructor->jsObject); } JSClassID CustomEvent::classId{0}; @@ -89,9 +89,7 @@ JSValue CustomEvent::initCustomEvent(JSContext* ctx, JSValue this_val, int argc, return JS_NULL; } -JSValue CustomEvent::instanceConstructor(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) { - -} +JSValue CustomEvent::instanceConstructor(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) {} IMPL_PROPERTY_GETTER(CustomEvent, detail)(JSContext* ctx, JSValue this_val, int argc, JSValue* argv) { auto* customEventInstance = static_cast(JS_GetOpaque(this_val, Event::kEventClassID)); diff --git a/bridge/bindings/qjs/dom/custom_event.h b/bridge/bindings/qjs/dom/custom_event.h index fda15db447..5dde950ea7 100644 --- a/bridge/bindings/qjs/dom/custom_event.h +++ b/bridge/bindings/qjs/dom/custom_event.h @@ -24,11 +24,11 @@ class CustomEvent : public Event { static JSValue constructor(ExecutionContext* context); static JSValue prototype(ExecutionContext* context); - void trace(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) const override; + void trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const override; void dispose() const override; -// CustomEvent() = delete; -// explicit CustomEvent(JSValue eventType, JSValue eventInit); + // CustomEvent() = delete; + // explicit CustomEvent(JSValue eventType, JSValue eventInit); DEFINE_PROTOTYPE_READONLY_PROPERTY(detail); DEFINE_FUNCTION(initCustomEvent); @@ -37,7 +37,7 @@ class CustomEvent : public Event { JSValue m_detail{JS_NULL}; }; -//class CustomEventInstance : public EventInstance { +// class CustomEventInstance : public EventInstance { // public: // explicit CustomEventInstance(CustomEvent* jsCustomEvent, JSAtom CustomEventType, JSValue eventInit); // explicit CustomEventInstance(CustomEvent* jsCustomEvent, NativeCustomEvent* nativeCustomEvent); @@ -66,11 +66,7 @@ auto customEventCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst return customEvent->toQuickJS(); }; -const WrapperTypeInfo customEventTypeInfo = { - "CustomEvent", - &eventTypeInfo, - customEventCreator -}; +const WrapperTypeInfo customEventTypeInfo = {"CustomEvent", &eventTypeInfo, customEventCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/dom/document.cc b/bridge/bindings/qjs/dom/document.cc index 1fc1d243e1..4c12abaac3 100644 --- a/bridge/bindings/qjs/dom/document.cc +++ b/bridge/bindings/qjs/dom/document.cc @@ -103,63 +103,66 @@ JSValue Document::prototype(ExecutionContext* context) { Document::Document() : Node() { if (!document_registered) { -// defineElement("img", ImageElement::instance(m_context)); -// defineElement("a", AnchorElement::instance(m_context)); -// defineElement("canvas", CanvasElement::instance(m_context)); -// defineElement("input", InputElement::instance(m_context)); -// defineElement("object", ObjectElement::instance(m_context)); -// defineElement("script", ScriptElement::instance(m_context)); -// defineElement("template", TemplateElement::instance(m_context)); + // defineElement("img", ImageElement::instance(m_context)); + // defineElement("a", AnchorElement::instance(m_context)); + // defineElement("canvas", CanvasElement::instance(m_context)); + // defineElement("input", InputElement::instance(m_context)); + // defineElement("object", ObjectElement::instance(m_context)); + // defineElement("script", ScriptElement::instance(m_context)); + // defineElement("template", TemplateElement::instance(m_context)); document_registered = true; } if (!event_registered) { event_registered = true; -// Event::defineEvent( -// EVENT_INPUT, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { return new InputEventInstance(InputEvent::instance(context), reinterpret_cast(nativeEvent)); }); -// Event::defineEvent(EVENT_MEDIA_ERROR, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new MediaErrorEventInstance(MediaErrorEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_MESSAGE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new MessageEventInstance(MessageEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent( -// EVENT_CLOSE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { return new CloseEventInstance(CloseEvent::instance(context), reinterpret_cast(nativeEvent)); }); -// Event::defineEvent(EVENT_INTERSECTION_CHANGE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new IntersectionChangeEventInstance(IntersectionChangeEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_TOUCH_START, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_TOUCH_END, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_TOUCH_MOVE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_TOUCH_CANCEL, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_SWIPE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_PAN, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_LONG_PRESS, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_SCALE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent( -// EVENT_CLICK, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { return new MouseEventInstance(MouseEvent::instance(context), reinterpret_cast(nativeEvent)); }); -// Event::defineEvent(EVENT_CANCEL, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new MouseEventInstance(MouseEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); -// Event::defineEvent(EVENT_POPSTATE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { -// return new PopStateEventInstance(PopStateEvent::instance(context), reinterpret_cast(nativeEvent)); -// }); + // Event::defineEvent( + // EVENT_INPUT, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { return new InputEventInstance(InputEvent::instance(context), + // reinterpret_cast(nativeEvent)); }); + // Event::defineEvent(EVENT_MEDIA_ERROR, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new MediaErrorEventInstance(MediaErrorEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_MESSAGE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new MessageEventInstance(MessageEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent( + // EVENT_CLOSE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { return new CloseEventInstance(CloseEvent::instance(context), + // reinterpret_cast(nativeEvent)); }); + // Event::defineEvent(EVENT_INTERSECTION_CHANGE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new IntersectionChangeEventInstance(IntersectionChangeEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_TOUCH_START, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_TOUCH_END, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_TOUCH_MOVE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_TOUCH_CANCEL, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new TouchEventInstance(TouchEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_SWIPE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_PAN, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_LONG_PRESS, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_SCALE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new GestureEventInstance(GestureEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent( + // EVENT_CLICK, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { return new MouseEventInstance(MouseEvent::instance(context), + // reinterpret_cast(nativeEvent)); }); + // Event::defineEvent(EVENT_CANCEL, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new MouseEventInstance(MouseEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); + // Event::defineEvent(EVENT_POPSTATE, [](ExecutionContext* context, void* nativeEvent) -> EventInstance* { + // return new PopStateEventInstance(PopStateEvent::instance(context), reinterpret_cast(nativeEvent)); + // }); } } @@ -198,12 +201,12 @@ IMPL_FUNCTION(Document, createElement)(JSContext* ctx, JSValue this_val, int arg } auto document = static_cast(JS_GetOpaque(this_val, Document::classId)); -// auto* context = static_cast(JS_GetContextOpaque(ctx)); -// std::string tagName = jsValueToStdString(ctx, tagNameValue); -// JSValue constructor = static_cast(document->prototype())->getElementConstructor(document->context(), tagName); -// -// JSValue element = JS_CallConstructor(ctx, constructor, argc, argv); -// return element; + // auto* context = static_cast(JS_GetContextOpaque(ctx)); + // std::string tagName = jsValueToStdString(ctx, tagNameValue); + // JSValue constructor = static_cast(document->prototype())->getElementConstructor(document->context(), tagName); + // + // JSValue element = JS_CallConstructor(ctx, constructor, argc, argv); + // return element; } IMPL_FUNCTION(Document, createTextNode)(JSContext* ctx, JSValue this_val, int argc, JSValue* argv) { @@ -555,8 +558,7 @@ Document::Document(Document* document) : Node(document, NodeType::DOCUMENT_NODE, #endif } -Document::~Document() { -} +Document::~Document() {} void Document::removeElementById(JSAtom id, Element* element) { if (m_elementMapById.count(id) > 0) { auto& list = m_elementMapById[id]; diff --git a/bridge/bindings/qjs/dom/document.h b/bridge/bindings/qjs/dom/document.h index feb7c44ed1..1e3ce04bdd 100644 --- a/bridge/bindings/qjs/dom/document.h +++ b/bridge/bindings/qjs/dom/document.h @@ -20,17 +20,16 @@ using TraverseHandler = std::function; void traverseNode(Node* node, TraverseHandler handler); class DocumentCookie { -public: + public: DocumentCookie() = default; std::string getCookie(); void setCookie(std::string& str); -private: + private: std::unordered_map cookiePairs; }; - class Document : public Node { public: static JSClassID classId; @@ -66,7 +65,6 @@ class Document : public Node { void dispose() const override; private: - void removeElementById(JSAtom id, Element* element); void addElementById(JSAtom id, Element* element); Element* getDocumentElement(); @@ -83,15 +81,9 @@ class Document : public Node { std::unordered_map elementConstructorMap; }; -auto documentCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags) -> JSValue { - return JS_ThrowTypeError(ctx, "Illegal constructor"); -}; +auto documentCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags) -> JSValue { return JS_ThrowTypeError(ctx, "Illegal constructor"); }; -const WrapperTypeInfo documentTypeInfo = { - "Document", - &nodeTypeInfo, - documentCreator -}; +const WrapperTypeInfo documentTypeInfo = {"Document", &nodeTypeInfo, documentCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/dom/document_fragment.cc b/bridge/bindings/qjs/dom/document_fragment.cc index 6b14777bba..2b2c096ad1 100644 --- a/bridge/bindings/qjs/dom/document_fragment.cc +++ b/bridge/bindings/qjs/dom/document_fragment.cc @@ -18,7 +18,7 @@ JSValue DocumentFragment::constructor(ExecutionContext* context) { return context->contextData()->constructorForType(&documentFragmentInfo); } -DocumentFragment * DocumentFragment::create(JSContext* ctx) { +DocumentFragment* DocumentFragment::create(JSContext* ctx) { auto* context = static_cast(JS_GetContextOpaque(ctx)); JSValue prototype = context->contextData()->prototypeForType(&documentFragmentInfo); auto* documentFragment = makeGarbageCollected()->initialize(ctx, &classId); diff --git a/bridge/bindings/qjs/dom/document_fragment.h b/bridge/bindings/qjs/dom/document_fragment.h index a2bdcf8791..b24c57314e 100644 --- a/bridge/bindings/qjs/dom/document_fragment.h +++ b/bridge/bindings/qjs/dom/document_fragment.h @@ -29,11 +29,7 @@ auto documentFragmentCreator = [](JSContext* ctx, JSValueConst func_obj, JSValue return eventTarget->toQuickJS(); }; -const WrapperTypeInfo documentFragmentInfo = { - "DocumentFragment", - &nodeTypeInfo, - documentFragmentCreator -}; +const WrapperTypeInfo documentFragmentInfo = {"DocumentFragment", &nodeTypeInfo, documentFragmentCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/dom/element.cc b/bridge/bindings/qjs/dom/element.cc index 6a082a7bd3..19cfd69963 100644 --- a/bridge/bindings/qjs/dom/element.cc +++ b/bridge/bindings/qjs/dom/element.cc @@ -185,7 +185,7 @@ JSValue Element::prototype(ExecutionContext* context) { return context->contextData()->prototypeForType(&elementTypeInfo); } -//JSValue Element::instanceConstructor(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) { +// JSValue Element::instanceConstructor(JSContext* ctx, JSValue func_obj, JSValue this_val, int argc, JSValue* argv) { // if (argc == 0) // return JS_ThrowTypeError(ctx, "Illegal constructor"); // JSValue tagName = argv[0]; @@ -643,11 +643,11 @@ IMPL_PROPERTY_SETTER(Element, outerHTML)(JSContext* ctx, JSValue this_val, int a return JS_NULL; } -//JSClassID Element::classId { +// JSClassID Element::classId { // return Element::classId; //} -//Element::~Element() {} +// Element::~Element() {} JSValue Element::internalGetTextContent() { JSValue array = JS_NewArray(m_ctx); @@ -887,7 +887,7 @@ void Element::trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) { NodeInstance::trace(rt, val, mark_func); } -//Element::Element(Element* element, std::string tagName, bool shouldAddUICommand): Node() { +// Element::Element(Element* element, std::string tagName, bool shouldAddUICommand): Node() { // m_attributes = makeGarbageCollected()->initialize(m_ctx, &ElementAttributes::classId); // JSValue arguments[] = {jsObject}; // JSValue style = JS_CallConstructor(m_ctx, CSSStyleDeclaration::instance(m_context)->jsObject, 1, arguments); @@ -907,12 +907,8 @@ StyleDeclarationInstance* Element::style() { return m_style; } -void Element::trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const { - -} -void Element::dispose() const { - -} +void Element::trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const {} +void Element::dispose() const {} IMPL_PROPERTY_GETTER(BoundingClientRect, x)(JSContext* ctx, JSValue this_val, int argc, JSValue* argv) { auto* boundingClientRect = static_cast(JS_GetOpaque(this_val, ExecutionContext::kHostObjectClassId)); diff --git a/bridge/bindings/qjs/dom/element.h b/bridge/bindings/qjs/dom/element.h index 126bd0b305..0442ba416c 100644 --- a/bridge/bindings/qjs/dom/element.h +++ b/bridge/bindings/qjs/dom/element.h @@ -7,8 +7,8 @@ #define KRAKENBRIDGE_ELEMENT_H #include -#include "bindings/qjs/garbage_collected.h" #include "bindings/qjs/executing_context.h" +#include "bindings/qjs/garbage_collected.h" #include "node.h" #include "style_declaration.h" @@ -126,6 +126,7 @@ class Element : public Node { protected: StyleDeclarationInstance* m_style{nullptr}; ElementAttributes* m_attributes{nullptr}; + private: std::string m_tagName; void _notifyNodeRemoved(Node* node) override; @@ -155,13 +156,13 @@ auto elementCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst thi Element* element = Element::create(ctx); auto* document = context->document(); -// auto* Document = Document::instance(context); -// if (Document->isCustomElement(name)) { -// return JS_CallConstructor(ctx, Document->getElementConstructor(context, name), argc, argv); -// } -// -// auto* element = new Element(this, name, true); -// return element->jsObject; + // auto* Document = Document::instance(context); + // if (Document->isCustomElement(name)) { + // return JS_CallConstructor(ctx, Document->getElementConstructor(context, name), argc, argv); + // } + // + // auto* element = new Element(this, name, true); + // return element->jsObject; }; const WrapperTypeInfo elementTypeInfo = {"Element", &nodeTypeInfo, elementCreator}; diff --git a/bridge/bindings/qjs/dom/event.cc b/bridge/bindings/qjs/dom/event.cc index 416a4c203b..caf65b665f 100644 --- a/bridge/bindings/qjs/dom/event.cc +++ b/bridge/bindings/qjs/dom/event.cc @@ -57,13 +57,9 @@ Event* Event::create(JSContext* ctx, NativeEvent* nativeEvent) { return event; } -Event::Event() { - -} -Event::Event(NativeEvent* nativeEvent): nativeEvent(nativeEvent) {} -Event::Event(JSValue eventType, JSValue eventInit) { - -} +Event::Event() {} +Event::Event(NativeEvent* nativeEvent) : nativeEvent(nativeEvent) {} +Event::Event(JSValue eventType, JSValue eventInit) {} JSValue Event::constructor(ExecutionContext* context) { return context->contextData()->constructorForType(&eventTypeInfo); @@ -137,7 +133,7 @@ IMPL_PROPERTY_GETTER(Event, cancelBubble)(JSContext* ctx, JSValue this_val, int return JS_NewBool(ctx, event->cancelled()); } -//Event* Event::buildEvent(JSValue eventType, JSContext* ctx, void* nativeEvent, bool isCustomEvent) { +// Event* Event::buildEvent(JSValue eventType, JSContext* ctx, void* nativeEvent, bool isCustomEvent) { // Event* event; // if (isCustomEvent) { // event = CustomEvent::create(ctx, reinterpret_cast(nativeEvent), eventType); diff --git a/bridge/bindings/qjs/dom/event.h b/bridge/bindings/qjs/dom/event.h index 35bc07fa46..dce9cb821c 100644 --- a/bridge/bindings/qjs/dom/event.h +++ b/bridge/bindings/qjs/dom/event.h @@ -108,10 +108,11 @@ class Event : public GarbageCollected { inline void cancelled(bool v) { m_cancelled = v; } inline const bool propagationImmediatelyStopped() { return m_propagationImmediatelyStopped; } - void trace(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) const override; + void trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const override; void dispose() const override; NativeEvent* nativeEvent{nullptr}; + private: static std::unordered_map m_eventCreatorMap; bool m_cancelled{false}; @@ -132,11 +133,7 @@ auto eventCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_ return event->toQuickJS(); }; -const WrapperTypeInfo eventTypeInfo = { - "Event", - nullptr, - eventCreator -}; +const WrapperTypeInfo eventTypeInfo = {"Event", nullptr, eventCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/dom/event_target.cc b/bridge/bindings/qjs/dom/event_target.cc index c823ab9b04..8c69328914 100644 --- a/bridge/bindings/qjs/dom/event_target.cc +++ b/bridge/bindings/qjs/dom/event_target.cc @@ -199,9 +199,7 @@ bool EventTarget::internalDispatchEvent(Event* event) { handler), so must take extra care */ JS_DupValue(m_ctx, handler); - JSValue arguments[] = { - event->toQuickJS() - }; + JSValue arguments[] = {event->toQuickJS()}; // The third params `thisObject` to null equals global object. JSValue returnedValue = JS_Call(m_ctx, handler, JS_NULL, 1, arguments); @@ -452,10 +450,10 @@ void NativeEventTarget::dispatchEventImpl(NativeEventTarget* nativeEventTarget, // So we can reinterpret_cast raw bytes pointer to NativeEvent type directly. auto* nativeEvent = reinterpret_cast(raw->bytes); Event* event = Event::create(); -// Event* event = Event::buildEventInstance(eventType, context, nativeEvent, isCustomEvent == 1); -// eventInstance->nativeEvent->target = eventTarget; -// eventTarget->dispatchEvent(eventInstance); -// JS_FreeValue(context->ctx(), eventInstance->jsObject); + // Event* event = Event::buildEventInstance(eventType, context, nativeEvent, isCustomEvent == 1); + // eventInstance->nativeEvent->target = eventTarget; + // eventTarget->dispatchEvent(eventInstance); + // JS_FreeValue(context->ctx(), eventInstance->jsObject); } } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/dom/event_target.h b/bridge/bindings/qjs/dom/event_target.h index 5e1f80f991..475ca23199 100644 --- a/bridge/bindings/qjs/dom/event_target.h +++ b/bridge/bindings/qjs/dom/event_target.h @@ -82,7 +82,8 @@ class EventTarget : public GarbageCollected { static void copyNodeProperties(EventTarget* newNode, EventTarget* referenceNode); NativeEventTarget* nativeEventTarget{new NativeEventTarget(this)}; -private: + + private: static int hasProperty(JSContext* ctx, JSValueConst obj, JSAtom atom); static JSValue getProperty(JSContext* ctx, JSValueConst obj, JSAtom atom, JSValueConst receiver); static int setProperty(JSContext* ctx, JSValueConst obj, JSAtom atom, JSValueConst value, JSValueConst receiver, int flags); diff --git a/bridge/bindings/qjs/dom/node.h b/bridge/bindings/qjs/dom/node.h index 8b6795777c..b47fd31090 100644 --- a/bridge/bindings/qjs/dom/node.h +++ b/bridge/bindings/qjs/dom/node.h @@ -77,7 +77,7 @@ class Node : public EventTarget { void trace(JSRuntime* rt, JSValue val, JS_MarkFunc* mark_func) const override; void dispose() const override; -protected: + protected: NodeJob nodeLink{this}; void refer(); @@ -93,7 +93,8 @@ class Node : public EventTarget { virtual void _notifyNodeRemoved(Node* node); virtual void _notifyNodeInsert(Node* node); -private: + + private: ObjectProperty m_childNodes{context(), jsObject, "childNodes", childNodes}; void ensureDetached(Node* node); @@ -101,15 +102,9 @@ class Node : public EventTarget { static JSValue copyNodeValue(JSContext* ctx, Node* node); }; -auto nodeCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags) -> JSValue { - return JS_ThrowTypeError(ctx, "Illegal constructor"); -}; +auto nodeCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags) -> JSValue { return JS_ThrowTypeError(ctx, "Illegal constructor"); }; -const WrapperTypeInfo nodeTypeInfo = { - "Node", - &eventTargetTypeInfo, - nodeCreator -}; +const WrapperTypeInfo nodeTypeInfo = {"Node", &eventTargetTypeInfo, nodeCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/dom/text_node.h b/bridge/bindings/qjs/dom/text_node.h index 2dea9ab6d4..955166d9f5 100644 --- a/bridge/bindings/qjs/dom/text_node.h +++ b/bridge/bindings/qjs/dom/text_node.h @@ -47,11 +47,7 @@ auto textNodeCreator = [](JSContext* ctx, JSValueConst func_obj, JSValueConst th return textNode->toQuickJS(); }; -const WrapperTypeInfo textNodeType = { - "TextNode", - &nodeTypeInfo, - textNodeCreator -}; +const WrapperTypeInfo textNodeType = {"TextNode", &nodeTypeInfo, textNodeCreator}; } // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/executing_context.cc b/bridge/bindings/qjs/executing_context.cc index d5f1dcdaf7..0129f81de4 100644 --- a/bridge/bindings/qjs/executing_context.cc +++ b/bridge/bindings/qjs/executing_context.cc @@ -368,7 +368,6 @@ void installPropertyGetter(ExecutionContext* context, JSValue thisObject, const JS_FreeValue(context->ctx(), getter); } - DOMTimerCoordinator* ExecutionContext::timers() { return &m_timers; } diff --git a/bridge/bindings/qjs/executing_context.h b/bridge/bindings/qjs/executing_context.h index 936f9025d6..0c9b3da367 100644 --- a/bridge/bindings/qjs/executing_context.h +++ b/bridge/bindings/qjs/executing_context.h @@ -17,11 +17,11 @@ #include #include #include "bindings/qjs/bom/dom_timer_coordinator.h" +#include "executing_context_data.h" #include "foundation/ui_command_buffer.h" #include "garbage_collected.h" #include "js_context_macros.h" #include "kraken_foundation.h" -#include "executing_context_data.h" #include "qjs_patch.h" #include "wrapper_type_info.h" @@ -156,7 +156,8 @@ static JSValue handleCallThisOnProxy(JSContext* ctx, JSValueConst this_val, int class ObjectProperty { KRAKEN_DISALLOW_COPY_ASSIGN_AND_MOVE(ObjectProperty); -public: + + public: ObjectProperty() = delete; // Define an property on object with a JSValue. @@ -166,7 +167,7 @@ class ObjectProperty { JSValue value() const { return m_value; } -private: + private: JSValue m_value{JS_NULL}; }; diff --git a/bridge/bindings/qjs/executing_context_data.cc b/bridge/bindings/qjs/executing_context_data.cc index 0007e650e3..1a396859e4 100644 --- a/bridge/bindings/qjs/executing_context_data.cc +++ b/bridge/bindings/qjs/executing_context_data.cc @@ -3,7 +3,6 @@ * Author: Kraken Team. */ - #include "executing_context_data.h" namespace kraken::binding::qjs { @@ -71,4 +70,4 @@ JSValue ExecutionContextData::constructorForIdSlowCase(const WrapperTypeInfo* ty return classObject; } -} +} // namespace kraken::binding::qjs diff --git a/bridge/bindings/qjs/executing_context_data.h b/bridge/bindings/qjs/executing_context_data.h index 16e2c8171f..dcc1d2fb55 100644 --- a/bridge/bindings/qjs/executing_context_data.h +++ b/bridge/bindings/qjs/executing_context_data.h @@ -16,7 +16,7 @@ namespace kraken::binding::qjs { // has a 1:1 relationship with ExecutionContext. class ExecutionContextData final { public: - explicit ExecutionContextData(ExecutionContext& context): m_context(context) {}; + explicit ExecutionContextData(ExecutionContext& context) : m_context(context){}; ExecutionContextData(const ExecutionContextData&) = delete; ExecutionContextData& operator=(const ExecutionContextData&) = delete; @@ -33,7 +33,6 @@ class ExecutionContextData final { ExecutionContext& m_context; }; - -} +} // namespace kraken::binding::qjs #endif // KRAKENBRIDGE_CONTEXT_DATA_H diff --git a/bridge/bindings/qjs/garbage_collected.h b/bridge/bindings/qjs/garbage_collected.h index aebb018d2e..bba83668a4 100644 --- a/bridge/bindings/qjs/garbage_collected.h +++ b/bridge/bindings/qjs/garbage_collected.h @@ -36,8 +36,10 @@ class GarbageCollected { public: using ParentMostGarbageCollectedType = T; - template P* initialize(JSContext* ctx, JSClassID* classId); - template P* initialize(JSContext* ctx, JSClassID* classId, JSClassExoticMethods* exoticMethods); + template + P* initialize(JSContext* ctx, JSClassID* classId); + template + P* initialize(JSContext* ctx, JSClassID* classId, JSClassExoticMethods* exoticMethods); // Must use MakeGarbageCollected. void* operator new(size_t) = delete; @@ -93,7 +95,8 @@ class MakeGarbageCollectedTrait { }; template -template P* GarbageCollected::initialize(JSContext* ctx, JSClassID* classId, JSClassExoticMethods* exoticMethods) { +template +P* GarbageCollected::initialize(JSContext* ctx, JSClassID* classId, JSClassExoticMethods* exoticMethods) { JSRuntime* runtime = JS_GetRuntime(ctx); /// When classId is 0, it means this class are not initialized. We should create a JSClassDef to describe the behavior of this class and associate with classID. @@ -143,7 +146,8 @@ template P* GarbageCollected::initialize(JSContext* ctx, JSClass } template -template P* GarbageCollected::initialize(JSContext* ctx, JSClassID* classId) { +template +P* GarbageCollected::initialize(JSContext* ctx, JSClassID* classId) { return initialize

(ctx, classId, nullptr); } diff --git a/bridge/bindings/qjs/js_context_macros.h b/bridge/bindings/qjs/js_context_macros.h index e514f28cbe..971280e9a7 100644 --- a/bridge/bindings/qjs/js_context_macros.h +++ b/bridge/bindings/qjs/js_context_macros.h @@ -15,45 +15,41 @@ #define IMPL_PROPERTY_GETTER(Constructor, Property) JSValue Constructor::Property##PropertyDescriptor::getter #define IMPL_PROPERTY_SETTER(Constructor, Property) JSValue Constructor::Property##PropertyDescriptor::setter -#define INSTALL_READONLY_PROPERTY(Host, thisObject, property) \ - installPropertyGetter(context.get(), thisObject, #property, Host::property##PropertyDescriptor::getter) +#define INSTALL_READONLY_PROPERTY(Host, thisObject, property) installPropertyGetter(context.get(), thisObject, #property, Host::property##PropertyDescriptor::getter) #define INSTALL_PROPERTY(Host, thisObject, property) \ installPropertyGetterSetter(context.get(), thisObject, #property, Host::property##PropertyDescriptor::getter, Host::property##PropertyDescriptor::setter) -#define INSTALL_FUNCTION(Host, thisObject, property, argc) \ - installFunctionProperty(context.get(), thisObject, #property, Host::m_##property##_, 1); +#define INSTALL_FUNCTION(Host, thisObject, property, argc) installFunctionProperty(context.get(), thisObject, #property, Host::m_##property##_, 1); -#define DEFINE_FUNCTION(NAME) \ - static JSValue m_##NAME##_(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); +#define DEFINE_FUNCTION(NAME) static JSValue m_##NAME##_(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); #define IMPL_FUNCTION(Host, NAME) JSValue Host::m_##NAME##_ - #define DEFINE_PROTOTYPE_READONLY_PROPERTY(PROPERTY) \ class PROPERTY##PropertyDescriptor { \ public: \ static JSValue getter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \ - }; \ + }; #define DEFINE_PROTOTYPE_PROPERTY(PROPERTY) \ class PROPERTY##PropertyDescriptor { \ public: \ static JSValue getter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \ static JSValue setter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \ - }; \ + }; #define DEFINE_READONLY_PROPERTY(PROPERTY) \ class PROPERTY##PropertyDescriptor { \ public: \ static JSValue getter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \ - }; \ + }; #define DEFINE_PROPERTY(PROPERTY) \ class PROPERTY##PropertyDescriptor { \ public: \ static JSValue getter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \ static JSValue setter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \ - }; \ + }; #endif // KRAKENBRIDGE_JS_CONTEXT_MACROS_H diff --git a/bridge/bindings/qjs/wrapper_type_info.h b/bridge/bindings/qjs/wrapper_type_info.h index a7bc005cd0..02496a855c 100644 --- a/bridge/bindings/qjs/wrapper_type_info.h +++ b/bridge/bindings/qjs/wrapper_type_info.h @@ -6,8 +6,8 @@ #ifndef KRAKENBRIDGE_WRAPPER_TYPE_INFO_H #define KRAKENBRIDGE_WRAPPER_TYPE_INFO_H -#include #include +#include #include "bindings/qjs/qjs_patch.h" #include "include/kraken_foundation.h" @@ -22,8 +22,7 @@ class WrapperTypeInfo final { bool equals(const WrapperTypeInfo* that) const { return this == that; } bool isSubclass(const WrapperTypeInfo* that) const { - for (const WrapperTypeInfo* current = this; current; - current = current->parent_class) { + for (const WrapperTypeInfo* current = this; current; current = current->parent_class) { if (current == that) return true; } @@ -37,6 +36,6 @@ class WrapperTypeInfo final { JSClassID classId{0}; }; -} +} // namespace kraken::binding::qjs #endif // KRAKENBRIDGE_WRAPPER_TYPE_INFO_H diff --git a/bridge/page.cc b/bridge/page.cc index c24d439888..02602cd6ce 100644 --- a/bridge/page.cc +++ b/bridge/page.cc @@ -12,10 +12,10 @@ #include "bindings/qjs/bom/blob.h" #include "bindings/qjs/bom/console.h" +#include "bindings/qjs/bom/location.h" #include "bindings/qjs/bom/performance.h" #include "bindings/qjs/bom/screen.h" #include "bindings/qjs/bom/timer.h" -#include "bindings/qjs/bom/location.h" #include "bindings/qjs/bom/window.h" #include "bindings/qjs/dom/comment_node.h" #include "bindings/qjs/dom/custom_event.h"