Skip to content

Commit 2505d12

Browse files
ShouruiSongjianliang00
authored andcommitted
[BugFix][ElementTemplate] Notify DevTool typed page root
- Notify DevTool with the materialized typed page root when creating a typed page ElementTemplate, so the existing page-root path initializes element_root_. - Keep InspectorTasmExecutor root handling limited to page nodes instead of deriving roots from arbitrary child insertion events. - Add unit coverage that typed page ElementTemplate creation reports the materialized page root to the inspector observer. TEST: tools/env.sh clang-format --dry-run --Werror lynx/core/runtime/lepus/bindings/renderer_functions.cc lynx/core/renderer/dom/fiber/fiber_element_unittest.cc lynx/devtool/lynx_devtool/agent/inspector_tasm_executor.cc lynx/devtool/lynx_devtool/agent/inspector_tasm_executor.h lynx/devtool/lynx_devtool/agent/inspector_tasm_executor_unittest.cc TEST: git diff --check -- lynx/core/runtime/lepus/bindings/renderer_functions.cc lynx/core/renderer/dom/fiber/fiber_element_unittest.cc lynx/devtool/lynx_devtool/agent/inspector_tasm_executor.cc lynx/devtool/lynx_devtool/agent/inspector_tasm_executor.h lynx/devtool/lynx_devtool/agent/inspector_tasm_executor_unittest.cc TEST: tools/env.sh python3 tools_shared/git_lynx.py check --checkers cpp-header-path --changed TEST: tools/env.sh lynx/tools/rtf/rtf native-ut run --name lynx --target dom_unittest_exec TEST: tools/env.sh lynx/tools/rtf/rtf native-ut run --name lynx --target devtool_agent_unittest_exec AutoSubmit:True
1 parent f334b7f commit 2505d12

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

core/renderer/dom/fiber/fiber_element_unittest.cc

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
#include "core/renderer/dom/fiber/fiber_element.h"
99

1010
#include <cmath>
11+
#include <functional>
12+
#include <map>
1113
#include <memory>
1214
#include <mutex>
1315
#include <tuple>
16+
#include <vector>
1417

1518
#include "base/include/auto_reset.h"
1619
#include "core/animation/css_transition_manager.h"
@@ -103,6 +106,39 @@ bool LayoutBundleHasStyle(const std::unique_ptr<LayoutBundle>& layout_bundle,
103106
return false;
104107
}
105108

109+
class RecordingInspectorElementObserver final
110+
: public InspectorElementObserver {
111+
public:
112+
void OnDocumentUpdated() override {}
113+
void OnElementNodeAdded(Element* ptr) override { added_nodes.push_back(ptr); }
114+
void OnElementNodeRemoved(Element* ptr) override {}
115+
void OnCharacterDataModified(Element* ptr) override {}
116+
void OnElementDataModelSet(Element* ptr) override {}
117+
void OnElementManagerWillDestroy() override {}
118+
void OnCSSStyleSheetAdded(Element* ptr) override {}
119+
void OnComponentUselessUpdate(const std::string& component_name,
120+
const lepus::Value& properties) override {}
121+
void OnSetNativeProps(Element* ptr, const std::string& name,
122+
const std::string& value, bool is_style) override {}
123+
124+
std::map<lynx::devtool::DevToolFunction,
125+
std::function<void(const base::any&)>>
126+
GetDevToolFunction() override {
127+
auto noop = [](const base::any&) {};
128+
return {
129+
{lynx::devtool::DevToolFunction::InitForInspector, noop},
130+
{lynx::devtool::DevToolFunction::InitPlugForInspector, noop},
131+
{lynx::devtool::DevToolFunction::InitStyleValueElement, noop},
132+
{lynx::devtool::DevToolFunction::InitStyleRoot, noop},
133+
{lynx::devtool::DevToolFunction::SetDocElement, noop},
134+
{lynx::devtool::DevToolFunction::SetStyleValueElement, noop},
135+
{lynx::devtool::DevToolFunction::SetStyleRoot, noop},
136+
};
137+
}
138+
139+
std::vector<Element*> added_nodes;
140+
};
141+
106142
bool LayoutBundleHasResetStyle(
107143
const std::unique_ptr<LayoutBundle>& layout_bundle, CSSPropertyID id) {
108144
if (layout_bundle == nullptr) {
@@ -10207,6 +10243,38 @@ TEST_P(FiberElementTest, CreateTypedPageTemplateMaterializesRoot) {
1020710243
EXPECT_EQ(page_template->result_->children()[0].get(), child.get());
1020810244
}
1020910245

10246+
TEST_P(FiberElementTest, CreateTypedPageTemplateNotifiesInspectorRoot) {
10247+
auto observer = std::make_shared<RecordingInspectorElementObserver>();
10248+
manager->SetInspectorElementObserver(observer);
10249+
manager->dom_tree_enabled_ = true;
10250+
10251+
auto lepus_ctx = runtime::MTSRuntime::CreateContext(
10252+
runtime::ContextType::LepusNGContextType);
10253+
ASSERT_TRUE(lepus_ctx);
10254+
lepus_ctx->Initialize();
10255+
lepus_ctx->SetGlobalData(
10256+
BASE_STATIC_STRING(tasm::kTemplateAssembler),
10257+
lepus::Value(static_cast<runtime::MTSRuntime::Delegate*>(tasm.get())));
10258+
auto* mts_ctx = runtime::MTSRuntime::ToQuickContext(lepus_ctx.get());
10259+
ASSERT_TRUE(mts_ctx);
10260+
10261+
lepus::Value create_args[] = {lepus::Value("page"), lepus::Value(),
10262+
lepus::Value(), lepus::Value("0")};
10263+
auto created_value = RendererFunctions::FiberCreateTypedElementTemplate(
10264+
mts_ctx, create_args, 4);
10265+
10266+
ASSERT_TRUE(created_value.IsRefCounted());
10267+
auto page_template =
10268+
fml::static_ref_ptr_cast<TemplateElement>(created_value.RefCounted())
10269+
.strongify();
10270+
ASSERT_NE(page_template, nullptr);
10271+
ASSERT_NE(manager->root(), nullptr);
10272+
ASSERT_EQ(observer->added_nodes.size(), 1u);
10273+
EXPECT_EQ(observer->added_nodes[0], manager->root());
10274+
EXPECT_NE(observer->added_nodes[0], page_template.get());
10275+
EXPECT_TRUE(observer->added_nodes[0]->is_page());
10276+
}
10277+
1021010278
TEST_P(FiberElementTest, InsertTypedPageTemplateChildBeforeAutomaticFlush) {
1021110279
auto lepus_ctx = runtime::MTSRuntime::CreateContext(
1021210280
runtime::ContextType::LepusNGContextType);

core/runtime/lepus/bindings/renderer_functions.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3674,15 +3674,20 @@ RENDERER_FUNCTION_CC(FiberCreateTypedElementTemplate) {
36743674
element->SetElementSlots(element_slots);
36753675
element->SetOptions(options);
36763676
element->SetUid(*arg3);
3677+
fml::RefPtr<FiberElement> typed_page_root = nullptr;
36773678
if (arg0->String().IsEqual(kElementPageTag)) {
36783679
// Page templates are root templates, so materialize the root eagerly while
36793680
// still returning the TemplateElement shell for template APIs.
3680-
if (element->GetRoot() == nullptr) {
3681+
typed_page_root = element->GetRoot();
3682+
if (typed_page_root == nullptr) {
36813683
RETURN_UNDEFINED();
36823684
}
36833685
}
36843686

36853687
ON_NODE_CREATE(element);
3688+
if (typed_page_root != nullptr) {
3689+
ON_NODE_ADDED(typed_page_root);
3690+
}
36863691

36873692
RETURN(lepus::Value(element));
36883693
}

0 commit comments

Comments
 (0)