Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
42e5e59
Update integration_test_flutter.yml
andycall Sep 24, 2022
029e98b
refactor: redesigned module api.
andycall Sep 24, 2022
44b341a
feat: remove unused and deprecated features.
andycall Sep 24, 2022
e0a799e
Committing clang-format changes
Sep 24, 2022
1da1165
chore: fix types.
andycall Sep 24, 2022
9e6af0e
beta: 0.13.0-beta.2
andycall Sep 25, 2022
e5ff545
fix: fix broken symlinks
andycall Sep 25, 2022
a73d2bd
fix: fix publish linter check.
andycall Sep 25, 2022
2fda093
fix: fix error assertion.
andycall Sep 25, 2022
6c0092d
fix: handle exception when convert script value to native value.
andycall Sep 25, 2022
091d230
fix: fix heap use after free when free QJSFunction at dispose stage.
andycall Sep 25, 2022
d3f87cc
Merge branch 'refactor/remove_host_class' into refactor/invoke_module…
andycall Sep 25, 2022
592b900
Committing clang-format changes
Sep 25, 2022
245a188
fix: fix compile.
andycall Sep 25, 2022
bd6be27
fix: fix scriptState cause string leaks.
andycall Sep 25, 2022
f7dd89a
beta: 0.13.0-beta.3
andycall Sep 25, 2022
4d2c85a
fix: fix integration tests.
andycall Sep 26, 2022
f77afe5
Merge remote-tracking branch 'origin/refactor/remove_host_class' into…
andycall Sep 26, 2022
72d1b2d
Merge remote-tracking branch 'origin/refactor/remove_host_class' into…
andycall Sep 26, 2022
d282c34
fix: fix document create event crash
andycall Sep 26, 2022
f0b5859
Merge branch 'refactor/remove_host_class' into refactor/invoke_module…
andycall Sep 26, 2022
3fb58eb
fix: upgrade websocket plugin.
andycall Sep 26, 2022
4791c38
fix: fix undefined params of addEventListener.
andycall Sep 26, 2022
c92a120
fix: add isContextValid and isCtxValid();
andycall Sep 26, 2022
11730de
feat: flush all disposeEventTarget commands when dispose page.
andycall Sep 26, 2022
462e0f6
Committing clang-format changes
Sep 26, 2022
0023f11
feat: add document.cookie.
andycall Sep 26, 2022
648c174
fix: fix multiple pages didn't schedule frames.
andycall Sep 26, 2022
2331909
fix: fix android 32bit build.
andycall Sep 27, 2022
4c37f96
Committing clang-format changes
Sep 27, 2022
9624a34
chore: remove mistake define.
andycall Sep 27, 2022
c9f0609
fix: fix JSPropertyDescriptor not initialized.
andycall Sep 27, 2022
0a60ef6
ci: fix integration test ci
andycall Sep 27, 2022
5a3c236
fix: should not bind bindObject when it already disposed.
andycall Sep 27, 2022
5f03c2c
fix: should init dart methods when allocate new bridge.
andycall Sep 27, 2022
ea22a72
fix: fix linux build.
andycall Sep 27, 2022
99c59fb
Committing clang-format changes
Sep 27, 2022
9d28b6b
chore: remove unused code.
andycall Sep 27, 2022
53513be
fix: fix dart allocated binding object not initialized.
andycall Sep 28, 2022
f7d70b6
fix: fix android 32 bit build.
andycall Sep 28, 2022
410f514
Committing clang-format changes
Sep 28, 2022
2da1286
fix: fix set event handler property to custom element.
andycall Sep 28, 2022
9920cb9
Committing clang-format changes
Sep 28, 2022
e4772f0
feat: ignore undefined property when set attribute.
andycall Sep 30, 2022
eac50cf
feat: add link element interface.
andycall Sep 30, 2022
c586a10
fix: disable attribute querySelector.
andycall Sep 30, 2022
66d353a
chore: add hsl snapshots.
andycall Sep 30, 2022
6606fb6
Committing clang-format changes
Sep 30, 2022
68dd213
fix: fix ui command buffer flush crash when hot restart.
andycall Sep 30, 2022
811cc27
Committing clang-format changes
Sep 30, 2022
53f1aed
fix: fix missing isAttributeDefined on element.
andycall Oct 1, 2022
150aa24
Committing clang-format changes
Oct 1, 2022
91558ae
revert: temporary disable ignore element attributes.
andycall Oct 1, 2022
18f9c24
fix: animation-duration should reset to zero if negative.
andycall Oct 2, 2022
ab43596
fix: element's offsetParent should ended at documentElement.
andycall Oct 2, 2022
93fdd74
fix: parseHTML should include header and body.
andycall Oct 2, 2022
52c6f6f
fix: fix animation test specs.
andycall Oct 2, 2022
6ca0074
Committing clang-format changes
Oct 2, 2022
4444b91
revert: ab43596cebead352cb43ea1f842212350f8111df
andycall Oct 4, 2022
478b1d5
test: fix test specs.
andycall Oct 4, 2022
8babe7b
test: fix test specs.
andycall Oct 4, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/example_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
env:
nodeVersion: "16"
cmakeVersion: "3.22.x"
flutterVersion: "3.0.4"
flutterVersion: "3.0.5"

jobs:
build_android-app_in_macos:
Expand Down
20 changes: 2 additions & 18 deletions .github/workflows/integration_test_flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [workflow_dispatch, pull_request]
env:
nodeVersion: "16"
cmakeVersion: "3.22.x"
flutterVersion: "3.0.4"
flutterVersion: "3.0.5"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand All @@ -30,7 +30,7 @@ jobs:
with:
cmake-version: ${{ env.cmakeVersion }}
- run: npm i
- run: ENABLE_ASAN=true npm run build:bridge:macos
- run: npm run build:bridge:macos
- uses: actions/upload-artifact@v2
with:
name: macos_bridge_binary
Expand All @@ -49,22 +49,6 @@ jobs:
- run: npm i
- run: ENABLE_ASAN=true npm run build:bridge:linux
- run: node scripts/run_bridge_unit_test.js
id: bridge_test
- name: Check on failures
if: steps.bridge_test.outcome == 'success'
run: exit 0
- run: sudo chmod -R +rwx /cores/* # Enable access to core dumps
- run: ulimit -c # should output 0 if disabled
- run: ulimit -c unlimited
- run: ulimit -c # should output 'unlimited' now
- run: sudo touch /cores/test
- run: ls /cores
- run: sudo rm /cores/test
- uses: actions/upload-artifact@master # capture all crashes as build artifacts
if: steps.bridge_test.outcome != 'success'
with:
name: crashes
path: /cores

webf_unit_test:
runs-on: ubuntu-latest
Expand Down
12 changes: 11 additions & 1 deletion bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()

if (ENABLE_ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -O1)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_link_options(-fsanitize=address -fno-omit-frame-pointer)
endif ()

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# Avoid quickjs stackoverflow.
add_compile_options(-O1)
endif()

if (DEFINED PLATFORM)
if (${PLATFORM} STREQUAL "OS")
add_compile_options(-fno-aligned-allocation)
Expand Down Expand Up @@ -194,6 +199,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
core/executing_context.cc
core/script_state.cc
core/page.cc
core/dart_methods.cc
core/executing_context_data.cc
core/fileapi/blob.cc
core/fileapi/blob_part.cc
Expand Down Expand Up @@ -270,6 +276,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
core/html/html_anchor_element.cc
core/html/html_image_element.cc
core/html/html_script_element.cc
core/html/html_link_element.cc
core/html/html_unknown_element.cc
core/html/image.cc
core/html/canvas/html_canvas_element.cc
Expand Down Expand Up @@ -362,6 +369,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
out/qjs_html_html_element.cc
out/qjs_html_image_element.cc
out/qjs_html_canvas_element.cc
out/qjs_html_link_element.cc
out/qjs_image.cc
out/qjs_widget_element.cc
out/qjs_canvas_rendering_context_2d.cc
Expand All @@ -386,6 +394,8 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
out/html_element_factory.cc
out/html_names.cc
out/script_type_names.cc
out/defined_properties.cc
out/defined_properties_initializer.cc
out/element_attribute_names.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 @@ -37,6 +37,7 @@
#include "qjs_html_html_element.h"
#include "qjs_html_image_element.h"
#include "qjs_html_input_element.h"
#include "qjs_html_link_element.h"
#include "qjs_html_script_element.h"
#include "qjs_html_template_element.h"
#include "qjs_html_textarea_element.h"
Expand Down Expand Up @@ -119,6 +120,7 @@ void InstallBindings(ExecutingContext* context) {
QJSHTMLButtonElement::Install(context);
QJSImage::Install(context);
QJSHTMLScriptElement::Install(context);
QJSHTMLLinkElement::Install(context);
QJSHTMLUnknownElement::Install(context);
QJSHTMLTemplateElement::Install(context);
QJSHTMLCanvasElement::Install(context);
Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/cppgc/mutation_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "mutation_scope.h"
#include "bindings/qjs/script_wrappable.h"
#include "core/executing_context.h"

namespace webf {
Expand Down
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/js_based_event_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void JSBasedEventListener::Invoke(ExecutingContext* context, Event* event, Excep
assert(context);
assert(event);

if (!context->IsValid())
if (!context->IsContextValid())
return;
// Step 10: Call a listener with event's currentTarget as receiver and event
// and handle errors if thrown.
Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/js_based_event_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <quickjs/quickjs.h>
#include "core/dom/events/event_listener.h"
#include "core/executing_context.h"
#include "foundation/casting.h"

namespace webf {

Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/rejected_promises.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include "rejected_promises.h"
#include "bindings/qjs/cppgc/mutation_scope.h"
#include "core/executing_context.h"

namespace webf {
Expand Down
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/script_promise_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ScriptPromiseResolver {
}

void ResolveOrReject(JSValue value, ResolutionState new_state) {
if (state_ != kPending || !context_->IsValid() || !context_)
if (state_ != kPending || !context_->IsContextValid() || !context_)
return;
assert(new_state == kResolving || new_state == kRejecting);
state_ = new_state;
Expand Down
6 changes: 3 additions & 3 deletions bridge/bindings/qjs/script_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ AtomicString ScriptValue::ToString() const {
return {ctx_, value_};
}

NativeValue ScriptValue::ToNative() const {
NativeValue ScriptValue::ToNative(ExceptionState& exception_state) const {
int8_t tag = JS_VALUE_GET_TAG(value_);

switch (tag) {
Expand Down Expand Up @@ -175,15 +175,15 @@ NativeValue ScriptValue::ToNative() const {
Converter<IDLSequence<IDLAny>>::FromValue(ctx_, value_, ASSERT_NO_EXCEPTION());
auto* result = new NativeValue[values.size()];
for (int i = 0; i < values.size(); i++) {
result[i] = values[i].ToNative();
result[i] = values[i].ToNative(exception_state);
}
return Native_NewList(values.size(), result);
} else if (JS_IsObject(value_)) {
if (QJSEventTarget::HasInstance(ExecutingContext::From(ctx_), value_)) {
auto* event_target = toScriptWrappable<EventTarget>(value_);
return Native_NewPtr(JSPointerType::Others, event_target->bindingObject());
}
return NativeValueConverter<NativeTypeJSON>::ToNativeValue(*this);
return NativeValueConverter<NativeTypeJSON>::ToNativeValue(*this, exception_state);
}
}
default:
Expand Down
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/script_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ScriptValue final {
// Create a new ScriptValue from call JSON.stringify to current value.
ScriptValue ToJSONStringify(ExceptionState* exception) const;
AtomicString ToString() const;
NativeValue ToNative() const;
NativeValue ToNative(ExceptionState& exception_state) const;

bool IsException() const;
bool IsEmpty() const;
Expand Down
39 changes: 39 additions & 0 deletions bridge/bindings/qjs/script_wrappable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ static int HandleJSPropertySetterCallback(JSContext* ctx,
auto* object = static_cast<ScriptWrappable*>(JS_GetOpaque(obj, JSValueGetClassId(obj)));
auto* wrapper_type_info = object->GetWrapperTypeInfo();

ExecutingContext* context = ExecutingContext::From(ctx);
JSValue prototypeObject = context->contextData()->prototypeForType(wrapper_type_info);
if (JS_HasProperty(ctx, prototypeObject, atom)) {
JSValue target = JS_DupValue(ctx, prototypeObject);
JSValue setterFunc = JS_UNDEFINED;
while (JS_IsUndefined(setterFunc)) {
JSPropertyDescriptor descriptor;
descriptor.setter = JS_UNDEFINED;
descriptor.getter = JS_UNDEFINED;
descriptor.value = JS_UNDEFINED;
JS_GetOwnProperty(ctx, &descriptor, target, atom);
setterFunc = descriptor.setter;
if (JS_IsFunction(ctx, setterFunc)) {
JS_FreeValue(ctx, descriptor.getter);
break;
}

JSValue new_target = JS_GetPrototype(ctx, target);
JS_FreeValue(ctx, target);
target = new_target;
JS_FreeValue(ctx, descriptor.getter);
JS_FreeValue(ctx, descriptor.setter);
}

assert_m(JS_IsFunction(ctx, setterFunc), "Setter on prototype should be an function.");
JSValue ret = JS_Call(ctx, setterFunc, obj, 1, &value);
if (JS_IsException(ret))
return -1;

JS_FreeValue(ctx, ret);
JS_FreeValue(ctx, setterFunc);
JS_FreeValue(ctx, target);
return 0;
}

if (wrapper_type_info->indexed_property_setter_handler_ != nullptr && JS_AtomIsTaggedInt(atom)) {
return wrapper_type_info->indexed_property_setter_handler_(ctx, obj, JS_AtomToUInt32(atom), value);
} else if (wrapper_type_info->string_property_setter_handler_ != nullptr) {
Expand Down Expand Up @@ -165,6 +200,8 @@ void ScriptWrappable::InitializeQuickJSObject() {
if (!JS_IsNull(return_value)) {
desc->flags = JS_PROP_ENUMERABLE;
desc->value = return_value;
desc->getter = JS_NULL;
desc->setter = JS_NULL;
return true;
}
}
Expand All @@ -175,6 +212,8 @@ void ScriptWrappable::InitializeQuickJSObject() {
if (!JS_IsNull(return_value)) {
desc->flags = JS_PROP_ENUMERABLE;
desc->value = return_value;
desc->getter = JS_NULL;
desc->setter = JS_NULL;
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/script_wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <quickjs/quickjs.h>
#include "bindings/qjs/cppgc/garbage_collected.h"
#include "core/executing_context.h"
#include "foundation/macros.h"
#include "wrapper_type_info.h"

Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/wrapper_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum {
JS_CLASS_HTML_IMAGE_ELEMENT,
JS_CLASS_HTML_SCRIPT_ELEMENT,
JS_CLASS_HTML_ANCHOR_ELEMENT,
JS_CLASS_HTML_LINK_ELEMENT,
JS_CLASS_HTML_CANVAS_ELEMENT,
JS_CLASS_IMAGE,
JS_CLASS_CANVAS_RENDERING_CONTEXT,
Expand Down
4 changes: 3 additions & 1 deletion bridge/core/binding_call_methods.json5
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
"getElementsByName",
"getElementsByTagName",
"id",
"className"
"className",
"cookie",
"class"
]
}
35 changes: 25 additions & 10 deletions bridge/core/binding_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ void NativeBindingObject::HandleCallFromDartSide(NativeBindingObject* binding_ob

BindingObject::BindingObject(ExecutingContext* context) : context_(context) {}
BindingObject::~BindingObject() {
delete binding_object_;
// Set below properties to nullptr to avoid dart callback to native.
binding_object_->disposed_ = true;
binding_object_->binding_target_ = nullptr;
binding_object_->invoke_binding_methods_from_dart = nullptr;
binding_object_->invoke_bindings_methods_from_native = nullptr;
}

BindingObject::BindingObject(ExecutingContext* context, NativeBindingObject* native_binding_object)
Expand Down Expand Up @@ -101,20 +105,24 @@ ScriptValue BindingObject::AnonymousFunctionCallback(JSContext* ctx,

std::vector<NativeValue> arguments;
arguments.reserve(argc + 1);

arguments.emplace_back(NativeValueConverter<NativeTypeInt64>::ToNativeValue(id));

ExceptionState exception_state;

for (int i = 0; i < argc; i++) {
arguments.emplace_back(argv[i].ToNative());
arguments.emplace_back(argv[i].ToNative(exception_state));
}

if (exception_state.HasException()) {
event_target->GetExecutingContext()->HandleException(exception_state);
return ScriptValue::Empty(ctx);
}

ExceptionState exception_state;
NativeValue result = event_target->InvokeBindingMethod(BindingMethodCallOperations::kAnonymousFunctionCall,
arguments.size(), arguments.data(), exception_state);

if (exception_state.HasException()) {
JSValue error = JS_GetException(ctx);
event_target->GetExecutingContext()->ReportError(error);
JS_FreeValue(ctx, error);
event_target->GetExecutingContext()->HandleException(exception_state);
return ScriptValue::Empty(ctx);
}
return ScriptValue(ctx, result);
Expand All @@ -125,7 +133,7 @@ void BindingObject::HandleAnonymousAsyncCalledFromDart(void* ptr,
int32_t contextId,
const char* errmsg) {
auto* promise_context = static_cast<BindingObjectPromiseContext*>(ptr);
if (!promise_context->context->IsValid())
if (!promise_context->context->IsContextValid())
return;
if (promise_context->context->contextId() != contextId)
return;
Expand Down Expand Up @@ -173,13 +181,20 @@ ScriptValue BindingObject::AnonymousAsyncFunctionCallback(JSContext* ctx,
arguments.emplace_back(NativeValueConverter<NativeTypePointer<void>>::ToNativeValue(
reinterpret_cast<void*>(HandleAnonymousAsyncCalledFromDart)));

ExceptionState exception_state;

for (int i = 0; i < argc; i++) {
arguments.emplace_back(argv[i].ToNative());
arguments.emplace_back(argv[i].ToNative(exception_state));
}

ExceptionState exception_state;
event_target->InvokeBindingMethod(BindingMethodCallOperations::kAsyncAnonymousFunction, argc + 4, arguments.data(),
exception_state);

if (exception_state.HasException()) {
event_target->GetExecutingContext()->HandleException(exception_state);
return ScriptValue::Empty(ctx);
}

return promise_resolver->Promise().ToValue();
}

Expand Down
1 change: 1 addition & 0 deletions bridge/core/binding_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct NativeBindingObject : public DartReadable {
int32_t argc,
NativeValue* argv);

bool disposed_{false};
BindingObject* binding_target_{nullptr};
InvokeBindingMethodsFromDart invoke_binding_methods_from_dart{nullptr};
InvokeBindingsMethodsFromNative invoke_bindings_methods_from_native{nullptr};
Expand Down
Loading