[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 <luoe@chromium.org>
Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51938}
This commit is contained in:
Erik Luo 2018-03-13 22:25:12 -07:00 committed by Commit Bot
parent 25363b8f2e
commit d452a7f63a
7 changed files with 61 additions and 4 deletions

View File

@ -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": [

View File

@ -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

View File

@ -573,7 +573,7 @@ void V8RuntimeAgentImpl::runScript(
}
Response V8RuntimeAgentImpl::queryObjects(
const String16& prototypeObjectId,
const String16& prototypeObjectId, Maybe<String16> objectGroup,
std::unique_ptr<protocol::Runtime::RemoteObject>* objects) {
InjectedScript::ObjectScope scope(m_session, prototypeObjectId);
Response response = scope.initialize();
@ -584,7 +584,8 @@ Response V8RuntimeAgentImpl::queryObjects(
v8::Local<v8::Array> resultArray = m_inspector->debugger()->queryObjects(
scope.context(), v8::Local<v8::Object>::Cast(scope.object()));
return scope.injectedScript()->wrapObject(
resultArray, scope.objectGroupName(), false, false, objects);
resultArray, objectGroup.fromMaybe(scope.objectGroupName()), false, false,
objects);
}
Response V8RuntimeAgentImpl::globalLexicalScopeNames(

View File

@ -99,7 +99,7 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
Maybe<bool> generatePreview, Maybe<bool> awaitPromise,
std::unique_ptr<RunScriptCallback>) override;
Response queryObjects(
const String16& prototypeObjectId,
const String16& prototypeObjectId, Maybe<String16> objectGroup,
std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
Response globalLexicalScopeNames(
Maybe<int> executionContextId,

View File

@ -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;

View File

@ -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

View File

@ -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 = `