Commit d452a7f6 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

[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: 's avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51938}
parent 25363b8f
......@@ -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": [
......
......@@ -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
......
......@@ -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(
......
......@@ -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,
......
......@@ -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;
......
......@@ -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
......@@ -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 = `
......
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