[inspector] Make InjectedScript::getProperties respect custom formatters

BUG=chromium:917136

Change-Id: I02696a3315c22b34705bbc48cddaeb9e6c59fa9f
Reviewed-on: https://chromium-review.googlesource.com/c/1391749
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58482}
This commit is contained in:
Alexei Filippov 2018-12-27 14:17:02 -08:00 committed by Commit Bot
parent 0d0f0c51c5
commit 4eae3bb140
6 changed files with 147 additions and 84 deletions

View File

@ -302,12 +302,9 @@ Response InjectedScript::getProperties(
Response response; Response response;
std::unique_ptr<RemoteObject> remoteObject; std::unique_ptr<RemoteObject> remoteObject;
if (mirror.value) { if (mirror.value) {
response = response = wrapObjectMirror(*mirror.value, groupName, wrapMode,
mirror.value->buildRemoteObject(context, wrapMode, &remoteObject); v8::MaybeLocal<v8::Value>(),
if (!response.isSuccess()) return response; kMaxCustomPreviewDepth, &remoteObject);
response =
bindRemoteObjectIfNeeded(sessionId, context, mirror.value->v8Value(),
groupName, remoteObject.get());
if (!response.isSuccess()) return response; if (!response.isSuccess()) return response;
descriptor->setValue(std::move(remoteObject)); descriptor->setValue(std::move(remoteObject));
descriptor->setWritable(mirror.writable); descriptor->setWritable(mirror.writable);
@ -411,12 +408,23 @@ Response InjectedScript::wrapObject(
std::unique_ptr<protocol::Runtime::RemoteObject>* result) { std::unique_ptr<protocol::Runtime::RemoteObject>* result) {
v8::Local<v8::Context> context = m_context->context(); v8::Local<v8::Context> context = m_context->context();
v8::Context::Scope contextScope(context); v8::Context::Scope contextScope(context);
std::unique_ptr<ValueMirror> mirror = ValueMirror::create(context, value);
if (!mirror) return Response::InternalError();
return wrapObjectMirror(*mirror, groupName, wrapMode, customPreviewConfig,
maxCustomPreviewDepth, result);
}
Response InjectedScript::wrapObjectMirror(
const ValueMirror& mirror, const String16& groupName, WrapMode wrapMode,
v8::MaybeLocal<v8::Value> customPreviewConfig, int maxCustomPreviewDepth,
std::unique_ptr<protocol::Runtime::RemoteObject>* result) {
int customPreviewEnabled = m_customPreviewEnabled; int customPreviewEnabled = m_customPreviewEnabled;
int sessionId = m_sessionId; int sessionId = m_sessionId;
auto obj = ValueMirror::create(m_context->context(), value); v8::Local<v8::Context> context = m_context->context();
if (!obj) return Response::InternalError(); v8::Context::Scope contextScope(context);
Response response = obj->buildRemoteObject(context, wrapMode, result); Response response = mirror.buildRemoteObject(context, wrapMode, result);
if (!response.isSuccess()) return response; if (!response.isSuccess()) return response;
v8::Local<v8::Value> value = mirror.v8Value();
response = bindRemoteObjectIfNeeded(sessionId, context, value, groupName, response = bindRemoteObjectIfNeeded(sessionId, context, value, groupName,
result->get()); result->get());
if (!response.isSuccess()) return response; if (!response.isSuccess()) return response;

View File

@ -48,6 +48,7 @@ namespace v8_inspector {
class RemoteObjectId; class RemoteObjectId;
class V8InspectorImpl; class V8InspectorImpl;
class V8InspectorSessionImpl; class V8InspectorSessionImpl;
class ValueMirror;
enum class WrapMode; enum class WrapMode;
using protocol::Maybe; using protocol::Maybe;
@ -93,6 +94,10 @@ class InjectedScript final {
v8::MaybeLocal<v8::Value> customPreviewConfig, v8::MaybeLocal<v8::Value> customPreviewConfig,
int maxCustomPreviewDepth, int maxCustomPreviewDepth,
std::unique_ptr<protocol::Runtime::RemoteObject>* result); std::unique_ptr<protocol::Runtime::RemoteObject>* result);
Response wrapObjectMirror(
const ValueMirror& mirror, const String16& groupName, WrapMode wrapMode,
v8::MaybeLocal<v8::Value> customPreviewConfig, int maxCustomPreviewDepth,
std::unique_ptr<protocol::Runtime::RemoteObject>* result);
std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable( std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable(
v8::Local<v8::Object> table, v8::MaybeLocal<v8::Array> columns); v8::Local<v8::Object> table, v8::MaybeLocal<v8::Array> columns);

View File

@ -325,9 +325,10 @@ class PrimitiveValueMirror final : public ValueMirror {
PrimitiveValueMirror(v8::Local<v8::Value> value, const String16& type) PrimitiveValueMirror(v8::Local<v8::Value> value, const String16& type)
: m_value(value), m_type(type) {} : m_value(value), m_type(type) {}
v8::Local<v8::Value> v8Value() override { return m_value; } v8::Local<v8::Value> v8Value() const override { return m_value; }
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
std::unique_ptr<protocol::Value> protocolValue; std::unique_ptr<protocol::Value> protocolValue;
toProtocolValue(context, m_value, &protocolValue); toProtocolValue(context, m_value, &protocolValue);
*result = RemoteObject::create() *result = RemoteObject::create()
@ -339,9 +340,9 @@ class PrimitiveValueMirror final : public ValueMirror {
return Response::OK(); return Response::OK();
} }
void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit, void buildEntryPreview(
int* indexLimit, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) override { std::unique_ptr<ObjectPreview>* preview) const override {
*preview = *preview =
ObjectPreview::create() ObjectPreview::create()
.setType(m_type) .setType(m_type)
@ -355,7 +356,7 @@ class PrimitiveValueMirror final : public ValueMirror {
void buildPropertyPreview( void buildPropertyPreview(
v8::Local<v8::Context> context, const String16& name, v8::Local<v8::Context> context, const String16& name,
std::unique_ptr<PropertyPreview>* preview) override { std::unique_ptr<PropertyPreview>* preview) const override {
*preview = PropertyPreview::create() *preview = PropertyPreview::create()
.setName(name) .setName(name)
.setValue(abbreviateString( .setValue(abbreviateString(
@ -375,10 +376,11 @@ class PrimitiveValueMirror final : public ValueMirror {
class NumberMirror final : public ValueMirror { class NumberMirror final : public ValueMirror {
public: public:
explicit NumberMirror(v8::Local<v8::Number> value) : m_value(value) {} explicit NumberMirror(v8::Local<v8::Number> value) : m_value(value) {}
v8::Local<v8::Value> v8Value() override { return m_value; } v8::Local<v8::Value> v8Value() const override { return m_value; }
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
bool unserializable = false; bool unserializable = false;
String16 descriptionValue = description(&unserializable); String16 descriptionValue = description(&unserializable);
*result = RemoteObject::create() *result = RemoteObject::create()
@ -392,9 +394,9 @@ class NumberMirror final : public ValueMirror {
} }
return Response::OK(); return Response::OK();
} }
void buildPropertyPreview(v8::Local<v8::Context> context, void buildPropertyPreview(
const String16& name, v8::Local<v8::Context> context, const String16& name,
std::unique_ptr<PropertyPreview>* result) override { std::unique_ptr<PropertyPreview>* result) const override {
bool unserializable = false; bool unserializable = false;
*result = PropertyPreview::create() *result = PropertyPreview::create()
.setName(name) .setName(name)
@ -402,9 +404,9 @@ class NumberMirror final : public ValueMirror {
.setValue(description(&unserializable)) .setValue(description(&unserializable))
.build(); .build();
} }
void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit, void buildEntryPreview(
int* indexLimit, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) override { std::unique_ptr<ObjectPreview>* preview) const override {
bool unserializable = false; bool unserializable = false;
*preview = ObjectPreview::create() *preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Number) .setType(RemoteObject::TypeEnum::Number)
@ -415,7 +417,7 @@ class NumberMirror final : public ValueMirror {
} }
private: private:
String16 description(bool* unserializable) { String16 description(bool* unserializable) const {
*unserializable = true; *unserializable = true;
double rawValue = m_value->Value(); double rawValue = m_value->Value();
if (std::isnan(rawValue)) return "NaN"; if (std::isnan(rawValue)) return "NaN";
@ -434,8 +436,9 @@ class BigIntMirror final : public ValueMirror {
public: public:
explicit BigIntMirror(v8::Local<v8::BigInt> value) : m_value(value) {} explicit BigIntMirror(v8::Local<v8::BigInt> value) : m_value(value) {}
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
String16 description = descriptionForBigInt(context, m_value); String16 description = descriptionForBigInt(context, m_value);
*result = RemoteObject::create() *result = RemoteObject::create()
.setType(RemoteObject::TypeEnum::Bigint) .setType(RemoteObject::TypeEnum::Bigint)
@ -445,9 +448,10 @@ class BigIntMirror final : public ValueMirror {
return Response::OK(); return Response::OK();
} }
void buildPropertyPreview( void buildPropertyPreview(v8::Local<v8::Context> context,
v8::Local<v8::Context> context, const String16& name, const String16& name,
std::unique_ptr<protocol::Runtime::PropertyPreview>* preview) override { std::unique_ptr<protocol::Runtime::PropertyPreview>*
preview) const override {
*preview = PropertyPreview::create() *preview = PropertyPreview::create()
.setName(name) .setName(name)
.setType(RemoteObject::TypeEnum::Bigint) .setType(RemoteObject::TypeEnum::Bigint)
@ -456,9 +460,10 @@ class BigIntMirror final : public ValueMirror {
.build(); .build();
} }
void buildEntryPreview( void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit,
v8::Local<v8::Context> context, int* nameLimit, int* indexLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>* preview) override { std::unique_ptr<protocol::Runtime::ObjectPreview>*
preview) const override {
*preview = ObjectPreview::create() *preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Bigint) .setType(RemoteObject::TypeEnum::Bigint)
.setDescription(descriptionForBigInt(context, m_value)) .setDescription(descriptionForBigInt(context, m_value))
@ -467,7 +472,7 @@ class BigIntMirror final : public ValueMirror {
.build(); .build();
} }
v8::Local<v8::Value> v8Value() override { return m_value; } v8::Local<v8::Value> v8Value() const override { return m_value; }
private: private:
v8::Local<v8::BigInt> m_value; v8::Local<v8::BigInt> m_value;
@ -478,8 +483,9 @@ class SymbolMirror final : public ValueMirror {
explicit SymbolMirror(v8::Local<v8::Value> value) explicit SymbolMirror(v8::Local<v8::Value> value)
: m_symbol(value.As<v8::Symbol>()) {} : m_symbol(value.As<v8::Symbol>()) {}
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
if (mode == WrapMode::kForceValue) { if (mode == WrapMode::kForceValue) {
return Response::Error("Object couldn't be returned by value"); return Response::Error("Object couldn't be returned by value");
} }
@ -490,9 +496,10 @@ class SymbolMirror final : public ValueMirror {
return Response::OK(); return Response::OK();
} }
void buildPropertyPreview( void buildPropertyPreview(v8::Local<v8::Context> context,
v8::Local<v8::Context> context, const String16& name, const String16& name,
std::unique_ptr<protocol::Runtime::PropertyPreview>* preview) override { std::unique_ptr<protocol::Runtime::PropertyPreview>*
preview) const override {
*preview = PropertyPreview::create() *preview = PropertyPreview::create()
.setName(name) .setName(name)
.setType(RemoteObject::TypeEnum::Symbol) .setType(RemoteObject::TypeEnum::Symbol)
@ -501,7 +508,7 @@ class SymbolMirror final : public ValueMirror {
.build(); .build();
} }
v8::Local<v8::Value> v8Value() override { return m_symbol; } v8::Local<v8::Value> v8Value() const override { return m_symbol; }
private: private:
v8::Local<v8::Symbol> m_symbol; v8::Local<v8::Symbol> m_symbol;
@ -530,8 +537,9 @@ class LocationMirror final : public ValueMirror {
suspendedLocation.GetColumnNumber()); suspendedLocation.GetColumnNumber());
} }
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
auto location = protocol::DictionaryValue::create(); auto location = protocol::DictionaryValue::create();
location->setString("scriptId", String16::fromInteger(m_scriptId)); location->setString("scriptId", String16::fromInteger(m_scriptId));
location->setInteger("lineNumber", m_lineNumber); location->setInteger("lineNumber", m_lineNumber);
@ -544,7 +552,7 @@ class LocationMirror final : public ValueMirror {
.build(); .build();
return Response::OK(); return Response::OK();
} }
v8::Local<v8::Value> v8Value() override { return m_value; } v8::Local<v8::Value> v8Value() const override { return m_value; }
private: private:
static std::unique_ptr<LocationMirror> create(v8::Local<v8::Value> value, static std::unique_ptr<LocationMirror> create(v8::Local<v8::Value> value,
@ -577,10 +585,11 @@ class FunctionMirror final : public ValueMirror {
explicit FunctionMirror(v8::Local<v8::Value> value) explicit FunctionMirror(v8::Local<v8::Value> value)
: m_value(value.As<v8::Function>()) {} : m_value(value.As<v8::Function>()) {}
v8::Local<v8::Value> v8Value() override { return m_value; } v8::Local<v8::Value> v8Value() const override { return m_value; }
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
// TODO(alph): drop this functionality. // TODO(alph): drop this functionality.
if (mode == WrapMode::kForceValue) { if (mode == WrapMode::kForceValue) {
std::unique_ptr<protocol::Value> protocolValue; std::unique_ptr<protocol::Value> protocolValue;
@ -601,18 +610,18 @@ class FunctionMirror final : public ValueMirror {
return Response::OK(); return Response::OK();
} }
void buildPropertyPreview(v8::Local<v8::Context> context, void buildPropertyPreview(
const String16& name, v8::Local<v8::Context> context, const String16& name,
std::unique_ptr<PropertyPreview>* result) override { std::unique_ptr<PropertyPreview>* result) const override {
*result = PropertyPreview::create() *result = PropertyPreview::create()
.setName(name) .setName(name)
.setType(RemoteObject::TypeEnum::Function) .setType(RemoteObject::TypeEnum::Function)
.setValue(String16()) .setValue(String16())
.build(); .build();
} }
void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit, void buildEntryPreview(
int* indexLimit, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) override { std::unique_ptr<ObjectPreview>* preview) const override {
*preview = ObjectPreview::create() *preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Function) .setType(RemoteObject::TypeEnum::Function)
.setDescription(descriptionForFunction(context, m_value)) .setDescription(descriptionForFunction(context, m_value))
@ -809,10 +818,11 @@ class ObjectMirror final : public ValueMirror {
m_hasSubtype(true), m_hasSubtype(true),
m_subtype(subtype) {} m_subtype(subtype) {}
v8::Local<v8::Value> v8Value() override { return m_value; } v8::Local<v8::Value> v8Value() const override { return m_value; }
Response buildRemoteObject(v8::Local<v8::Context> context, WrapMode mode, Response buildRemoteObject(
std::unique_ptr<RemoteObject>* result) override { v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<RemoteObject>* result) const override {
if (mode == WrapMode::kForceValue) { if (mode == WrapMode::kForceValue) {
std::unique_ptr<protocol::Value> protocolValue; std::unique_ptr<protocol::Value> protocolValue;
Response response = toProtocolValue(context, m_value, &protocolValue); Response response = toProtocolValue(context, m_value, &protocolValue);
@ -842,26 +852,26 @@ class ObjectMirror final : public ValueMirror {
return Response::OK(); return Response::OK();
} }
void buildObjectPreview(v8::Local<v8::Context> context, void buildObjectPreview(
bool generatePreviewForTable, int* nameLimit, v8::Local<v8::Context> context, bool generatePreviewForTable,
int* indexLimit, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) override { std::unique_ptr<ObjectPreview>* result) const override {
buildObjectPreviewInternal(context, false /* forEntry */, buildObjectPreviewInternal(context, false /* forEntry */,
generatePreviewForTable, nameLimit, indexLimit, generatePreviewForTable, nameLimit, indexLimit,
result); result);
} }
void buildEntryPreview(v8::Local<v8::Context> context, int* nameLimit, void buildEntryPreview(
int* indexLimit, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) override { std::unique_ptr<ObjectPreview>* result) const override {
buildObjectPreviewInternal(context, true /* forEntry */, buildObjectPreviewInternal(context, true /* forEntry */,
false /* generatePreviewForTable */, nameLimit, false /* generatePreviewForTable */, nameLimit,
indexLimit, result); indexLimit, result);
} }
void buildPropertyPreview(v8::Local<v8::Context> context, void buildPropertyPreview(
const String16& name, v8::Local<v8::Context> context, const String16& name,
std::unique_ptr<PropertyPreview>* result) override { std::unique_ptr<PropertyPreview>* result) const override {
*result = PropertyPreview::create() *result = PropertyPreview::create()
.setName(name) .setName(name)
.setType(RemoteObject::TypeEnum::Object) .setType(RemoteObject::TypeEnum::Object)
@ -874,10 +884,10 @@ class ObjectMirror final : public ValueMirror {
} }
private: private:
void buildObjectPreviewInternal(v8::Local<v8::Context> context, bool forEntry, void buildObjectPreviewInternal(
bool generatePreviewForTable, int* nameLimit, v8::Local<v8::Context> context, bool forEntry,
int* indexLimit, bool generatePreviewForTable, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) { std::unique_ptr<ObjectPreview>* result) const {
std::unique_ptr<protocol::Array<PropertyPreview>> properties = std::unique_ptr<protocol::Array<PropertyPreview>> properties =
protocol::Array<PropertyPreview>::create(); protocol::Array<PropertyPreview>::create();
std::unique_ptr<protocol::Array<EntryPreview>> entriesPreview; std::unique_ptr<protocol::Array<EntryPreview>> entriesPreview;

View File

@ -47,18 +47,18 @@ class ValueMirror {
v8::Local<v8::Value> value); v8::Local<v8::Value> value);
virtual protocol::Response buildRemoteObject( virtual protocol::Response buildRemoteObject(
v8::Local<v8::Context> context, WrapMode mode, v8::Local<v8::Context> context, WrapMode mode,
std::unique_ptr<protocol::Runtime::RemoteObject>* result) = 0; std::unique_ptr<protocol::Runtime::RemoteObject>* result) const = 0;
virtual void buildPropertyPreview( virtual void buildPropertyPreview(
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>*) const {}
virtual void buildObjectPreview( virtual void buildObjectPreview(
v8::Local<v8::Context> context, bool generatePreviewForTable, 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>*) const {}
virtual void buildEntryPreview( virtual void buildEntryPreview(
v8::Local<v8::Context> context, int* nameLimit, int* indexLimit, v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*) {} std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
virtual v8::Local<v8::Value> v8Value() = 0; virtual v8::Local<v8::Value> v8Value() const = 0;
class PropertyAccumulator { class PropertyAccumulator {
public: public:

View File

@ -148,6 +148,35 @@ Change formatters order and dump again..
{ {
header : ["span",{},"Formatter with config ",["object",{"type":"object","className":"Object","description":"Object","objectId":"{\"injectedScriptId\":1,\"id\":21}","customPreview":{"header":"[\"span\",{},\"Header \",\"info: \",\"additional info\"]","bodyGetterId":"{\"injectedScriptId\":1,\"id\":22}"}}]] header : ["span",{},"Formatter with config ",["object",{"type":"object","className":"Object","description":"Object","objectId":"{\"injectedScriptId\":1,\"id\":21}","customPreview":{"header":"[\"span\",{},\"Header \",\"info: \",\"additional info\"]","bodyGetterId":"{\"injectedScriptId\":1,\"id\":22}"}}]]
} }
Test Runtime.getProperties
{
bodyGetterId : <bodyGetterId>
header : ["span",{},"Header formatted by 1 ","a"]
}
{
id : <messageId>
result : {
result : {
type : object
value : [
[0] : span
[1] : {
}
[2] : Body formatted by 1
[3] : a
[4] : [
[0] : object
[1] : {
className : Object
description : Object
objectId : <objectId>
type : object
}
]
]
}
}
}
Try to break custom preview.. Try to break custom preview..
{ {
method : Runtime.consoleAPICalled method : Runtime.consoleAPICalled

View File

@ -51,18 +51,24 @@ const {session, contextGroup, Protocol} =
Protocol.Runtime.onConsoleAPICalled(m => InspectorTest.logMessage(m)); Protocol.Runtime.onConsoleAPICalled(m => InspectorTest.logMessage(m));
InspectorTest.log('Dump custom previews..'); InspectorTest.log('Dump custom previews..');
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'a'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'a'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'b'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'b'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'c'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'c'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'configTest'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'configTest'}));
InspectorTest.log('Change formatters order and dump again..'); InspectorTest.log('Change formatters order and dump again..');
await Protocol.Runtime.evaluate({ await Protocol.Runtime.evaluate({
expression: 'this.devtoolsFormatters = [formatter2, formatter1, formatterWithConfig1, formatterWithConfig2]' expression: 'this.devtoolsFormatters = [formatter2, formatter1, formatterWithConfig1, formatterWithConfig2]'
}); });
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'a'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'a'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'b'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'b'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'c'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'c'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'configTest'})); await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'configTest'}));
InspectorTest.log('Test Runtime.getProperties');
const {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({expression: '({a})'});
const {result:{result}} = await Protocol.Runtime.getProperties({
objectId, ownProperties: true, generatePreview: true});
await dumpCustomPreview(result.find(value => value.name === 'a').value);
InspectorTest.log('Try to break custom preview..'); InspectorTest.log('Try to break custom preview..');
await Protocol.Runtime.evaluate({ await Protocol.Runtime.evaluate({
@ -104,11 +110,16 @@ const {session, contextGroup, Protocol} =
}); });
Protocol.Runtime.evaluate({ expression: '({})', generatePreview: true }); Protocol.Runtime.evaluate({ expression: '({})', generatePreview: true });
InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled()); InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
InspectorTest.completeTest(); InspectorTest.completeTest();
})() })()
function dumpCustomPreviewForEvaluate(result) {
return dumpCustomPreview(result.result.result);
}
async function dumpCustomPreview(result) { async function dumpCustomPreview(result) {
const { objectId, customPreview } = result.result.result; const { objectId, customPreview } = result;
InspectorTest.logMessage(customPreview); InspectorTest.logMessage(customPreview);
if (customPreview.bodyGetterId) { if (customPreview.bodyGetterId) {
const body = await Protocol.Runtime.callFunctionOn({ const body = await Protocol.Runtime.callFunctionOn({