Commit b11cedb4 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

[inspector] restore console.table limits

`console.table` used to have a 1k limit on preview properties, which
regressed to 100 during refactoring.

This CL restores the 1k limit, and ensures that `buildEntryPreview`
does not use the 1k limit.

Bug: chromium:903623
Change-Id: I8fab3182a79d1bb6b662e2ff9b229db3d3a889ca
Reviewed-on: https://chromium-review.googlesource.com/c/1332127Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Erik Luo <luoe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57518}
parent fa306d43
...@@ -448,8 +448,8 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable( ...@@ -448,8 +448,8 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
auto mirror = ValueMirror::create(context, table); auto mirror = ValueMirror::create(context, table);
std::unique_ptr<ObjectPreview> preview; std::unique_ptr<ObjectPreview> preview;
int limit = 100; int limit = 1000;
mirror->buildObjectPreview(context, true /* generatePreviewForProperties */, mirror->buildObjectPreview(context, true /* generatePreviewForTable */,
&limit, &limit, &preview); &limit, &limit, &preview);
Array<PropertyPreview>* columns = preview->getProperties(); Array<PropertyPreview>* columns = preview->getProperties();
......
...@@ -277,7 +277,7 @@ String16 descriptionForEntry(v8::Local<v8::Context> context, ...@@ -277,7 +277,7 @@ String16 descriptionForEntry(v8::Local<v8::Context> context,
if (wrapper) { if (wrapper) {
std::unique_ptr<ObjectPreview> preview; std::unique_ptr<ObjectPreview> preview;
int limit = 5; int limit = 5;
wrapper->buildEntryPreview(context, false, &limit, &limit, &preview); wrapper->buildEntryPreview(context, &limit, &limit, &preview);
if (preview) { if (preview) {
key = preview->getDescription(String16()); key = preview->getDescription(String16());
if (preview->getType() == RemoteObject::TypeEnum::String) { if (preview->getType() == RemoteObject::TypeEnum::String) {
...@@ -294,7 +294,7 @@ String16 descriptionForEntry(v8::Local<v8::Context> context, ...@@ -294,7 +294,7 @@ String16 descriptionForEntry(v8::Local<v8::Context> context,
if (wrapper) { if (wrapper) {
std::unique_ptr<ObjectPreview> preview; std::unique_ptr<ObjectPreview> preview;
int limit = 5; int limit = 5;
wrapper->buildEntryPreview(context, false, &limit, &limit, &preview); wrapper->buildEntryPreview(context, &limit, &limit, &preview);
if (preview) { if (preview) {
value = preview->getDescription(String16()); value = preview->getDescription(String16());
if (preview->getType() == RemoteObject::TypeEnum::String) { if (preview->getType() == RemoteObject::TypeEnum::String) {
...@@ -337,8 +337,7 @@ class PrimitiveValueMirror final : public ValueMirror { ...@@ -337,8 +337,7 @@ class PrimitiveValueMirror final : public ValueMirror {
return Response::OK(); return Response::OK();
} }
void buildEntryPreview(v8::Local<v8::Context> context, void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit,
bool generatePreviewForProperties, int* nameLimit,
int* indexLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) override { std::unique_ptr<ObjectPreview>* preview) override {
*preview = *preview =
...@@ -401,8 +400,7 @@ class NumberMirror final : public ValueMirror { ...@@ -401,8 +400,7 @@ class NumberMirror final : public ValueMirror {
.setValue(description(&unserializable)) .setValue(description(&unserializable))
.build(); .build();
} }
void buildEntryPreview(v8::Local<v8::Context> context, void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit,
bool generatePreviewForProperties, int* nameLimit,
int* indexLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) override { std::unique_ptr<ObjectPreview>* preview) override {
bool unserializable = false; bool unserializable = false;
...@@ -457,8 +455,7 @@ class BigIntMirror final : public ValueMirror { ...@@ -457,8 +455,7 @@ class BigIntMirror final : public ValueMirror {
} }
void buildEntryPreview( void buildEntryPreview(
v8::Local<v8::Context> context, bool generatePreviewForProperties, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>* preview) override { std::unique_ptr<protocol::Runtime::ObjectPreview>* preview) override {
*preview = ObjectPreview::create() *preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Bigint) .setType(RemoteObject::TypeEnum::Bigint)
...@@ -611,8 +608,7 @@ class FunctionMirror final : public ValueMirror { ...@@ -611,8 +608,7 @@ class FunctionMirror final : public ValueMirror {
.setValue(String16()) .setValue(String16())
.build(); .build();
} }
void buildEntryPreview(v8::Local<v8::Context> context, void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit,
bool generatePreviewForProperties, int* nameLimit,
int* indexLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) override { std::unique_ptr<ObjectPreview>* preview) override {
*preview = ObjectPreview::create() *preview = ObjectPreview::create()
...@@ -845,20 +841,19 @@ class ObjectMirror final : public ValueMirror { ...@@ -845,20 +841,19 @@ class ObjectMirror final : public ValueMirror {
} }
void buildObjectPreview(v8::Local<v8::Context> context, void buildObjectPreview(v8::Local<v8::Context> context,
bool generatePreviewForProperties, int* nameLimit, bool generatePreviewForTable, int* nameLimit,
int* indexLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) override { std::unique_ptr<ObjectPreview>* result) override {
buildObjectPreviewInternal(context, false /* forEntry */, buildObjectPreviewInternal(context, false /* forEntry */,
generatePreviewForProperties, nameLimit, generatePreviewForTable, nameLimit, indexLimit,
indexLimit, result); result);
} }
void buildEntryPreview(v8::Local<v8::Context> context, void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit,
bool generatePreviewForProperties, int* nameLimit,
int* indexLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) override { std::unique_ptr<ObjectPreview>* result) override {
buildObjectPreviewInternal(context, true /* forEntry */, buildObjectPreviewInternal(context, true /* forEntry */,
generatePreviewForProperties, nameLimit, false /* generatePreviewForTable */, nameLimit,
indexLimit, result); indexLimit, result);
} }
...@@ -878,8 +873,8 @@ class ObjectMirror final : public ValueMirror { ...@@ -878,8 +873,8 @@ class ObjectMirror final : public ValueMirror {
private: private:
void buildObjectPreviewInternal(v8::Local<v8::Context> context, bool forEntry, void buildObjectPreviewInternal(v8::Local<v8::Context> context, bool forEntry,
bool generatePreviewForProperties, bool generatePreviewForTable, int* nameLimit,
int* nameLimit, int* indexLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) { std::unique_ptr<ObjectPreview>* result) {
std::unique_ptr<protocol::Array<PropertyPreview>> properties = std::unique_ptr<protocol::Array<PropertyPreview>> properties =
protocol::Array<PropertyPreview>::create(); protocol::Array<PropertyPreview>::create();
...@@ -911,9 +906,10 @@ class ObjectMirror final : public ValueMirror { ...@@ -911,9 +906,10 @@ class ObjectMirror final : public ValueMirror {
if (mirrors[i].value) { if (mirrors[i].value) {
mirrors[i].value->buildPropertyPreview(context, mirrors[i].name, mirrors[i].value->buildPropertyPreview(context, mirrors[i].name,
&preview); &preview);
if (generatePreviewForProperties) { if (generatePreviewForTable) {
mirrors[i].value->buildObjectPreview(context, false, nameLimit, int tableLimit = 1000;
indexLimit, &valuePreview); mirrors[i].value->buildObjectPreview(context, false, &tableLimit,
&tableLimit, &valuePreview);
} }
} else { } else {
preview = PropertyPreview::create() preview = PropertyPreview::create()
...@@ -937,15 +933,13 @@ class ObjectMirror final : public ValueMirror { ...@@ -937,15 +933,13 @@ class ObjectMirror final : public ValueMirror {
entriesPreview = protocol::Array<EntryPreview>::create(); entriesPreview = protocol::Array<EntryPreview>::create();
for (const auto& entry : entries) { for (const auto& entry : entries) {
std::unique_ptr<ObjectPreview> valuePreview; std::unique_ptr<ObjectPreview> valuePreview;
entry.value->buildEntryPreview( entry.value->buildEntryPreview(context, nameLimit, indexLimit,
context, generatePreviewForProperties, nameLimit, indexLimit, &valuePreview);
&valuePreview);
if (!valuePreview) continue; if (!valuePreview) continue;
std::unique_ptr<ObjectPreview> keyPreview; std::unique_ptr<ObjectPreview> keyPreview;
if (entry.key) { if (entry.key) {
entry.key->buildEntryPreview(context, entry.key->buildEntryPreview(context, nameLimit, indexLimit,
generatePreviewForProperties, &keyPreview);
nameLimit, indexLimit, &keyPreview);
if (!keyPreview) continue; if (!keyPreview) continue;
} }
std::unique_ptr<EntryPreview> entryPreview = std::unique_ptr<EntryPreview> entryPreview =
......
...@@ -52,12 +52,11 @@ class ValueMirror { ...@@ -52,12 +52,11 @@ class ValueMirror {
v8::Local<v8::Context> context, const String16& name, v8::Local<v8::Context> context, const String16& name,
std::unique_ptr<protocol::Runtime::PropertyPreview>*) {} std::unique_ptr<protocol::Runtime::PropertyPreview>*) {}
virtual void buildObjectPreview( virtual void buildObjectPreview(
v8::Local<v8::Context> context, bool generatePreviewForProperties, v8::Local<v8::Context> context, bool generatePreviewForTable,
int* nameLimit, int* indexLimit, int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*) {} std::unique_ptr<protocol::Runtime::ObjectPreview>*) {}
virtual void buildEntryPreview( virtual void buildEntryPreview(
v8::Local<v8::Context> context, bool generatePreviewForProperties, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*) {} std::unique_ptr<protocol::Runtime::ObjectPreview>*) {}
virtual v8::Local<v8::Value> v8Value() = 0; virtual v8::Local<v8::Value> v8Value() = 0;
......
...@@ -325,3 +325,61 @@ console.table ...@@ -325,3 +325,61 @@ console.table
subtype : array subtype : array
type : object type : object
} }
last value property:
{
name : 1
type : string
value : b
}
last property:
{
name : 998
subtype : array
type : object
value : Array(2)
valuePreview : {
description : Array(2)
overflow : false
properties : <ValuePreviewPropertiesArray(2)>
subtype : array
type : object
}
}
preview:
{
description : Array(999)
overflow : false
properties : <PropertiesArray(999)>
subtype : array
type : object
}
last value property:
{
name : 1
type : string
value : b
}
last property:
{
name : 999
subtype : array
type : object
value : Array(2)
valuePreview : {
description : Array(2)
overflow : false
properties : <ValuePreviewPropertiesArray(2)>
subtype : array
type : object
}
}
preview:
{
description : Array(1001)
overflow : true
properties : <PropertiesArray(1000)>
subtype : array
type : object
}
...@@ -53,12 +53,50 @@ const { session, contextGroup, Protocol } = ...@@ -53,12 +53,50 @@ const { session, contextGroup, Protocol } =
expression: `console.table([john, jane, emily], ['firstName'])` expression: `console.table([john, jane, emily], ['firstName'])`
}); });
await waitConsoleAPICalledAndDump(); await waitConsoleAPICalledAndDump();
Protocol.Runtime.evaluate({
expression: `var bigTable = new Array(999);
bigTable.fill(['a', 'b']);
console.table(bigTable);`
});
await waitConsoleAPICalledAndDump(true /* concise */);
Protocol.Runtime.evaluate({
expression: `var bigTable = new Array(1001);
bigTable.fill(['a', 'b']);
console.table(bigTable);`
});
await waitConsoleAPICalledAndDump(true /* concise */);
InspectorTest.completeTest(); InspectorTest.completeTest();
})() })()
async function waitConsoleAPICalledAndDump() { /**
* @param {boolean=} concise
*/
async function waitConsoleAPICalledAndDump(concise) {
const { params : { const { params : {
args: [ arg ] args: [ arg ]
} } = await Protocol.Runtime.onceConsoleAPICalled(); } } = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.logMessage(arg.preview); const preview = arg.preview;
if (concise)
simplifyAndPrintLast(preview);
else
InspectorTest.logMessage(arg.preview);
function simplifyAndPrintLast(preview) {
if (!Array.isArray(preview.properties))
return;
const properties = preview.properties;
const lastProperty = properties[properties.length - 1];
if (lastProperty.valuePreview && lastProperty.valuePreview.properties) {
const innerProperties = lastProperty.valuePreview.properties;
InspectorTest.logMessage(`last value property:`);
InspectorTest.logMessage(innerProperties[innerProperties.length - 1]);
lastProperty.valuePreview.properties = `<ValuePreviewPropertiesArray(${innerProperties.length})>`;
}
InspectorTest.logMessage(`last property:`);
InspectorTest.logMessage(lastProperty);
preview.properties = `<PropertiesArray(${properties.length})>`;
InspectorTest.logMessage(`preview:`);
InspectorTest.logMessage(preview);
InspectorTest.logMessage(``);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment