Commit d01fc272 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[inspector] improved queryObjects command line API

API resolves functions to its .prototype property to make possible
queries like queryObjects(Object), queryObjects(HTMLElement), e.t.c.

R=dgozman@chromium.org

Bug: v8:6732
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ie8dc2288fa7e59c69f9b2647a9d5e35f0ac9215f
Reviewed-on: https://chromium-review.googlesource.com/630244
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47561}
parent 172d6f50
...@@ -554,10 +554,9 @@ void V8Console::lastEvaluationResultCallback( ...@@ -554,10 +554,9 @@ void V8Console::lastEvaluationResultCallback(
} }
static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
int sessionId, InspectRequest request, v8::Local<v8::Value> value, int sessionId,
V8InspectorImpl* inspector) { InspectRequest request, V8InspectorImpl* inspector) {
if (info.Length() < 1) return; if (request == kRegular) info.GetReturnValue().Set(value);
if (request == kRegular) info.GetReturnValue().Set(info[0]);
v8::debug::ConsoleCallArguments args(info); v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, v8::debug::ConsoleContext(), inspector); ConsoleHelper helper(args, v8::debug::ConsoleContext(), inspector);
...@@ -565,7 +564,7 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, ...@@ -565,7 +564,7 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
if (!injectedScript) return; if (!injectedScript) return;
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
protocol::Response response = protocol::Response response =
injectedScript->wrapObject(info[0], "", false /** forceValueType */, injectedScript->wrapObject(value, "", false /** forceValueType */,
false /** generatePreview */, &wrappedObject); false /** generatePreview */, &wrappedObject);
if (!response.isSuccess()) return; if (!response.isSuccess()) return;
...@@ -584,18 +583,37 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, ...@@ -584,18 +583,37 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
void V8Console::inspectCallback(const v8::FunctionCallbackInfo<v8::Value>& info, void V8Console::inspectCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
int sessionId) { int sessionId) {
inspectImpl(info, sessionId, kRegular, m_inspector); if (info.Length() < 1) return;
inspectImpl(info, info[0], sessionId, kRegular, m_inspector);
} }
void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info, void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
int sessionId) { int sessionId) {
inspectImpl(info, sessionId, kCopyToClipboard, m_inspector); if (info.Length() < 1) return;
inspectImpl(info, info[0], sessionId, kCopyToClipboard, m_inspector);
} }
void V8Console::queryObjectsCallback( void V8Console::queryObjectsCallback(
const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) { const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
if (info.Length() < 1 || !info[0]->IsObject()) return; if (info.Length() < 1) return;
inspectImpl(info, sessionId, kQueryObjects, m_inspector); v8::Local<v8::Value> arg = info[0];
if (arg->IsFunction()) {
v8::Isolate* isolate = info.GetIsolate();
v8::TryCatch tryCatch(isolate);
v8::Local<v8::Value> prototype;
if (arg.As<v8::Function>()
->Get(isolate->GetCurrentContext(),
toV8StringInternalized(isolate, "prototype"))
.ToLocal(&prototype) &&
prototype->IsObject()) {
arg = prototype;
}
if (tryCatch.HasCaught()) {
tryCatch.ReThrow();
return;
}
}
inspectImpl(info, arg, sessionId, kQueryObjects, m_inspector);
} }
void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
......
...@@ -86,32 +86,75 @@ Running test: testInspect ...@@ -86,32 +86,75 @@ Running test: testInspect
} }
} }
} }
{
id : <messageId>
result : {
result : {
type : undefined
}
}
}
{ {
method : Runtime.inspectRequested method : Runtime.inspectRequested
params : { params : {
hints : { hints : {
queryObjects : true
} }
object : { object : {
className : Function className : Object
description : function Promise() { [native code] } description : Object
objectId : <objectId> objectId : <objectId>
type : function type : object
} }
} }
} }
Running test: testQueryObjects
{ {
id : <messageId> id : <messageId>
result : { result : {
result : { result : {
type : undefined className : Function
description : function queryObjects(constructor) { [Command Line API] }
objectId : <objectId>
type : function
}
}
}
{
method : Runtime.inspectRequested
params : {
hints : {
queryObjects : true
}
object : {
className : Promise
description : Promise
objectId : <objectId>
type : object
}
}
}
Is Promise.prototype: true
{
method : Runtime.inspectRequested
params : {
hints : {
queryObjects : true
}
object : {
className : Promise
description : Promise
objectId : <objectId>
type : object
} }
} }
} }
Is Promise.prototype: true
{ {
method : Runtime.inspectRequested method : Runtime.inspectRequested
params : { params : {
hints : { hints : {
queryObjects : true
} }
object : { object : {
className : Object className : Object
...@@ -121,6 +164,20 @@ Running test: testInspect ...@@ -121,6 +164,20 @@ Running test: testInspect
} }
} }
} }
Is p: true
{
method : Runtime.inspectRequested
params : {
hints : {
queryObjects : true
}
object : {
description : 1
type : number
value : 1
}
}
}
Running test: testEvaluationResult Running test: testEvaluationResult
{ {
...@@ -624,16 +681,3 @@ Running test: testClear ...@@ -624,16 +681,3 @@ Running test: testClear
type : clear type : clear
} }
} }
Running test: testQueryObjects
{
id : <messageId>
result : {
result : {
className : Function
description : function queryObjects(constructor) { [Command Line API] }
objectId : <objectId>
type : function
}
}
}
...@@ -24,8 +24,6 @@ InspectorTest.runAsyncTestSuite([ ...@@ -24,8 +24,6 @@ InspectorTest.runAsyncTestSuite([
await Protocol.Runtime.evaluate({expression: 'inspect(239)', includeCommandLineAPI: true}); await Protocol.Runtime.evaluate({expression: 'inspect(239)', includeCommandLineAPI: true});
await Protocol.Runtime.evaluate({expression: 'inspect(-0)', includeCommandLineAPI: true}); await Protocol.Runtime.evaluate({expression: 'inspect(-0)', includeCommandLineAPI: true});
await Protocol.Runtime.evaluate({expression: 'copy(\'hello\')', includeCommandLineAPI: true}); await Protocol.Runtime.evaluate({expression: 'copy(\'hello\')', includeCommandLineAPI: true});
await Protocol.Runtime.evaluate({expression: 'queryObjects(Promise)', includeCommandLineAPI: true});
await Protocol.Runtime.evaluate({expression: 'queryObjects(1)', includeCommandLineAPI: true});
InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$0', includeCommandLineAPI: true})); InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$0', includeCommandLineAPI: true}));
Protocol.Runtime.evaluate({expression: 'this.inspect = inspect', includeCommandLineAPI: true}); Protocol.Runtime.evaluate({expression: 'this.inspect = inspect', includeCommandLineAPI: true});
...@@ -35,6 +33,31 @@ InspectorTest.runAsyncTestSuite([ ...@@ -35,6 +33,31 @@ InspectorTest.runAsyncTestSuite([
await Protocol.Runtime.disable(); await Protocol.Runtime.disable();
}, },
async function testQueryObjects() {
InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'queryObjects', includeCommandLineAPI: true}));
await Protocol.Runtime.enable();
let {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({expression: 'Promise.prototype'});
Protocol.Runtime.evaluate({expression: 'queryObjects(Promise)', includeCommandLineAPI: true});
let request = await Protocol.Runtime.onceInspectRequested();
InspectorTest.logMessage(request);
InspectorTest.logMessage('Is Promise.prototype: ' + await isEqual(objectId, request.params.object.objectId));
Protocol.Runtime.evaluate({expression: 'queryObjects(Promise.prototype)', includeCommandLineAPI: true});
request = await Protocol.Runtime.onceInspectRequested();
InspectorTest.logMessage(request);
InspectorTest.logMessage('Is Promise.prototype: ' + await isEqual(objectId, request.params.object.objectId));
({result:{result:{objectId}}} = await Protocol.Runtime.evaluate({expression:'p = {a:1}'}));
Protocol.Runtime.evaluate({expression: 'queryObjects(p)', includeCommandLineAPI: true});
request = await Protocol.Runtime.onceInspectRequested();
InspectorTest.logMessage(request);
InspectorTest.logMessage('Is p: ' + await isEqual(objectId, request.params.object.objectId));
Protocol.Runtime.evaluate({expression: 'queryObjects(1)', includeCommandLineAPI: true});
InspectorTest.logMessage(await Protocol.Runtime.onceInspectRequested());
await Protocol.Runtime.disable();
},
async function testEvaluationResult() { async function testEvaluationResult() {
InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true})); InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true}));
await Protocol.Runtime.evaluate({expression: '42', objectGroup: 'console', includeCommandLineAPI: true}); await Protocol.Runtime.evaluate({expression: '42', objectGroup: 'console', includeCommandLineAPI: true});
...@@ -173,9 +196,14 @@ InspectorTest.runAsyncTestSuite([ ...@@ -173,9 +196,14 @@ InspectorTest.runAsyncTestSuite([
Protocol.Runtime.evaluate({expression: 'this.clear()'}); Protocol.Runtime.evaluate({expression: 'this.clear()'});
InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled()); InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
await Protocol.Runtime.disable(); await Protocol.Runtime.disable();
},
async function testQueryObjects() {
InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'queryObjects', includeCommandLineAPI: true}));
} }
]); ]);
async function isEqual(objectId1, objectId2) {
return (await Protocol.Runtime.callFunctionOn({
objectId: objectId1,
functionDeclaration: 'function(arg){return this === arg;}',
returnByValue: true,
arguments: [{objectId: objectId2}]
})).result.result.value;
}
...@@ -78,3 +78,19 @@ Query objects with Foo prototype. ...@@ -78,3 +78,19 @@ Query objects with Foo prototype.
Dump each object constructor name. Dump each object constructor name.
[ [
] ]
Running test: testObjectCreate
Declare Object p & store it.
Create object using Object.create(p).
Query objects with p prototype.
Dump each object constructor name.
[
[0] : Object,object
]
Create object using Object.create(p).
Query objects with p prototype.
Dump each object constructor name.
[
[0] : Object,object
[1] : Object,object
]
...@@ -99,6 +99,23 @@ InspectorTest.runAsyncTestSuite([ ...@@ -99,6 +99,23 @@ InspectorTest.runAsyncTestSuite([
Protocol.Runtime.evaluate({expression: 'inspector.markObjectAsNotInspectable(a)'}); Protocol.Runtime.evaluate({expression: 'inspector.markObjectAsNotInspectable(a)'});
await queryObjects(session, objectId, 'Foo'); await queryObjects(session, objectId, 'Foo');
session.disconnect(); session.disconnect();
},
async function testObjectCreate() {
let contextGroup = new InspectorTest.ContextGroup();
let session = contextGroup.connect();
let Protocol = session.Protocol;
InspectorTest.log('Declare Object p & store it.');
let {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({
expression: 'p = {a:1}'
});
for (let i = 0; i < 2; ++i) {
InspectorTest.log('Create object using Object.create(p).');
Protocol.Runtime.evaluate({expression: 'Object.create(p)'});
await queryObjects(session, objectId, 'p');
}
session.disconnect();
} }
]); ]);
......
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