Skip to content

Commit

Permalink
fix: fix parse HTML.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed May 17, 2022
1 parent 5ff9df6 commit 65d6f89
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
8 changes: 3 additions & 5 deletions bridge/bindings/qjs/cppgc/member.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ class Member {
return;
auto* wrappable = To<ScriptWrappable>(raw_);
// Record the free operation to avoid JSObject had been freed immediately.
if (LIKELY(wrappable->GetExecutingContext()->HasMutationScope())) {
wrappable->GetExecutingContext()->mutationScope()->RecordFree(wrappable);
} else {
JS_FreeValue(wrappable->ctx(), wrappable->ToQuickJSUnsafe());
}
wrappable->GetExecutingContext()->mutationScope()->RecordFree(wrappable);
raw_ = nullptr;
}

Expand Down Expand Up @@ -86,6 +82,8 @@ class Member {
void SetRaw(T* p) {
if (p != nullptr) {
auto* wrappable = To<ScriptWrappable>(p);
assert_m(wrappable->GetExecutingContext()->HasMutationScope(),
"Member must be used after MemberMutationScope allcated.");
runtime_ = wrappable->runtime();
JS_DupValue(wrappable->ctx(), wrappable->ToQuickJSUnsafe());
}
Expand Down
2 changes: 1 addition & 1 deletion bridge/bindings/qjs/script_wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Local<T>::~Local<T>() {
if (LIKELY(wrappable->GetExecutingContext()->HasMutationScope())) {
wrappable->GetExecutingContext()->mutationScope()->RecordFree(wrappable);
} else {
assert_m(false, "LocalHandle must be used before MemberMutationScope allcated.");
assert_m(false, "LocalHandle must be used after MemberMutationScope allcated.");
}
}

Expand Down
1 change: 1 addition & 0 deletions bridge/core/dom/node_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TEST(Node, childNodes) {
};
auto bridge = TEST_init([](int32_t contextId, const char* errmsg) { errorCalled = true; });
auto context = bridge->GetExecutingContext();
MemberMutationScope scope{context};
const char* code =
"let div1 = document.createElement('div');"
"let div2 = document.createElement('div');"
Expand Down
2 changes: 2 additions & 0 deletions bridge/core/page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ bool KrakenPage::parseHTML(const char* code, size_t length) {
if (!context_->IsValid())
return false;

MemberMutationScope scope{context_};

// Remove all Nodes including body and head.
context_->document()->documentElement()->RemoveChildren();

Expand Down
2 changes: 1 addition & 1 deletion kraken/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class _MyHomePageState extends State<MyBrowser> {
devToolsService: ChromeDevToolsService(),
viewportWidth: viewportSize.width - queryData.padding.horizontal,
viewportHeight: viewportSize.height - appBar.preferredSize.height - queryData.padding.vertical,
bundle: KrakenBundle.fromUrl('assets:assets/bundle.js'),
bundle: KrakenBundle.fromUrl('assets:assets/bundle.html'),
),
));
}
Expand Down

0 comments on commit 65d6f89

Please sign in to comment.