Commit 4eae3bb1 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[inspector] Make InjectedScript::getProperties respect custom formatters

BUG=chromium:917136

Change-Id: I02696a3315c22b34705bbc48cddaeb9e6c59fa9f
Reviewed-on: https://chromium-review.googlesource.com/c/1391749Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58482}
parent 0d0f0c51
......@@ -302,12 +302,9 @@ Response InjectedScript::getProperties(
Response response;
std::unique_ptr<RemoteObject> remoteObject;
if (mirror.value) {
response =
mirror.value->buildRemoteObject(context, wrapMode, &remoteObject);
if (!response.isSuccess()) return response;
response =
bindRemoteObjectIfNeeded(sessionId, context, mirror.value->v8Value(),
groupName, remoteObject.get());
response = wrapObjectMirror(*mirror.value, groupName, wrapMode,
v8::MaybeLocal<v8::Value>(),
kMaxCustomPreviewDepth, &remoteObject);
if (!response.isSuccess()) return response;
descriptor->setValue(std::move(remoteObject));
descriptor->setWritable(mirror.writable);
......@@ -411,12 +408,23 @@ Response InjectedScript::wrapObject(
std::unique_ptr<protocol::Runtime::RemoteObject>* result) {
v8::Local<v8::Context> context = m_context->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 sessionId = m_sessionId;
auto obj = ValueMirror::create(m_context->context(), value);
if (!obj) return Response::InternalError();
Response response = obj->buildRemoteObject(context, wrapMode, result);
v8::Local<v8::Context> context = m_context->context();
v8::Context::Scope contextScope(context);
Response response = mirror.buildRemoteObject(context, wrapMode, result);
if (!response.isSuccess()) return response;
v8::Local<v8::Value> value = mirror.v8Value();
response = bindRemoteObjectIfNeeded(sessionId, context, value, groupName,
result->get());
if (!response.isSuccess()) return response;
......
......@@ -48,6 +48,7 @@ namespace v8_inspector {
class RemoteObjectId;
class V8InspectorImpl;
class V8InspectorSessionImpl;
class ValueMirror;
enum class WrapMode;
using protocol::Maybe;
......@@ -93,6 +94,10 @@ class InjectedScript final {
v8::MaybeLocal<v8::Value> customPreviewConfig,
int maxCustomPreviewDepth,
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(
v8::Local<v8::Object> table, v8::MaybeLocal<v8::Array> columns);
......
This diff is collapsed.
......@@ -47,18 +47,18 @@ class ValueMirror {
v8::Local<v8::Value> value);
virtual protocol::Response buildRemoteObject(
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(
v8::Local<v8::Context> context, const String16& name,
std::unique_ptr<protocol::Runtime::PropertyPreview>*) {}
std::unique_ptr<protocol::Runtime::PropertyPreview>*) const {}
virtual void buildObjectPreview(
v8::Local<v8::Context> context, bool generatePreviewForTable,
int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*) {}
std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
virtual void buildEntryPreview(
v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*) {}
virtual v8::Local<v8::Value> v8Value() = 0;
std::unique_ptr<protocol::Runtime::ObjectPreview>*) const {}
virtual v8::Local<v8::Value> v8Value() const = 0;
class PropertyAccumulator {
public:
......
......@@ -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}"}}]]
}
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..
{
method : Runtime.consoleAPICalled
......
......@@ -51,18 +51,24 @@ const {session, contextGroup, Protocol} =
Protocol.Runtime.onConsoleAPICalled(m => InspectorTest.logMessage(m));
InspectorTest.log('Dump custom previews..');
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'a'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'b'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'c'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'configTest'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'a'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'b'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'c'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'configTest'}));
InspectorTest.log('Change formatters order and dump again..');
await Protocol.Runtime.evaluate({
expression: 'this.devtoolsFormatters = [formatter2, formatter1, formatterWithConfig1, formatterWithConfig2]'
});
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'a'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'b'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'c'}));
await dumpCustomPreview(await Protocol.Runtime.evaluate({expression: 'configTest'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'a'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'b'}));
await dumpCustomPreviewForEvaluate(await Protocol.Runtime.evaluate({expression: 'c'}));
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..');
await Protocol.Runtime.evaluate({
......@@ -104,11 +110,16 @@ const {session, contextGroup, Protocol} =
});
Protocol.Runtime.evaluate({ expression: '({})', generatePreview: true });
InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
InspectorTest.completeTest();
})()
function dumpCustomPreviewForEvaluate(result) {
return dumpCustomPreview(result.result.result);
}
async function dumpCustomPreview(result) {
const { objectId, customPreview } = result.result.result;
const { objectId, customPreview } = result;
InspectorTest.logMessage(customPreview);
if (customPreview.bodyGetterId) {
const body = await Protocol.Runtime.callFunctionOn({
......
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