From d452a7f63a41cff3e48f0d6b83238fd798fc28da Mon Sep 17 00:00:00 2001 From: Erik Luo Date: Tue, 13 Mar 2018 22:25:12 -0700 Subject: [PATCH] [inspector] queryObjects() should take objectGroup Now, 'queryObjects' takes an optional 'objectGroup' argument, allowing the frontend to release the response value. This is important because each call produces a new Array, which could not be released before. Bug: chromium:815263 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: I18c9a68c4ba45020fce9eea63cb263396a18d498 Reviewed-on: https://chromium-review.googlesource.com/935153 Commit-Queue: Erik Luo Reviewed-by: Aleksey Kozyatinskiy Reviewed-by: Dmitry Gozman Cr-Commit-Position: refs/heads/master@{#51938} --- src/inspector/js_protocol.json | 6 +++ src/inspector/js_protocol.pdl | 2 + src/inspector/v8-runtime-agent-impl.cc | 5 ++- src/inspector/v8-runtime-agent-impl.h | 2 +- test/inspector/protocol-test.js | 2 + .../runtime/query-objects-expected.txt | 9 +++++ test/inspector/runtime/query-objects.js | 39 ++++++++++++++++++- 7 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/inspector/js_protocol.json b/src/inspector/js_protocol.json index 069bfe43c2..7a35532835 100644 --- a/src/inspector/js_protocol.json +++ b/src/inspector/js_protocol.json @@ -2677,6 +2677,12 @@ "name": "prototypeObjectId", "description": "Identifier of the prototype to return objects for.", "$ref": "RemoteObjectId" + }, + { + "name": "objectGroup", + "description": "Symbolic group name that can be used to release the results.", + "optional": true, + "type": "string" } ], "returns": [ diff --git a/src/inspector/js_protocol.pdl b/src/inspector/js_protocol.pdl index bab5f6c645..f2e4ab6ca1 100644 --- a/src/inspector/js_protocol.pdl +++ b/src/inspector/js_protocol.pdl @@ -1229,6 +1229,8 @@ domain Runtime parameters # Identifier of the prototype to return objects for. RemoteObjectId prototypeObjectId + # Symbolic group name that can be used to release the results. + optional string objectGroup returns # Array with objects. RemoteObject objects diff --git a/src/inspector/v8-runtime-agent-impl.cc b/src/inspector/v8-runtime-agent-impl.cc index 54e39db56c..f3fd9ee7a0 100644 --- a/src/inspector/v8-runtime-agent-impl.cc +++ b/src/inspector/v8-runtime-agent-impl.cc @@ -573,7 +573,7 @@ void V8RuntimeAgentImpl::runScript( } Response V8RuntimeAgentImpl::queryObjects( - const String16& prototypeObjectId, + const String16& prototypeObjectId, Maybe objectGroup, std::unique_ptr* objects) { InjectedScript::ObjectScope scope(m_session, prototypeObjectId); Response response = scope.initialize(); @@ -584,7 +584,8 @@ Response V8RuntimeAgentImpl::queryObjects( v8::Local resultArray = m_inspector->debugger()->queryObjects( scope.context(), v8::Local::Cast(scope.object())); return scope.injectedScript()->wrapObject( - resultArray, scope.objectGroupName(), false, false, objects); + resultArray, objectGroup.fromMaybe(scope.objectGroupName()), false, false, + objects); } Response V8RuntimeAgentImpl::globalLexicalScopeNames( diff --git a/src/inspector/v8-runtime-agent-impl.h b/src/inspector/v8-runtime-agent-impl.h index 43016a6efe..3cb8e11f48 100644 --- a/src/inspector/v8-runtime-agent-impl.h +++ b/src/inspector/v8-runtime-agent-impl.h @@ -99,7 +99,7 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend { Maybe generatePreview, Maybe awaitPromise, std::unique_ptr) override; Response queryObjects( - const String16& prototypeObjectId, + const String16& prototypeObjectId, Maybe objectGroup, std::unique_ptr* objects) override; Response globalLexicalScopeNames( Maybe executionContextId, diff --git a/test/inspector/protocol-test.js b/test/inspector/protocol-test.js index 91f55e442a..9b7ba0aafe 100644 --- a/test/inspector/protocol-test.js +++ b/test/inspector/protocol-test.js @@ -309,6 +309,8 @@ InspectorTest.Session = class { } _sendCommandPromise(method, params) { + if (typeof params !== 'object') + utils.print(`WARNING: non-object params passed to invocation of method ${method}`); if (InspectorTest._commandsForLogging.has(method)) utils.print(method + ' called'); var requestId = ++this._requestId; diff --git a/test/inspector/runtime/query-objects-expected.txt b/test/inspector/runtime/query-objects-expected.txt index 9f365d979a..db16402986 100644 --- a/test/inspector/runtime/query-objects-expected.txt +++ b/test/inspector/runtime/query-objects-expected.txt @@ -94,3 +94,12 @@ Dump each object constructor name. [0] : Object,object [1] : Object,object ] + +Running test: testWithObjectGroup +Query for Array.prototype 3 times +Results since initial: 0 +Results since initial: 1 +Results since initial: 2 + +Released object group. +Results since initial: 0 diff --git a/test/inspector/runtime/query-objects.js b/test/inspector/runtime/query-objects.js index c3b1b2bd91..f37f1ed581 100644 --- a/test/inspector/runtime/query-objects.js +++ b/test/inspector/runtime/query-objects.js @@ -116,7 +116,44 @@ InspectorTest.runAsyncTestSuite([ await queryObjects(session, objectId, 'p'); } session.disconnect(); - } + }, + + async function testWithObjectGroup() { + let contextGroup = new InspectorTest.ContextGroup(); + let session = contextGroup.connect(); + let Protocol = session.Protocol; + let {result:{result:{objectId}}} = await Protocol.Runtime.evaluate({ + expression: 'Array.prototype' + }); + + let initialArrayCount; + const N = 3; + InspectorTest.log(`Query for Array.prototype ${N} times`); + for (let i = 0; i < N; ++i) { + const {result:{objects}} = await Protocol.Runtime.queryObjects({ + prototypeObjectId: objectId, + objectGroup: 'console' + }); + logCountSinceInitial(objects.description); + } + + await Protocol.Runtime.releaseObjectGroup({objectGroup: 'console'}); + InspectorTest.log('\nReleased object group.'); + + const {result:{objects}} = await Protocol.Runtime.queryObjects({ + prototypeObjectId: objectId, + objectGroup: 'console' + }); + logCountSinceInitial(objects.description); + session.disconnect(); + + function logCountSinceInitial(description) { + const count = parseInt(/Array\((\d+)\)/.exec(description)[1]); + if (typeof initialArrayCount === 'undefined') + initialArrayCount = count; + InspectorTest.logMessage(`Results since initial: ${count - initialArrayCount}`); + } + }, ]); const constructorsNameFunction = `