diff --git a/src/inspector/v8-console.cc b/src/inspector/v8-console.cc index bef916afb5..72f4f613e6 100644 --- a/src/inspector/v8-console.cc +++ b/src/inspector/v8-console.cc @@ -186,6 +186,8 @@ void createBoundFunctionProperty(v8::Local 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& 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& info, std::unique_ptr 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& info, void V8Console::inspectCallback(const v8::FunctionCallbackInfo& info, int sessionId) { - inspectImpl(info, sessionId, false, m_inspector); + inspectImpl(info, sessionId, kRegular, m_inspector); } void V8Console::copyCallback(const v8::FunctionCallbackInfo& info, int sessionId) { - inspectImpl(info, sessionId, true, m_inspector); + inspectImpl(info, sessionId, kCopyToClipboard, m_inspector); +} + +void V8Console::queryObjectsCallback( + const v8::FunctionCallbackInfo& info, int sessionId) { + if (info.Length() < 1 || !info[0]->IsFunction()) return; + inspectImpl(info, sessionId, kQueryObjects, m_inspector); } void V8Console::inspectedObject(const v8::FunctionCallbackInfo& info, @@ -683,6 +695,10 @@ v8::Local 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>); diff --git a/src/inspector/v8-console.h b/src/inspector/v8-console.h index b0e4beb2e6..a47a0b7cad 100644 --- a/src/inspector/v8-console.h +++ b/src/inspector/v8-console.h @@ -164,6 +164,8 @@ class V8Console : public v8::debug::ConsoleDelegate { int sessionId) { inspectedObject(info, sessionId, 4); } + void queryObjectsCallback(const v8::FunctionCallbackInfo& info, + int sessionId); V8InspectorImpl* m_inspector; }; diff --git a/test/inspector/runtime/command-line-api-expected.txt b/test/inspector/runtime/command-line-api-expected.txt index bcc15334f4..7976595343 100644 --- a/test/inspector/runtime/command-line-api-expected.txt +++ b/test/inspector/runtime/command-line-api-expected.txt @@ -86,6 +86,20 @@ Running test: testInspect } } } +{ + method : Runtime.inspectRequested + params : { + hints : { + queryObjects : true + } + object : { + className : Function + description : function Promise() { [native code] } + objectId : + type : function + } + } +} { id : result : { @@ -610,3 +624,16 @@ Running test: testClear type : clear } } + +Running test: testQueryObjects +{ + id : + result : { + result : { + className : Function + description : function queryObjects(constructor) { [Command Line API] } + objectId : + type : function + } + } +} diff --git a/test/inspector/runtime/command-line-api.js b/test/inspector/runtime/command-line-api.js index 16abde45e9..586cd4eb88 100644 --- a/test/inspector/runtime/command-line-api.js +++ b/test/inspector/runtime/command-line-api.js @@ -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})); } ]);