Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
f3f6f62
feat: add dedicatedJSThread API.
andycall Oct 31, 2023
9b30a1f
feat: support dedicated JavaScript thread and double uiCommandBuffer …
penneryu Nov 15, 2023
e7bc4b3
doc: guides for flutter dev part I. (#507)
andycall Nov 1, 2023
4da0883
Update README.md
andycall Nov 1, 2023
b748b71
Update README.md
andycall Nov 1, 2023
9a5fc9a
Update README.md
andycall Nov 7, 2023
f293b17
fix: fix compile issue.
andycall Nov 17, 2023
34ee24c
chore: rename functions and symbols.
andycall Nov 18, 2023
659a750
Committing clang-format changes
Nov 18, 2023
20efa90
refactor: re-organize codes.
andycall Nov 19, 2023
af85233
Committing clang-format changes
Nov 19, 2023
58bf452
fix: fix integration test build.
andycall Nov 20, 2023
edbaeb4
fix: fix crash.
andycall Nov 20, 2023
67b3112
fix: create every webf with dedicatedThread have it's own thread.
andycall Nov 21, 2023
323b1d2
fix: fix dispose js thread.
andycall Nov 21, 2023
bd4559f
fix: support running webf mixed dedicated options.
andycall Nov 21, 2023
b560ae0
Committing clang-format changes
Nov 21, 2023
f4310cd
feat: support thread group and put multiple js context into one thread.
andycall Nov 23, 2023
cd1220a
fix: fix html code been freed before used.
andycall Nov 23, 2023
f8b7896
fix: fix compile.
andycall Nov 23, 2023
6c2f23e
Committing clang-format changes
Nov 23, 2023
84727be
fix: fix invoke module events.
andycall Nov 23, 2023
abe6d0d
fix: fix dispatch event and invoke module event from dart.
andycall Nov 23, 2023
fe79cea
Committing clang-format changes
Nov 23, 2023
8915c74
fix: fix dispatch module event crash on android arm devices.
andycall Nov 24, 2023
c104faa
Committing clang-format changes
Nov 24, 2023
92646a7
feat: optimize Element.getBoundingClientRect() and window.screen perf…
andycall Nov 24, 2023
5b3f3d4
Committing clang-format changes
Nov 24, 2023
e36c164
fix: fix dump bytecodes and dart methods.
andycall Nov 25, 2023
046f741
Committing clang-format changes
Nov 25, 2023
8828e6d
feat: use read-write lock to replace the multiple buffering in uiComm…
andycall Nov 26, 2023
9ac005b
Committing clang-format changes
Nov 26, 2023
dcb9d84
fix: fix integration test and potential dead locks.
andycall Nov 27, 2023
aa91203
fix: add logs and fix dart call blocked js thread.
andycall Nov 28, 2023
d9ffe18
fix: fix invoke module dead locks.
andycall Nov 28, 2023
3572505
refactor: improve timer and RAF performance.
andycall Nov 29, 2023
9f99a43
fix: fix widget elements.
andycall Nov 29, 2023
6a65a26
fix: fix simulate pointer and get property of widget element.
andycall Nov 29, 2023
8e66859
fix: fix bounding client rect and potential crash.
andycall Nov 29, 2023
f193e8e
fix: fix websocket and mutation observer tests.
andycall Nov 29, 2023
dbbc3a2
fix: fix unit tests.
andycall Nov 29, 2023
ef52ee6
fix: fix build issue and linter.
andycall Nov 30, 2023
d8c93c5
fix: support run integration test in single thread.
andycall Dec 1, 2023
2d02363
fix: fix memory leaks on getOwnerProperty.
andycall Dec 1, 2023
35a7048
Committing clang-format changes
Dec 1, 2023
0fa71a1
fix: fix controller.reload() error.
andycall Dec 1, 2023
e1eb46e
fix: fix event test specs.
andycall Dec 1, 2023
632803b
fix: fix requestAnimationFrame crash.
andycall Dec 4, 2023
ef0b90b
fix: fix RenderLineBox renderer error.
andycall Dec 4, 2023
48ed68c
fix: fix percentage infinity error.
andycall Dec 4, 2023
7c7e8c7
Committing clang-format changes
Dec 4, 2023
b38fe5a
fix: fix memory leaks of RAF callbacks.
andycall Dec 5, 2023
781179e
build: optimize build scripts.
andycall Dec 5, 2023
c6d352a
fix: fix renderObject disposed and paint in the same frame.
andycall Dec 5, 2023
cf5009d
chore: fix example.
andycall Dec 5, 2023
3fe9708
chore: fix example.
andycall Dec 5, 2023
772e8af
feat: support flushUICommand by various conditions.
andycall Dec 13, 2023
8e0aa67
feat: optimize commands iteration.
andycall Dec 13, 2023
001e8bd
fix: fix ui command not flushed when no new command arrived.
andycall Dec 14, 2023
18a5b3b
fix: fix RAF animation crashed by cancel.
andycall Dec 15, 2023
875e1a3
feat: make allocateNewPage and disposePage async.
andycall Dec 16, 2023
7c59779
fix: fix dead locks when disposePages.
andycall Dec 20, 2023
6dc3904
fix: fix dead locks when hot restart.
andycall Dec 21, 2023
4639bd5
fix: fix js runtime resource not freeed when dart isolate finalized.
andycall Dec 25, 2023
56038bc
fix: fix freeze when no js running when hot restart.
andycall Dec 27, 2023
5080ec8
revert: revert UI command.
andycall Dec 27, 2023
14d01ad
fix: fix linter.
andycall Dec 27, 2023
79dc274
fix: compact with main branch
andycall Dec 28, 2023
e1519a2
Committing clang-format changes
Dec 28, 2023
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
WebF presents a high-performance, cutting-edge web rendering engine built on top of Flutter, empowering web applications to operate natively within the Flutter ecosystem.

- **Adherence to W3C Standards:** By leveraging HTML/CSS and JavaScript, WebF renders content on Flutter, ensuring impeccable alignment with standard browser rendering.

- **Compatible with Leading Front-End Frameworks:** Given its compliance with W3C standards, WebF seamlessly integrates with popular front-end frameworks, including [React](https://reactjs.org/) and [Vue](https://vuejs.org/).

- **Amplify Your Web Applications with Flutter:** WebF's adaptability shines through its customization capabilities. Craft bespoke HTML elements using Flutter Widgets or enhance your application by integrating a JavaScript API sourced from any Dart library on the `pub.dev` registry.

- **Authentic Web Development Environment:** Experience a traditional web development setting with WebF. It facilitates DOM structure inspection, CSS style evaluations, and JavaScript debugging via Chrome DevTools.

- **Craft Once, Deploy Everywhere:** Harness the versatility of WebF to design your web application and launch it across any Flutter-compatible device. What's more, maintain the flexibility to execute your apps within Node.js or web browsers, all from a unified codebase.

## Join Our Mission
Expand All @@ -26,7 +26,7 @@ If you or your team are interested in supporting us, please contact @andycall on

[![Discord Shield](https://discordapp.com/api/guilds/1008119434688344134/widget.png?style=banner1)](https://discord.gg/DvUBtXZ5rK)

## The update and maintenance policy for WebF versions
## The update and maintenance policy for WebF versions

Each version of WebF will be maintained for the lifespan of three minor WebF releases. For instance, WebF 0.15.0 was released to be compatible with Flutter 3.10.x. Its support will conclude once WebF 0.18.0 is introduced. Any updates applied to versions 0.16.x and 0.17.x will be cherry-picked for the subsequent update of 0.15.x.

Expand Down
17 changes: 16 additions & 1 deletion bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ else ()
add_definitions(-DENABLE_PROFILE=0)
endif ()

if (${ENABLE_LOG})
add_definitions(-DENABLE_LOG=1)
else()
add_definitions(-DENABLE_LOG=0)
endif()

if(NOT MSVC)
if (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
include(CheckIPOSupported)
Expand Down Expand Up @@ -91,17 +97,19 @@ if (DEFINED PLATFORM)
endif()

list(APPEND BRIDGE_SOURCE
webf_bridge.cc
foundation/logging.cc
foundation/native_string.cc
foundation/ui_task_queue.cc
foundation/shared_ui_command.cc
foundation/inspector_task_queue.cc
foundation/task_queue.cc
foundation/string_view.cc
foundation/native_value.cc
foundation/native_type.cc
foundation/ui_command_buffer.cc
polyfill/dist/polyfill.cc
multiple_threading/dispatcher.cc
multiple_threading/looper.cc
${CMAKE_CURRENT_LIST_DIR}/third_party/dart/include/dart_api_dl.c
)

Expand Down Expand Up @@ -189,6 +197,11 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
third_party/quickjs/src/core/builtins/js-symbol.c
third_party/quickjs/src/core/builtins/js-typed-array.c
)

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_definitions(-DDDEBUG)
endif ()

if(${STATIC_QUICKJS})
add_library(quickjs STATIC ${QUICK_JS_SOURCE})
else()
Expand Down Expand Up @@ -247,6 +260,8 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
bindings/qjs/rejected_promises.cc
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
Expand Down
8 changes: 8 additions & 0 deletions bridge/bindings/qjs/script_wrappable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ ScriptValue ScriptWrappable::ToValue() {
return ScriptValue(ctx_, jsObject_);
}

multi_threading::Dispatcher* ScriptWrappable::GetDispatcher() const {
return context_->dartIsolateContext()->dispatcher().get();
}

/// This callback will be called when QuickJS GC is running at marking stage.
/// Users of this class should override `void TraceMember(JSRuntime* rt, JSValueConst val, JS_MarkFunc* mark_func)` to
/// tell GC which member of their class should be collected by GC.
Expand Down Expand Up @@ -238,6 +242,8 @@ void ScriptWrappable::InitializeQuickJSObject() {
desc->value = return_value;
desc->getter = JS_NULL;
desc->setter = JS_NULL;
} else {
JS_FreeValue(ctx, return_value);
}
return true;
}
Expand All @@ -252,6 +258,8 @@ void ScriptWrappable::InitializeQuickJSObject() {
desc->value = return_value;
desc->getter = JS_NULL;
desc->setter = JS_NULL;
} else {
JS_FreeValue(ctx, return_value);
}
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions bridge/bindings/qjs/script_wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <quickjs/quickjs.h>
#include "bindings/qjs/cppgc/garbage_collected.h"
#include "foundation/macros.h"
#include "multiple_threading/dispatcher.h"
#include "wrapper_type_info.h"

namespace webf {
Expand Down Expand Up @@ -52,6 +53,7 @@ class ScriptWrappable : public GarbageCollected<ScriptWrappable> {

ScriptValue ToValue();
FORCE_INLINE ExecutingContext* GetExecutingContext() const { return context_; };
multi_threading::Dispatcher* GetDispatcher() const;
FORCE_INLINE JSContext* ctx() const { return ctx_; }
FORCE_INLINE JSRuntime* runtime() const { return runtime_; }
FORCE_INLINE int64_t contextId() const { return context_id_; }
Expand Down
88 changes: 88 additions & 0 deletions bridge/core/api/api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/

#include "api.h"
#include "core/dart_isolate_context.h"
#include "core/html/parser/html_parser.h"
#include "core/page.h"
#include "multiple_threading/dispatcher.h"

namespace webf {

static void ReturnEvaluateScriptsInternal(Dart_PersistentHandle persistent_handle,
EvaluateQuickjsByteCodeCallback result_callback,
bool is_success) {
Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle);
result_callback(handle, is_success ? 1 : 0);
Dart_DeletePersistentHandle_DL(persistent_handle);
}

void evaluateScriptsInternal(void* page_,
const char* code,
uint64_t code_len,
uint8_t** parsed_bytecodes,
uint64_t* bytecode_len,
const char* bundleFilename,
int32_t startLine,
Dart_Handle persistent_handle,
EvaluateScriptsCallback result_callback) {
auto page = reinterpret_cast<webf::WebFPage*>(page_);
assert(std::this_thread::get_id() == page->currentThread());
bool is_success = page->evaluateScript(code, code_len, parsed_bytecodes, bytecode_len, bundleFilename, startLine);
page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateScriptsInternal,
persistent_handle, result_callback, is_success);
}

static void ReturnEvaluateQuickjsByteCodeResultToDart(Dart_PersistentHandle persistent_handle,
EvaluateQuickjsByteCodeCallback result_callback,
bool is_success) {
Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle);
result_callback(handle, is_success ? 1 : 0);
Dart_DeletePersistentHandle_DL(persistent_handle);
}

void evaluateQuickjsByteCodeInternal(void* page_,
uint8_t* bytes,
int32_t byteLen,
Dart_PersistentHandle persistent_handle,
EvaluateQuickjsByteCodeCallback result_callback) {
auto page = reinterpret_cast<webf::WebFPage*>(page_);
assert(std::this_thread::get_id() == page->currentThread());
bool is_success = page->evaluateByteCode(bytes, byteLen);
page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateQuickjsByteCodeResultToDart,
persistent_handle, result_callback, is_success);
}

void parseHTMLInternal(void* page_, const char* code, int32_t length) {
auto page = reinterpret_cast<webf::WebFPage*>(page_);
assert(std::this_thread::get_id() == page->currentThread());
page->parseHTML(code, length);
delete code;
}

static void ReturnInvokeEventResultToDart(Dart_Handle persistent_handle,
InvokeModuleEventCallback result_callback,
webf::NativeValue* result) {
Dart_Handle handle = Dart_HandleFromPersistent_DL(persistent_handle);
result_callback(handle, result);
Dart_DeletePersistentHandle_DL(persistent_handle);
}

void invokeModuleEventInternal(void* page_,
void* module_name,
const char* eventType,
void* event,
void* extra,
Dart_Handle persistent_handle,
InvokeModuleEventCallback result_callback) {
auto page = reinterpret_cast<webf::WebFPage*>(page_);
auto dart_isolate_context = page->executingContext()->dartIsolateContext();
assert(std::this_thread::get_id() == page->currentThread());
auto* result = page->invokeModuleEvent(reinterpret_cast<webf::SharedNativeString*>(module_name), eventType, event,
reinterpret_cast<webf::NativeValue*>(extra));
dart_isolate_context->dispatcher()->PostToDart(page->isDedicated(), ReturnInvokeEventResultToDart, persistent_handle,
result_callback, result);
}

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

#ifndef WEBF_CORE_API_API_H_
#define WEBF_CORE_API_API_H_

#include <cassert>
#include "include/webf_bridge.h"

namespace webf {

void evaluateScriptsInternal(void* page_,
const char* code,
uint64_t code_len,
uint8_t** parsed_bytecodes,
uint64_t* bytecode_len,
const char* bundleFilename,
int32_t startLine,
Dart_Handle dart_handle,
EvaluateScriptsCallback result_callback);

void evaluateQuickjsByteCodeInternal(void* page_,
uint8_t* bytes,
int32_t byteLen,
Dart_PersistentHandle persistent_handle,
EvaluateQuickjsByteCodeCallback result_callback);
void parseHTMLInternal(void* page_, const char* code, int32_t length);

void invokeModuleEventInternal(void* page_,
void* module_name,
const char* eventType,
void* event,
void* extra,
Dart_Handle dart_handle,
InvokeModuleEventCallback result_callback);

} // namespace webf

#endif // WEBF_CORE_API_API_H_
Loading