Browse Source

LibJS: Fix redundancy-detection when printing raw values

Note that this does not change cycle-detection.

This is also was an unnecessary copy, since there is an easier, less
memory-intense way to do cycle detection than copying the entire
visited_set all the time.
Ben Wiederhake 2 years ago
parent
commit
a9b3aaa887

+ 3 - 2
Userland/Libraries/LibJS/MarkupGenerator.cpp

@@ -32,7 +32,8 @@ ErrorOr<String> MarkupGenerator::html_from_source(StringView source)
 ErrorOr<String> MarkupGenerator::html_from_value(Value value)
 {
     StringBuilder output_html;
-    TRY(value_to_html(value, output_html));
+    HashTable<Object*> seen_objects;
+    TRY(value_to_html(value, output_html, seen_objects));
     return output_html.to_string();
 }
 
@@ -43,7 +44,7 @@ ErrorOr<String> MarkupGenerator::html_from_error(Error const& object, bool in_pr
     return output_html.to_string();
 }
 
-ErrorOr<void> MarkupGenerator::value_to_html(Value value, StringBuilder& output_html, HashTable<Object*> seen_objects)
+ErrorOr<void> MarkupGenerator::value_to_html(Value value, StringBuilder& output_html, HashTable<Object*>& seen_objects)
 {
     if (value.is_empty()) {
         TRY(output_html.try_append("&lt;empty&gt;"sv));

+ 1 - 1
Userland/Libraries/LibJS/MarkupGenerator.h

@@ -33,7 +33,7 @@ private:
         ObjectType,
     };
 
-    static ErrorOr<void> value_to_html(Value, StringBuilder& output_html, HashTable<Object*> seen_objects = {});
+    static ErrorOr<void> value_to_html(Value, StringBuilder& output_html, HashTable<Object*>& seen_objects);
     static ErrorOr<void> array_to_html(Array const&, StringBuilder& output_html, HashTable<Object*>&);
     static ErrorOr<void> object_to_html(Object const&, StringBuilder& output_html, HashTable<Object*>&);
     static ErrorOr<void> function_to_html(Object const&, StringBuilder& output_html, HashTable<Object*>&);