Skip to content

Commit 330fa19

Browse files
committed
Expose item on child collections
1 parent a29ad3d commit 330fa19

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_properties.inc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@
398398
for (uint32_t index = 0; index < children.size(); ++index) {
399399
result->Set(local_context, index, self->wrap_node(*children[index])).Check();
400400
}
401+
result->Set(
402+
local_context,
403+
js_string(info.GetIsolate(), "item"),
404+
v8::Function::New(local_context, collection_item).ToLocalChecked()).Check();
401405
info.GetReturnValue().Set(result);
402406
}
403407

‎experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_browser_dom_tests.inc‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,37 @@ void test_specialized_content_properties(webscene_engine* engine)
207207
"specialized meta/template content properties diverged: " + result);
208208
}
209209

210+
void test_child_collection_item(webscene_engine* engine)
211+
{
212+
const auto result = evaluate(engine, R"JS(
213+
(() => {
214+
const host = document.createElement('div');
215+
host.append('leading text');
216+
const first = document.createElement('span');
217+
const second = document.createElement('button');
218+
host.append(first, second);
219+
return {
220+
children: [
221+
typeof host.children.item,
222+
host.children.item(0) === first,
223+
host.children.item(1) === second,
224+
host.children.item(2)
225+
],
226+
childNodes: [
227+
typeof host.childNodes.item,
228+
host.childNodes.item(0).nodeType,
229+
host.childNodes.item(1) === first,
230+
host.childNodes.item(9)
231+
]
232+
};
233+
})()
234+
)JS", "native-child-collection-item.js");
235+
const auto expected = R"JSON({"children":["function",true,true,null],"childNodes":["function",3,true,null]})JSON";
236+
require(
237+
result == expected,
238+
"child collection item lookup diverged: " + result);
239+
}
240+
210241
void test_textarea_child_text_value_lifecycle(webscene_engine* engine)
211242
{
212243
const auto result = evaluate(engine, R"JS(

‎experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_tests.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ int main()
515515
require(focused_engine != nullptr, "focused engine creation failed");
516516
test_dom_traversal_cloning_primitives(focused_engine);
517517
test_specialized_content_properties(focused_engine);
518+
test_child_collection_item(focused_engine);
518519
webscene_engine_destroy(focused_engine);
519520
return 0;
520521
}
@@ -809,6 +810,7 @@ int main()
809810
test_dom_box_dimensions_primitives(engine);
810811
test_dom_traversal_cloning_primitives(engine);
811812
test_specialized_content_properties(engine);
813+
test_child_collection_item(engine);
812814
test_fragment_replacement_and_inline_script_lifecycle(engine);
813815
test_textarea_child_text_value_lifecycle(engine);
814816
test_secondary_click(engine);

0 commit comments

Comments
 (0)