Truly independent web browser
WebContent: Keep minimal object summaries in console history
sideshowbarker05aed8230186
diff --git a/Services/WebContent/DevToolsConsoleClient.cpp b/Services/WebContent/DevToolsConsoleClient.cppindex a637386908c..d3632f8aa90 100644--- a/Services/WebContent/DevToolsConsoleClient.cpp+++ b/Services/WebContent/DevToolsConsoleClient.cpp@@ -257,13 +257,13 @@ JS::ThrowCompletionOr<JS::Value> DevToolsConsoleClient::printer(JS::Console::Logauto const& argument_values = arguments.get<GC::RootVector<JS::Value>>();- Vector<JsonValue> printed_arguments;+ Vector<JsonValue> buffered_arguments;Utf16StringBuilder output_builder;auto argument_count = min(argument_values.size(), 100uz);for (size_t index = 0; index < argument_count; ++index) {if (output_builder.length_in_code_units() >= 8192) {output_builder.append_ascii(" ..."sv);- printed_arguments.append("..."_string);+ buffered_arguments.append("..."_string);break;}auto value = argument_values[index];@@ -274,10 +274,13 @@ JS::ThrowCompletionOr<JS::Value> DevToolsConsoleClient::printer(JS::Console::Logauto utf16_text = Utf16String::from_utf8(text);auto remaining = 8192 - output_builder.length_in_code_units();output_builder.append(utf16_text.utf16_view().substring_view(0, min(utf16_text.length_in_code_units(), remaining)));- printed_arguments.append(move(serialized));+ if (value.is_object() && !Web::Bindings::impl_from<Web::DOM::Element>(&value.as_object()))+ buffered_arguments.append(MUST(String::from_utf8(value.as_object().class_name())));+ else+ buffered_arguments.append(move(serialized));if (utf16_text.length_in_code_units() > remaining || (index + 1 == argument_count && argument_count < argument_values.size())) {output_builder.append_ascii(" ..."sv);- printed_arguments.append("..."_string);+ buffered_arguments.append("..."_string);break;}}@@ -301,12 +304,8 @@ JS::ThrowCompletionOr<JS::Value> DevToolsConsoleClient::printer(JS::Console::Log// The console hands a table over as the one object that holds its rows and columns.auto is_table = log_level == JS::Console::LogLevel::Table && !argument_values.is_empty() && argument_values.first().is_object();- // The buffer keeps the arguments printed, so it keeps no objects alive, and a table as its text.- if (is_table) {- printed_arguments.clear();- printed_arguments.append(output.to_utf8());- }- m_client->buffer_console_output(console_log(is_table ? JS::Console::LogLevel::Log : log_level, printed_arguments));+ // The history keeps primitive values and object summaries, without retaining objects or their properties.+ m_client->buffer_console_output(console_log(is_table ? JS::Console::LogLevel::Log : log_level, buffered_arguments));// A DevTools client that takes the messages gets grips for the objects instead, which it may expand.if (!m_client->devtools_takes_console_messages())diff --git a/Tests/LibWebView/test-console-previews.py b/Tests/LibWebView/test-console-previews.pyindex 6a3b931c212..9861a37a59b 100755--- a/Tests/LibWebView/test-console-previews.py+++ b/Tests/LibWebView/test-console-previews.py@@ -94,6 +94,10 @@ def main():client.evaluate("""(() => {const cycle = {}; cycle.self = cycle;console.log('cycle', cycle);+ console.log('primitive values', undefined, null, true, false, 42, -0, NaN, Infinity, -Infinity, 'text', 42n);+ console.log('buffered contents', { marker: 'terminal-property-value' });+ console.log('table begins');+ console.table([{ marker: 'table-property-value' }]);console.log('large string', 'x'.repeat(1000000));console.log('large array', Array(100000).fill('x'.repeat(1000)));console.log('sparse array', new Array(0xffffffff));@@ -137,8 +141,34 @@ def main():assert isinstance(preview, str) and len(preview) < 16384, (label, type(preview))assert preview, label- assert "Getter" in message_arguments("before watching")[1]- assert "inherited" not in message_arguments("before watching")[1]+ for label, summary in {+ "before watching": "Object",+ "cycle": "Object",+ "buffered contents": "Object",+ "large array": "Array",+ "sparse array": "Array",+ "array getter": "Array",+ "large map": "Map",+ "large set": "Set",+ "deep object": "Object",+ "proxy": "ProxyObject",+ }.items():+ assert message_arguments(label)[1] == summary, (label, message_arguments(label))+ assert message_arguments("primitive values")[1:] == [+ {"type": "undefined"},+ {"type": "null"},+ True,+ False,+ 42,+ {"type": "-0"},+ {"type": "NaN"},+ {"type": "Infinity"},+ {"type": "-Infinity"},+ "text",+ {"type": "BigInt", "text": "42"},+ ]+ table_start = next(i for i, message in enumerate(messages) if message["arguments"] == ["table begins"])+ assert messages[table_start + 1]["arguments"] == ["Object"], messages[table_start + 1]assert message_arguments("buffered DOM")[1] == '<dfn id="definition">'assert len(message_arguments("large bigint")[1]["text"]) < 16384assert sum(len(value) for value in message_arguments("many arguments")) < 16384