Jonathan Kelley 1 год назад
Родитель
Сommit
23f7a37b06
3 измененных файлов с 16 добавлено и 53 удалено
  1. 3 3
      packages/core/tests/fuzzing.rs
  2. 12 49
      packages/native-core/tests/fuzzing.rs
  3. 1 1
      packages/rsx/src/lib.rs

+ 3 - 3
packages/core/tests/fuzzing.rs

@@ -2,7 +2,7 @@
 
 use dioxus::prelude::Props;
 use dioxus_core::{MountedAttribute, *};
-use std::{cfg, collections::HashSet};
+use std::{cell::Cell, cfg, collections::HashSet};
 
 fn random_ns() -> Option<&'static str> {
     let namespace = rand::random::<u8>() % 2;
@@ -177,7 +177,7 @@ fn create_random_dynamic_node(cx: &ScopeState, depth: usize) -> DynamicNode {
             //                 Template {
             // =======
             cx.vnode(
-                None,
+                None.into(),
                 Default::default(),
                 Cell::new(Template {
                     // >>>>>>> 9fe172e9 (Fix leak in render macro)
@@ -293,7 +293,7 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
             // =======
             // println!("{template:#?}");
             let node = cx.vnode(
-                None,
+                None.into(),
                 None,
                 Cell::new(template),
                 bumpalo::collections::Vec::new_in(cx.bump()).into(),

+ 12 - 49
packages/native-core/tests/fuzzing.rs

@@ -1,3 +1,5 @@
+use std::cell::Cell;
+
 use dioxus::prelude::Props;
 use dioxus_core::*;
 use dioxus_native_core::prelude::*;
@@ -178,27 +180,16 @@ fn create_random_dynamic_node(cx: &ScopeState, depth: usize) -> DynamicNode {
     match rand::random::<u8>() % range {
         0 => DynamicNode::Placeholder(Default::default()),
         1 => cx.make_node((0..(rand::random::<u8>() % 5)).map(|_| {
-            // <<<<<<< HEAD
-            //             VNode::new(
-            //                 None,
-            //                 Template {
-            // =======
             cx.vnode(
-                None,
+                None.into(),
                 Default::default(),
                 Cell::new(Template {
-                    // >>>>>>> 9fe172e9 (Fix leak in render macro)
                     name: concat!(file!(), ":", line!(), ":", column!(), ":0"),
                     roots: &[TemplateNode::Dynamic { id: 0 }],
                     node_paths: &[&[0]],
                     attr_paths: &[],
-                    // <<<<<<< HEAD
-                    //                 },
-                    //                 dioxus::core::exports::bumpalo::collections::Vec::new_in(cx.bump()),
-                    // =======
                 }),
                 dioxus::core::exports::bumpalo::collections::Vec::new_in(cx.bump()).into(),
-                // >>>>>>> 9fe172e9 (Fix leak in render macro)
                 cx.bump().alloc([cx.component(
                     create_random_element,
                     DepthProps { depth, root: false },
@@ -216,20 +207,6 @@ fn create_random_dynamic_node(cx: &ScopeState, depth: usize) -> DynamicNode {
     }
 }
 
-fn create_random_dynamic_mounted_attr(cx: &ScopeState) -> MountedAttribute {
-    match rand::random::<u8>() % 2 {
-        0 => MountedAttribute::from(
-            &*cx.bump().alloc(
-                (0..(rand::random::<u8>() % 3) as usize)
-                    .map(|_| create_random_dynamic_attr(cx))
-                    .collect::<Vec<_>>(),
-            ),
-        ),
-        1 => MountedAttribute::from(create_random_dynamic_attr(cx)),
-        _ => unreachable!(),
-    }
-}
-
 fn create_random_dynamic_attr(cx: &ScopeState) -> Attribute {
     let value = match rand::random::<u8>() % 6 {
         0 => AttributeValue::Text(Box::leak(
@@ -242,6 +219,7 @@ fn create_random_dynamic_attr(cx: &ScopeState) -> Attribute {
         5 => AttributeValue::None,
         _ => unreachable!(),
     };
+
     Attribute::new(
         Box::leak(format!("attr{}", rand::random::<usize>()).into_boxed_str()),
         value,
@@ -278,18 +256,11 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
                 .into_boxed_str(),
             ));
             println!("{template:#?}");
-            // <<<<<<< HEAD
-            //             let node = VNode::new(
-            //                 None,
-            //                 template,
-            //                 dioxus::core::exports::bumpalo::collections::Vec::new_in(cx.bump()),
-            // =======
             let node = cx.vnode(
-                None,
+                None.into(),
                 None,
                 Cell::new(template),
                 dioxus::core::exports::bumpalo::collections::Vec::new_in(cx.bump()).into(),
-                // >>>>>>> 9fe172e9 (Fix leak in render macro)
                 {
                     let dynamic_nodes: Vec<_> = dynamic_node_types
                         .iter()
@@ -304,21 +275,13 @@ fn create_random_element(cx: Scope<DepthProps>) -> Element {
                         .collect();
                     cx.bump().alloc(dynamic_nodes)
                 },
-                // <<<<<<< HEAD
-                //                 cx.bump()
-                //                     .alloc(
-                //                         (0..template.attr_paths.len())
-                //                             .map(|_| create_random_dynamic_mounted_attr(cx))
-                //                             .collect::<Vec<_>>(),
-                //                     )
-                //                     .as_slice(),
-                // =======
-                cx.bump().alloc(
-                    (0..template.attr_paths.len())
-                        .map(|_| create_random_dynamic_attr(cx))
-                        .collect::<Vec<_>>(),
-                ),
-                // >>>>>>> 9fe172e9 (Fix leak in render macro)
+                cx.bump()
+                    .alloc(
+                        (0..template.attr_paths.len())
+                            .map(|_| create_random_dynamic_attr(cx).into())
+                            .collect::<Vec<_>>(),
+                    )
+                    .as_slice(),
             );
             Some(node)
         }

+ 1 - 1
packages/rsx/src/lib.rs

@@ -261,7 +261,7 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
 //                 dioxus::core::exports::bumpalo::collections::Vec::with_capacity_in(#root_count, __cx.bump()),
 // =======
             __cx.vnode(
-                None,
+                None.into(),
                 #key_tokens,
                 std::cell::Cell::new(TEMPLATE),
                 dioxus::core::exports::bumpalo::collections::Vec::with_capacity_in(#root_count, __cx.bump()).into(),