Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: Add Rust native support #554

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c1f3da4
feat: init rust project.
andycall Jan 31, 2024
6dfdf79
feat: initialize version of rust bindings of WebF.
andycall Feb 6, 2024
311db90
feat: replace three line JavaScript polyfill with rust based on Rust …
andycall Feb 7, 2024
9664627
feat: add webf-sys crate.
andycall Feb 8, 2024
3fe606b
Committing clang-format changes
Feb 8, 2024
4cac071
feat: rename to webf-sys crate
andycall Feb 16, 2024
c13ac99
fix: fix build scripts.
andycall Feb 16, 2024
6b6ac9c
feat: compile and running on macos works.
andycall Feb 16, 2024
950fd92
fix build failure
LeuisKen Jul 1, 2024
5a25ba9
feat: Add new document methods binding
LeuisKen Jul 2, 2024
8aaab8e
refactor: merge rust public API as standard WebF C/C++ public API.
andycall Jul 3, 2024
e265f09
feat: add native library loader.
andycall Jul 5, 2024
5585fe5
add new create_element methods
LeuisKen Jul 5, 2024
e3e1647
add createDocumentFragment
LeuisKen Jul 5, 2024
57f23c9
add createComment
LeuisKen Jul 5, 2024
81bd0ec
feat: add rust build gule.
andycall Jul 7, 2024
02d7efb
feat: add cargokit to example.
andycall Jul 7, 2024
5031265
fix: fix macos lib name.
andycall Jul 7, 2024
63f82d5
feat: add document.head and document.body API.
andycall Jul 8, 2024
530983f
fix: fix package name in other platforms.
andycall Jul 10, 2024
717de63
add document.createEvent
LeuisKen Jul 8, 2024
82ec236
querySelector & getElementById
LeuisKen Jul 9, 2024
956e154
The elementFromPoint() method.
LeuisKen Jul 9, 2024
443bb76
feat: add Node.removeChild.
andycall Jul 11, 2024
9ab44bb
feat: remove core_rs module.
andycall Jul 11, 2024
a2f510b
feat: add rust support for integration test.
andycall Jul 11, 2024
58b22b1
fix: fix dom init polyfill
andycall Jul 11, 2024
2f2abdd
feat: add EventTarget.addEventListener API.
andycall Jul 21, 2024
59153e7
fix: fix match check.
andycall Jul 21, 2024
90a2cdb
feat: support event handler callback.
andycall Jul 21, 2024
e274a04
add remove event listener
LeuisKen Jul 25, 2024
1369d95
feat: upgrade example code.
andycall Jul 26, 2024
c3ade49
event & event_target
LeuisKen Sep 2, 2024
03b0d6f
update event handling in Rust API
LeuisKen Sep 11, 2024
9ba8148
feat: new rust ffi arch.
andycall Sep 12, 2024
219cfa2
fix: fix method pointer crash.
andycall Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if(MSVC)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
# set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()

if(WIN32)
Expand Down Expand Up @@ -138,6 +138,7 @@ list(APPEND BRIDGE_INCLUDE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/polyfill/dist
${CMAKE_CURRENT_LIST_DIR}/core_rs/include
${CMAKE_CURRENT_LIST_DIR}/third_party/dart
${ADDITIONAL_INCLUDE_DIRS}
)
Expand Down Expand Up @@ -265,12 +266,27 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
bindings/qjs/union_base.cc
# Core sources
webf_bridge.cc
core/api/api.cc
core/executing_context.cc
core/script_forbidden_scope.cc
core/script_state.cc
core/page.cc
core/dart_methods.cc
core/api/exception_state.cc
core/api/event_target.cc
core/api/event.cc
core/api/node.cc
core/api/executing_context.cc
core/api/container_node.cc
core/api/document.cc
core/api/element.cc
core/api/html_element.cc
core/api/html_image_element.cc
core/api/html_canvas_element.cc
core/api/document_fragment.cc
core/api/window.cc
core/api/text.cc
core/api/comment.cc
core/api/character_data.cc
core/dart_isolate_context.cc
core/dart_context_data.cc
core/executing_context_data.cc
Expand Down Expand Up @@ -379,6 +395,8 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
core/html/forms/html_form_element.cc
core/html/forms/html_textarea_element.cc

core/native/native_loader.cc

# SVG files
core/svg/svg_element.cc
core/svg/svg_graphics_element.cc
Expand Down Expand Up @@ -475,6 +493,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
out/qjs_css_style_declaration.cc
out/qjs_inline_css_style_declaration.cc
out/qjs_computed_css_style_declaration.cc
out/qjs_native_loader.cc
out/qjs_text.cc
out/qjs_screen.cc
out/qjs_node_list.cc
Expand Down
2 changes: 2 additions & 0 deletions bridge/bindings/qjs/binding_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qjs_dom_matrix.h"
#include "qjs_dom_matrix_readonly.h"
#include "qjs_dom_string_map.h"
#include "qjs_native_loader.h"
#include "qjs_dom_token_list.h"
#include "qjs_element.h"
#include "qjs_element_attributes.h"
Expand Down Expand Up @@ -199,6 +200,7 @@ void InstallBindings(ExecutingContext* context) {
QJSSVGEllipseElement::Install(context);
QJSSVGStyleElement::Install(context);
QJSSVGLineElement::Install(context);
QJSNativeLoader::Install(context);

// Legacy bindings, not standard.
QJSElementAttributes::Install(context);
Expand Down
5 changes: 5 additions & 0 deletions bridge/bindings/qjs/exception_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/
#include "exception_state.h"
#include "plugin_api/exception_state.h"

namespace webf {

ExceptionStatePublicMethods* ExceptionState::publicMethodPointer() {
return new ExceptionStatePublicMethods();
}

void ExceptionState::ThrowException(JSContext* ctx, ErrorType type, const std::string& message) {
switch (type) {
case ErrorType::TypeError:
Expand Down
4 changes: 4 additions & 0 deletions bridge/bindings/qjs/exception_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace webf {

class ExceptionStatePublicMethods;

enum ErrorType { TypeError, InternalError, RangeError, ReferenceError, SyntaxError };

// ExceptionState is a scope-like class and provides a way to store an exception.
Expand All @@ -21,6 +23,8 @@ class ExceptionState {
WEBF_DISALLOW_NEW();

public:
static ExceptionStatePublicMethods* publicMethodPointer();

void ThrowException(JSContext* ctx, ErrorType type, const std::string& message);
void ThrowException(JSContext* ctx, JSValue exception);
bool HasException();
Expand Down
21 changes: 10 additions & 11 deletions bridge/bindings/qjs/script_wrappable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,19 @@ void ScriptWrappable::InitializeQuickJSObject() {
}

void ScriptWrappable::KeepAlive() {
if (is_alive)
return;

context_->RegisterActiveScriptWrappers(this);
JS_DupValue(ctx_, jsObject_);
is_alive = true;
if (alive_count == 0) {
context_->RegisterActiveScriptWrappers(this);
JS_DupValue(ctx_, jsObject_);
}
alive_count++;
}

void ScriptWrappable::ReleaseAlive() {
if (!is_alive)
return;
context_->InActiveScriptWrappers(this);
JS_FreeValue(ctx_, jsObject_);
is_alive = false;
alive_count--;
if (alive_count == 0) {
context_->InActiveScriptWrappers(this);
JS_FreeValue(ctx_, jsObject_);
}
}

} // namespace webf
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/script_wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ScriptWrappable : public GarbageCollected<ScriptWrappable> {
void ReleaseAlive();

private:
bool is_alive = false;
uint32_t alive_count = 0;
JSValue jsObject_{JS_NULL};
JSContext* ctx_{nullptr};
ExecutingContext* context_{nullptr};
Expand Down
2 changes: 2 additions & 0 deletions bridge/bindings/qjs/wrapper_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ enum {
JS_CLASS_DOM_TOKEN_LIST,
JS_CLASS_DOM_STRING_MAP,

JS_CLASS_NATIVE_LOADER,

// SVG
JS_CLASS_SVG_ELEMENT,
JS_CLASS_SVG_GRAPHICS_ELEMENT,
Expand Down
157 changes: 0 additions & 157 deletions bridge/core/api/api.cc

This file was deleted.

57 changes: 0 additions & 57 deletions bridge/core/api/api.h

This file was deleted.

10 changes: 10 additions & 0 deletions bridge/core/api/character_data.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/

#include "plugin_api/character_data.h"
#include "core/dom/node.h"

namespace webf {

} // namespace webf
10 changes: 10 additions & 0 deletions bridge/core/api/comment.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/

#include "plugin_api/comment.h"
#include "core/dom/character_data.h"

namespace webf {

} // namespace webf
Loading
Loading