mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibJS: Do not print large arrays
Printing the whole array causes wpt console/console-log-large-array.any.html to crash. This limits logged arrays to 100 elements and truncates the rest with ...
This commit is contained in:
parent
567a6cc02d
commit
9650cf8b15
|
|
@ -165,6 +165,7 @@ ErrorOr<void> print_array(JS::PrintContext& print_context, JS::Array const& arra
|
|||
{
|
||||
TRY(js_out(print_context, "["));
|
||||
bool first = true;
|
||||
size_t printed_count = 0;
|
||||
for (auto it = array.indexed_properties().begin(false); it != array.indexed_properties().end(); ++it) {
|
||||
TRY(print_separator(print_context, first));
|
||||
auto value_or_error = array.get(it.index());
|
||||
|
|
@ -175,6 +176,10 @@ ErrorOr<void> print_array(JS::PrintContext& print_context, JS::Array const& arra
|
|||
return {};
|
||||
auto value = value_or_error.release_value();
|
||||
TRY(print_value(print_context, value, seen_objects));
|
||||
if (++printed_count > 100 && it != array.indexed_properties().end()) {
|
||||
TRY(js_out(print_context, ", ..."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!first)
|
||||
TRY(js_out(print_context, " "));
|
||||
|
|
@ -472,10 +477,15 @@ ErrorOr<void> print_typed_array(JS::PrintContext& print_context, JS::TypedArrayB
|
|||
TRY(js_out(print_context, "[ ")); \
|
||||
auto& typed_array = static_cast<JS::ClassName const&>(typed_array_base); \
|
||||
auto data = typed_array.data(); \
|
||||
size_t printed_count = 0; \
|
||||
for (size_t i = 0; i < length; ++i) { \
|
||||
if (i > 0) \
|
||||
TRY(js_out(print_context, ", ")); \
|
||||
TRY(print_number(print_context, data[i])); \
|
||||
if (++printed_count > 100 && i < length) { \
|
||||
TRY(js_out(print_context, ", ...")); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
TRY(js_out(print_context, " ]")); \
|
||||
return {}; \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user