[inspector] added queryObjects command line API
This API generates inspectRequested call with hints.queryObjects flag. It's not possible to expose this method by itself since command line API methods can leak. R=pfeldman@chromium.org Bug: v8:6732 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I3c582186f65d84a25eed910925a1b6ab36966a72 Reviewed-on: https://chromium-review.googlesource.com/622370 Reviewed-by: Pavel Feldman <pfeldman@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#47480}
This commit is contained in:
parent
e58ae53132
commit
f160520394
@ -186,6 +186,8 @@ void createBoundFunctionProperty(v8::Local<v8::Context> context,
|
||||
createDataProperty(context, console, funcName, func);
|
||||
}
|
||||
|
||||
enum InspectRequest { kRegular, kCopyToClipboard, kQueryObjects };
|
||||
|
||||
} // namespace
|
||||
|
||||
V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
|
||||
@ -552,10 +554,10 @@ void V8Console::lastEvaluationResultCallback(
|
||||
}
|
||||
|
||||
static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
int sessionId, bool copyToClipboard,
|
||||
int sessionId, InspectRequest request,
|
||||
V8InspectorImpl* inspector) {
|
||||
if (info.Length() < 1) return;
|
||||
if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
|
||||
if (request == kRegular) info.GetReturnValue().Set(info[0]);
|
||||
|
||||
v8::debug::ConsoleCallArguments args(info);
|
||||
ConsoleHelper helper(args, v8::debug::ConsoleContext(), inspector);
|
||||
@ -569,7 +571,11 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
|
||||
std::unique_ptr<protocol::DictionaryValue> hints =
|
||||
protocol::DictionaryValue::create();
|
||||
if (copyToClipboard) hints->setBoolean("copyToClipboard", true);
|
||||
if (request == kCopyToClipboard) {
|
||||
hints->setBoolean("copyToClipboard", true);
|
||||
} else if (request == kQueryObjects) {
|
||||
hints->setBoolean("queryObjects", true);
|
||||
}
|
||||
if (V8InspectorSessionImpl* session = helper.session(sessionId)) {
|
||||
session->runtimeAgent()->inspect(std::move(wrappedObject),
|
||||
std::move(hints));
|
||||
@ -578,12 +584,18 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
|
||||
void V8Console::inspectCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
int sessionId) {
|
||||
inspectImpl(info, sessionId, false, m_inspector);
|
||||
inspectImpl(info, sessionId, kRegular, m_inspector);
|
||||
}
|
||||
|
||||
void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
int sessionId) {
|
||||
inspectImpl(info, sessionId, true, m_inspector);
|
||||
inspectImpl(info, sessionId, kCopyToClipboard, m_inspector);
|
||||
}
|
||||
|
||||
void V8Console::queryObjectsCallback(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& info, int sessionId) {
|
||||
if (info.Length() < 1 || !info[0]->IsFunction()) return;
|
||||
inspectImpl(info, sessionId, kQueryObjects, m_inspector);
|
||||
}
|
||||
|
||||
void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
@ -683,6 +695,10 @@ v8::Local<v8::Object> V8Console::createCommandLineAPI(
|
||||
createBoundFunctionProperty(context, commandLineAPI, data, "copy",
|
||||
&V8Console::call<&V8Console::copyCallback>,
|
||||
"function copy(value) { [Command Line API] }");
|
||||
createBoundFunctionProperty(
|
||||
context, commandLineAPI, data, "queryObjects",
|
||||
&V8Console::call<&V8Console::queryObjectsCallback>,
|
||||
"function queryObjects(constructor) { [Command Line API] }");
|
||||
createBoundFunctionProperty(
|
||||
context, commandLineAPI, data, "$_",
|
||||
&V8Console::call<&V8Console::lastEvaluationResultCallback>);
|
||||
|
@ -164,6 +164,8 @@ class V8Console : public v8::debug::ConsoleDelegate {
|
||||
int sessionId) {
|
||||
inspectedObject(info, sessionId, 4);
|
||||
}
|
||||
void queryObjectsCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
|
||||
int sessionId);
|
||||
|
||||
V8InspectorImpl* m_inspector;
|
||||
};
|
||||
|
@ -86,6 +86,20 @@ Running test: testInspect
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
method : Runtime.inspectRequested
|
||||
params : {
|
||||
hints : {
|
||||
queryObjects : true
|
||||
}
|
||||
object : {
|
||||
className : Function
|
||||
description : function Promise() { [native code] }
|
||||
objectId : <objectId>
|
||||
type : function
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
id : <messageId>
|
||||
result : {
|
||||
@ -610,3 +624,16 @@ Running test: testClear
|
||||
type : clear
|
||||
}
|
||||
}
|
||||
|
||||
Running test: testQueryObjects
|
||||
{
|
||||
id : <messageId>
|
||||
result : {
|
||||
result : {
|
||||
className : Function
|
||||
description : function queryObjects(constructor) { [Command Line API] }
|
||||
objectId : <objectId>
|
||||
type : function
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ InspectorTest.runAsyncTestSuite([
|
||||
await Protocol.Runtime.evaluate({expression: 'inspect(239)', 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: 'queryObjects(Promise)', includeCommandLineAPI: true});
|
||||
await Protocol.Runtime.evaluate({expression: 'queryObjects(1)', includeCommandLineAPI: true});
|
||||
InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$0', includeCommandLineAPI: true}));
|
||||
|
||||
Protocol.Runtime.evaluate({expression: 'this.inspect = inspect', includeCommandLineAPI: true});
|
||||
@ -171,5 +173,9 @@ InspectorTest.runAsyncTestSuite([
|
||||
Protocol.Runtime.evaluate({expression: 'this.clear()'});
|
||||
InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
|
||||
await Protocol.Runtime.disable();
|
||||
},
|
||||
|
||||
async function testQueryObjects() {
|
||||
InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'queryObjects', includeCommandLineAPI: true}));
|
||||
}
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user