Skip to content

Commit

Permalink
refactor: core modules compile success.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Jan 30, 2022
1 parent ace4002 commit d55a199
Show file tree
Hide file tree
Showing 38 changed files with 837 additions and 843 deletions.
51 changes: 29 additions & 22 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ list(APPEND BRIDGE_SOURCE
foundation/logging.cc
foundation/logging.h
foundation/colors.h
foundation/native_string.cc
foundation/native_string.h
foundation/ref_counted_internal.h
foundation/ref_counter.h
foundation/ref_ptr.h
Expand Down Expand Up @@ -184,35 +186,40 @@ if ($ENV{KRAKEN_JS_ENGINE} MATCHES "quickjs")
list(APPEND BRIDGE_SOURCE
page.cc
page.h

# Binding files
bindings/qjs/binding_initializer.cc
bindings/qjs/binding_initializer.h
bindings/qjs/garbage_collected.h
bindings/qjs/executing_context.cc
bindings/qjs/executing_context.h
bindings/qjs/executing_context_data.cc
bindings/qjs/executing_context_data.h
bindings/qjs/wrapper_type_info.h
bindings/qjs/heap_hashmap.h
bindings/qjs/native_string.cc
bindings/qjs/native_string.h
bindings/qjs/native_string_utils.cc
bindings/qjs/native_string_utils.h
bindings/qjs/qjs_patch.cc
bindings/qjs/qjs_patch.h
bindings/qjs/dart_methods.cc
bindings/qjs/dart_methods.h
core/dart_methods.h

# Core sources
core/dom/character_data.cc
core/dom/character_data.h
core/dom/comment.cc
core/dom/comment.h
core/dom/node.cc
core/dom/node.h
core/dom/events/custom_event.cc
core/dom/events/custom_event.h
core/dom/events/event.h
core/dom/events/event.cc
core/dom/events/event_listener_map.cc
core/dom/events/event_listener_map.h
core/dom/events/event_target.cc
core/dom/events/event_target.h
core/executing_context.cc
core/executing_context.h
core/executing_context_data.cc
core/executing_context_data.h
core/frame/dom_timer_coordinator.cc
core/frame/dom_timer_coordinator.h
# core/dom/character_data.cc
# core/dom/character_data.h
# core/dom/comment.cc
# core/dom/comment.h
# core/dom/node.cc
# core/dom/node.h
# core/dom/events/custom_event.cc
# core/dom/events/custom_event.h
# core/dom/events/event.h
# core/dom/events/event.cc
# core/dom/events/event_listener_map.cc
# core/dom/events/event_listener_map.h
# core/dom/events/event_target.cc
# core/dom/events/event_target.h
)

# Quickjs use __builtin_frame_address() to get stack pointer, we should add follow options to get it work with -O2
Expand Down
49 changes: 49 additions & 0 deletions bridge/bindings/qjs/binding_initializer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2019 Alibaba Inc. All rights reserved.
* Author: Kraken Team.
*/

#include "binding_initializer.h"


//#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/window.h"
//#include "bindings/qjs/dom/comment_node.h"
//#include "bindings/qjs/dom/custom_event.h"
//#include "bindings/qjs/dom/document.h"
//#include "bindings/qjs/dom/document_fragment.h"
//#include "bindings/qjs/dom/element.h"
//#include "bindings/qjs/dom/elements/.gen/anchor_element.h"
//#include "bindings/qjs/dom/elements/.gen/canvas_element.h"
//#include "bindings/qjs/dom/elements/.gen/input_element.h"
//#include "bindings/qjs/dom/elements/.gen/object_element.h"
//#include "bindings/qjs/dom/elements/.gen/script_element.h"
//#include "bindings/qjs/dom/elements/image_element.h"
//#include "bindings/qjs/dom/elements/template_element.h"
//#include "bindings/qjs/dom/event.h"
//#include "bindings/qjs/dom/event_target.h"
//#include "bindings/qjs/dom/events/.gen/close_event.h"
//#include "bindings/qjs/dom/events/.gen/gesture_event.h"
//#include "bindings/qjs/dom/events/.gen/input_event.h"
//#include "bindings/qjs/dom/events/.gen/intersection_change.h"
//#include "bindings/qjs/dom/events/.gen/media_error_event.h"
//#include "bindings/qjs/dom/events/.gen/message_event.h"
//#include "bindings/qjs/dom/events/.gen/mouse_event.h"
//#include "bindings/qjs/dom/events/.gen/popstate_event.h"
//#include "bindings/qjs/dom/events/touch_event.h"
//#include "bindings/qjs/dom/style_declaration.h"
//#include "bindings/qjs/dom/text_node.h"
//#include "bindings/qjs/module_manager.h"

namespace kraken {

void initBinding() {

}

}
51 changes: 51 additions & 0 deletions bridge/bindings/qjs/binding_initializer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2019 Alibaba Inc. All rights reserved.
* Author: Kraken Team.
*/

#ifndef KRAKENBRIDGE_BINDING_INITIALIZER_H
#define KRAKENBRIDGE_BINDING_INITIALIZER_H

namespace kraken {

void initBinding();


// bindConsole(m_context);
// bindTimer(m_context);
// bindScreen(m_context);
// bindModuleManager(m_context);
// bindEventTarget(m_context);
// bindBlob(m_context);
// bindLocation(m_context);
// bindWindow(m_context);
// bindEvent(m_context);
// bindCustomEvent(m_context);
// bindNode(m_context);
// bindDocumentFragment(m_context);
// bindTextNode(m_context);
// bindCommentNode(m_context);
// bindElement(m_context);
// bindAnchorElement(m_context);
// bindCanvasElement(m_context);
// bindImageElement(m_context);
// bindInputElement(m_context);
// bindObjectElement(m_context);
// bindScriptElement(m_context);
// bindTemplateElement(m_context);
// bindCSSStyleDeclaration(m_context);
// bindCloseEvent(m_context);
// bindGestureEvent(m_context);
// bindInputEvent(m_context);
// bindIntersectionChangeEvent(m_context);
// bindMediaErrorEvent(m_context);
// bindMouseEvent(m_context);
// bindMessageEvent(m_context);
// bindPopStateEvent(m_context);
// bindTouchEvent(m_context);
// bindDocument(m_context);
// bindPerformance(m_context);

}

#endif // KRAKENBRIDGE_BINDING_INITIALIZER_H
44 changes: 0 additions & 44 deletions bridge/bindings/qjs/dart_methods.cc

This file was deleted.

3 changes: 2 additions & 1 deletion bridge/bindings/qjs/garbage_collected.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#define KRAKENBRIDGE_GARBAGE_COLLECTED_H

#include <quickjs/quickjs.h>
#include "include/kraken_foundation.h"

#include "foundation/macros.h"
#include "qjs_patch.h"

namespace kraken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Author: Kraken Team.
*/

#ifndef KRAKENBRIDGE_CONTEXT_MACROS_H
#define KRAKENBRIDGE_CONTEXT_MACROS_H
#ifndef KRAKENBRIDGE_BINDING_MACROS_H
#define KRAKENBRIDGE_BINDING_MACROS_H

#define QJS_GLOBAL_BINDING_FUNCTION(context, function, name, argc) \
{ \
Expand Down Expand Up @@ -52,4 +52,4 @@
static JSValue setter(JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv); \
};

#endif // KRAKENBRIDGE_CONTEXT_MACROS_H
#endif // KRAKENBRIDGE_BINDING_MACROS_H
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@
* Author: Kraken Team.
*/

#include "native_string.h"
#include "native_string_utils.h"
#include "bindings/qjs/qjs_patch.h"

namespace kraken {


NativeString* NativeString::clone() {
auto* newNativeString = new NativeString();
auto* newString = new uint16_t[length];

memcpy(newString, string, length * sizeof(uint16_t));
newNativeString->string = newString;
newNativeString->length = length;
return newNativeString;
}

void NativeString::free() {
delete[] string;
}

std::unique_ptr<NativeString> jsValueToNativeString(JSContext* ctx, JSValue value) {
bool isValueString = true;
if (JS_IsNull(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
* Author: Kraken Team.
*/

#ifndef KRAKENBRIDGE_NATIVE_STRING_H
#define KRAKENBRIDGE_NATIVE_STRING_H
#ifndef KRAKENBRIDGE_NATIVE_STRING_UTILS_H
#define KRAKENBRIDGE_NATIVE_STRING_UTILS_H

#include <quickjs/quickjs.h>
#include <cinttypes>
#include <string>
#include <memory>
#include <locale>
#include <codecvt>

namespace kraken {

struct NativeString {
const uint16_t* string;
uint32_t length;
#include "foundation/native_string.h"

NativeString* clone();
void free();
};
namespace kraken {

// Convert to string and return a full copy of NativeString from JSValue.
std::unique_ptr<NativeString> jsValueToNativeString(JSContext* ctx, JSValue value);
Expand Down Expand Up @@ -56,6 +49,4 @@ void fromUTF8(const std::string& source, std::basic_string<T, std::char_traits<T

}

class native_string {};

#endif // KRAKENBRIDGE_NATIVE_STRING_H
#endif // KRAKENBRIDGE_NATIVE_STRING_UTILS_H
2 changes: 1 addition & 1 deletion bridge/core/css/css_style_declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef KRAKENBRIDGE_CSS_STYLE_DECLARATION_H
#define KRAKENBRIDGE_CSS_STYLE_DECLARATION_H

#include "bindings/qjs/context_macros.h"
#include "bindings/qjs/macros.h"
#include "bindings/qjs/dom/event_target.h"
#include "bindings/qjs/garbage_collected.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ struct DartMethodPointer {
InitDocument initDocument{nullptr};
};

void registerDartMethods(std::shared_ptr<DartMethodPointer> methodPointer, uint64_t* methodBytes, int32_t length);

#ifdef IS_TEST
KRAKEN_EXPORT
void registerTestEnvDartMethods(std::shared_ptr<DartMethodPointer> methodPointer, uint64_t* methodBytes, int32_t length);
#endif

} // namespace kraken

#endif
2 changes: 0 additions & 2 deletions bridge/core/dom/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#define KRAKENBRIDGE_ELEMENT_H

#include <unordered_map>
#include "bindings/qjs/executing_context.h"
#include "bindings/qjs/garbage_collected.h"
#include "node.h"
#include "style_declaration.h"

namespace kraken {

Expand Down
2 changes: 1 addition & 1 deletion bridge/core/dom/events/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef KRAKENBRIDGE_EVENT_H
#define KRAKENBRIDGE_EVENT_H

#include "bindings/qjs/context_macros.h"
#include "bindings/qjs/macros.h"
#include "bindings/qjs/executing_context.h"

namespace kraken {
Expand Down
1 change: 0 additions & 1 deletion bridge/core/dom/events/event_listener_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <quickjs/quickjs.h>
#include <vector>
#include "include/kraken_foundation.h"

namespace kraken {

Expand Down
10 changes: 4 additions & 6 deletions bridge/core/dom/events/event_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
* Author: Kraken Team.
*/

#include "event_target.h"

#include <utility>
#include "bindings/qjs/bom/window.h"
#include "bindings/qjs/dom/text_node.h"

#include "event_target.h"
#include "bindings/qjs/qjs_patch.h"
#include "custom_event.h"
#include "document.h"
#include "element.h"
#include "event.h"
#include "core/dom/node.h"
#include "core/frame/window.h"

#if UNIT_TEST
#include "kraken_test_env.h"
Expand Down
Loading

0 comments on commit d55a199

Please sign in to comment.