Commit 673480f1 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (V8)

New revision: 83b1154a9661d22bba9a368d368214cc20880419

This updates the usages of the protocol types to the new
definitions, using std::vector-based implementations
of protocol::Array.

Change-Id: Ibb095862fed7db23f1a0b4b5b726bddbe1e2585e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1654091
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62194}
parent c5391e9d
......@@ -8,6 +8,7 @@ include_rules = [
"+src/base/platform/platform.h",
"+src/base/platform/mutex.h",
"+src/base/safe_conversions.h",
"+src/base/template-utils.h",
"+src/base/v8-fallthrough.h",
"+src/common/v8memory.h",
"+src/numbers/conversions.h",
......
......@@ -284,7 +284,7 @@ Response InjectedScript::getProperties(
int sessionId = m_sessionId;
v8::TryCatch tryCatch(isolate);
*properties = Array<PropertyDescriptor>::create();
*properties = v8::base::make_unique<Array<PropertyDescriptor>>();
std::vector<PropertyMirror> mirrors;
PropertyAccumulator accumulator(&mirrors);
if (!ValueMirror::getProperties(context, object, ownProperties,
......@@ -351,7 +351,7 @@ Response InjectedScript::getProperties(
descriptor->setValue(std::move(remoteObject));
descriptor->setWasThrown(true);
}
(*properties)->addItem(std::move(descriptor));
(*properties)->emplace_back(std::move(descriptor));
}
return Response::OK();
}
......@@ -362,8 +362,10 @@ Response InjectedScript::getInternalAndPrivateProperties(
internalProperties,
std::unique_ptr<protocol::Array<PrivatePropertyDescriptor>>*
privateProperties) {
*internalProperties = protocol::Array<InternalPropertyDescriptor>::create();
*privateProperties = protocol::Array<PrivatePropertyDescriptor>::create();
*internalProperties =
v8::base::make_unique<Array<InternalPropertyDescriptor>>();
*privateProperties =
v8::base::make_unique<Array<PrivatePropertyDescriptor>>();
if (!value->IsObject()) return Response::OK();
......@@ -384,10 +386,10 @@ Response InjectedScript::getInternalAndPrivateProperties(
groupName, remoteObject.get());
if (!response.isSuccess()) return response;
(*internalProperties)
->addItem(InternalPropertyDescriptor::create()
.setName(internalProperty.name)
.setValue(std::move(remoteObject))
.build());
->emplace_back(InternalPropertyDescriptor::create()
.setName(internalProperty.name)
.setValue(std::move(remoteObject))
.build());
}
std::vector<PrivatePropertyMirror> privatePropertyWrappers =
ValueMirror::getPrivateProperties(m_context->context(), value_obj);
......@@ -401,10 +403,10 @@ Response InjectedScript::getInternalAndPrivateProperties(
groupName, remoteObject.get());
if (!response.isSuccess()) return response;
(*privateProperties)
->addItem(PrivatePropertyDescriptor::create()
.setName(privateProperty.name)
.setValue(std::move(remoteObject))
.build());
->emplace_back(PrivatePropertyDescriptor::create()
.setName(privateProperty.name)
.setValue(std::move(remoteObject))
.build());
}
return Response::OK();
}
......@@ -487,7 +489,6 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
&limit, &limit, &preview);
if (!preview) return nullptr;
Array<PropertyPreview>* columns = preview->getProperties();
std::unordered_set<String16> selectedColumns;
v8::Local<v8::Array> v8Columns;
if (maybeColumns.ToLocal(&v8Columns)) {
......@@ -500,18 +501,17 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
}
}
if (!selectedColumns.empty()) {
for (size_t i = 0; i < columns->length(); ++i) {
ObjectPreview* columnPreview = columns->get(i)->getValuePreview(nullptr);
for (const std::unique_ptr<PropertyPreview>& column :
*preview->getProperties()) {
ObjectPreview* columnPreview = column->getValuePreview(nullptr);
if (!columnPreview) continue;
std::unique_ptr<Array<PropertyPreview>> filtered =
Array<PropertyPreview>::create();
Array<PropertyPreview>* columns = columnPreview->getProperties();
for (size_t j = 0; j < columns->length(); ++j) {
PropertyPreview* property = columns->get(j);
auto filtered = v8::base::make_unique<Array<PropertyPreview>>();
for (const std::unique_ptr<PropertyPreview>& property :
*columnPreview->getProperties()) {
if (selectedColumns.find(property->getName()) !=
selectedColumns.end()) {
filtered->addItem(property->clone());
filtered->emplace_back(property->clone());
}
}
columnPreview->setProperties(std::move(filtered));
......
......@@ -257,8 +257,8 @@ V8ConsoleMessage::wrapArguments(V8InspectorSessionImpl* session,
v8::HandleScope handles(isolate);
v8::Local<v8::Context> context = inspectedContext->context();
std::unique_ptr<protocol::Array<protocol::Runtime::RemoteObject>> args =
protocol::Array<protocol::Runtime::RemoteObject>::create();
auto args =
v8::base::make_unique<protocol::Array<protocol::Runtime::RemoteObject>>();
v8::Local<v8::Value> value = m_arguments[0]->Get(isolate);
if (value->IsObject() && m_type == ConsoleAPIType::kTable &&
......@@ -282,7 +282,7 @@ V8ConsoleMessage::wrapArguments(V8InspectorSessionImpl* session,
inspectedContext = inspector->getContext(contextGroupId, contextId);
if (!inspectedContext) return nullptr;
if (wrapped) {
args->addItem(std::move(wrapped));
args->emplace_back(std::move(wrapped));
} else {
args = nullptr;
}
......@@ -297,7 +297,7 @@ V8ConsoleMessage::wrapArguments(V8InspectorSessionImpl* session,
args = nullptr;
break;
}
args->addItem(std::move(wrapped));
args->emplace_back(std::move(wrapped));
}
}
return args;
......@@ -341,14 +341,15 @@ void V8ConsoleMessage::reportToFrontend(protocol::Runtime::Frontend* frontend,
arguments = wrapArguments(session, generatePreview);
if (!inspector->hasConsoleMessageStorage(contextGroupId)) return;
if (!arguments) {
arguments = protocol::Array<protocol::Runtime::RemoteObject>::create();
arguments = v8::base::make_unique<
protocol::Array<protocol::Runtime::RemoteObject>>();
if (!m_message.isEmpty()) {
std::unique_ptr<protocol::Runtime::RemoteObject> messageArg =
protocol::Runtime::RemoteObject::create()
.setType(protocol::Runtime::RemoteObject::TypeEnum::String)
.build();
messageArg->setValue(protocol::StringValue::create(m_message));
arguments->addItem(std::move(messageArg));
arguments->emplace_back(std::move(messageArg));
}
}
Maybe<String16> consoleContext;
......
......@@ -262,7 +262,7 @@ String16 scopeType(v8::debug::ScopeIterator::ScopeType type) {
Response buildScopes(v8::Isolate* isolate, v8::debug::ScopeIterator* iterator,
InjectedScript* injectedScript,
std::unique_ptr<Array<Scope>>* scopes) {
*scopes = Array<Scope>::create();
*scopes = v8::base::make_unique<Array<Scope>>();
if (!injectedScript) return Response::OK();
if (iterator->Done()) return Response::OK();
......@@ -299,7 +299,7 @@ Response buildScopes(v8::Isolate* isolate, v8::debug::ScopeIterator* iterator,
.setColumnNumber(end.GetColumnNumber())
.build());
}
(*scopes)->addItem(std::move(scope));
(*scopes)->emplace_back(std::move(scope));
}
return Response::OK();
}
......@@ -472,7 +472,7 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(
Maybe<int> optionalColumnNumber, Maybe<String16> optionalCondition,
String16* outBreakpointId,
std::unique_ptr<protocol::Array<protocol::Debugger::Location>>* locations) {
*locations = Array<protocol::Debugger::Location>::create();
*locations = v8::base::make_unique<Array<protocol::Debugger::Location>>();
int specified = (optionalURL.isJust() ? 1 : 0) +
(optionalURLRegex.isJust() ? 1 : 0) +
......@@ -539,7 +539,7 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(
if (location && type != BreakpointType::kByUrlRegex) {
hint = breakpointHint(*script.second, lineNumber, columnNumber);
}
if (location) (*locations)->addItem(std::move(location));
if (location) (*locations)->emplace_back(std::move(location));
}
breakpoints->setString(breakpointId, condition);
if (!hint.isEmpty()) {
......@@ -708,7 +708,8 @@ Response V8DebuggerAgentImpl::getPossibleBreakpoints(
v8Start, v8End, restrictToFunction.fromMaybe(false), &v8Locations);
}
*locations = protocol::Array<protocol::Debugger::BreakLocation>::create();
*locations = v8::base::make_unique<
protocol::Array<protocol::Debugger::BreakLocation>>();
for (size_t i = 0; i < v8Locations.size(); ++i) {
std::unique_ptr<protocol::Debugger::BreakLocation> breakLocation =
protocol::Debugger::BreakLocation::create()
......@@ -719,7 +720,7 @@ Response V8DebuggerAgentImpl::getPossibleBreakpoints(
if (v8Locations[i].type() != v8::debug::kCommonBreakLocation) {
breakLocation->setType(breakLocationType(v8Locations[i].type()));
}
(*locations)->addItem(std::move(breakLocation));
(*locations)->emplace_back(std::move(breakLocation));
}
return Response::OK();
}
......@@ -871,13 +872,11 @@ Response V8DebuggerAgentImpl::searchInContent(
if (it == m_scripts.end())
return Response::Error("No script for id: " + scriptId);
std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches =
searchInTextByLinesImpl(m_session, it->second->source(0), query,
optionalCaseSensitive.fromMaybe(false),
optionalIsRegex.fromMaybe(false));
*results = protocol::Array<protocol::Debugger::SearchMatch>::create();
for (size_t i = 0; i < matches.size(); ++i)
(*results)->addItem(std::move(matches[i]));
*results =
v8::base::make_unique<protocol::Array<protocol::Debugger::SearchMatch>>(
searchInTextByLinesImpl(m_session, it->second->source(0), query,
optionalCaseSensitive.fromMaybe(false),
optionalIsRegex.fromMaybe(false)));
return Response::OK();
}
......@@ -1190,7 +1189,7 @@ Response V8DebuggerAgentImpl::setAsyncCallStackDepth(int depth) {
Response V8DebuggerAgentImpl::setBlackboxPatterns(
std::unique_ptr<protocol::Array<String16>> patterns) {
if (!patterns->length()) {
if (patterns->empty()) {
m_blackboxPattern = nullptr;
resetBlackboxedStateCache();
m_state->remove(DebuggerAgentState::blackboxPattern);
......@@ -1199,11 +1198,11 @@ Response V8DebuggerAgentImpl::setBlackboxPatterns(
String16Builder patternBuilder;
patternBuilder.append('(');
for (size_t i = 0; i < patterns->length() - 1; ++i) {
patternBuilder.append(patterns->get(i));
for (size_t i = 0; i < patterns->size() - 1; ++i) {
patternBuilder.append((*patterns)[i]);
patternBuilder.append("|");
}
patternBuilder.append(patterns->get(patterns->length() - 1));
patternBuilder.append(patterns->back());
patternBuilder.append(')');
String16 pattern = patternBuilder.toString();
Response response = setBlackboxPattern(pattern);
......@@ -1236,16 +1235,16 @@ Response V8DebuggerAgentImpl::setBlackboxedRanges(
if (it == m_scripts.end())
return Response::Error("No script with passed id.");
if (!inPositions->length()) {
if (inPositions->empty()) {
m_blackboxedPositions.erase(scriptId);
it->second->resetBlackboxedStateCache();
return Response::OK();
}
std::vector<std::pair<int, int>> positions;
positions.reserve(inPositions->length());
for (size_t i = 0; i < inPositions->length(); ++i) {
protocol::Debugger::ScriptPosition* position = inPositions->get(i);
positions.reserve(inPositions->size());
for (const std::unique_ptr<protocol::Debugger::ScriptPosition>& position :
*inPositions) {
if (position->getLineNumber() < 0)
return Response::Error("Position missing 'line' or 'line' < 0.");
if (position->getColumnNumber() < 0)
......@@ -1271,11 +1270,11 @@ Response V8DebuggerAgentImpl::setBlackboxedRanges(
Response V8DebuggerAgentImpl::currentCallFrames(
std::unique_ptr<Array<CallFrame>>* result) {
if (!isPaused()) {
*result = Array<CallFrame>::create();
*result = v8::base::make_unique<Array<CallFrame>>();
return Response::OK();
}
v8::HandleScope handles(m_isolate);
*result = Array<CallFrame>::create();
*result = v8::base::make_unique<Array<CallFrame>>();
auto iterator = v8::debug::StackTraceIterator::Create(m_isolate);
int frameOrdinal = 0;
for (; !iterator->Done(); iterator->Advance(), frameOrdinal++) {
......@@ -1354,7 +1353,7 @@ Response V8DebuggerAgentImpl::currentCallFrames(
if (!res.isSuccess()) return res;
frame->setReturnValue(std::move(value));
}
(*result)->addItem(std::move(frame));
(*result)->emplace_back(std::move(frame));
}
return Response::OK();
}
......@@ -1603,7 +1602,7 @@ void V8DebuggerAgentImpl::didPause(
}
}
std::unique_ptr<Array<String16>> hitBreakpointIds = Array<String16>::create();
auto hitBreakpointIds = v8::base::make_unique<Array<String16>>();
for (const auto& id : hitBreakpoints) {
auto it = m_breakpointsOnScriptRun.find(id);
......@@ -1619,7 +1618,7 @@ void V8DebuggerAgentImpl::didPause(
continue;
}
const String16& breakpointId = breakpointIterator->second;
hitBreakpointIds->addItem(breakpointId);
hitBreakpointIds->emplace_back(breakpointId);
BreakpointType type;
parseBreakpointId(breakpointId, &type);
if (type != BreakpointType::kDebugCommand) continue;
......@@ -1655,7 +1654,8 @@ void V8DebuggerAgentImpl::didPause(
std::unique_ptr<Array<CallFrame>> protocolCallFrames;
Response response = currentCallFrames(&protocolCallFrames);
if (!response.isSuccess()) protocolCallFrames = Array<CallFrame>::create();
if (!response.isSuccess())
protocolCallFrames = v8::base::make_unique<Array<CallFrame>>();
m_frontend.paused(std::move(protocolCallFrames), breakReason,
std::move(breakAuxData), std::move(hitBreakpointIds),
......
......@@ -4,6 +4,7 @@
#include "src/inspector/v8-heap-profiler-agent-impl.h"
#include "src/base/template-utils.h"
#include "src/inspector/injected-script.h"
#include "src/inspector/inspected-context.h"
#include "src/inspector/protocol/Protocol.h"
......@@ -127,12 +128,11 @@ class HeapStatsStream final : public v8::OutputStream {
WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData,
int count) override {
DCHECK_GT(count, 0);
std::unique_ptr<protocol::Array<int>> statsDiff =
protocol::Array<int>::create();
auto statsDiff = v8::base::make_unique<protocol::Array<int>>();
for (int i = 0; i < count; ++i) {
statsDiff->addItem(updateData[i].index);
statsDiff->addItem(updateData[i].count);
statsDiff->addItem(updateData[i].size);
statsDiff->emplace_back(updateData[i].index);
statsDiff->emplace_back(updateData[i].count);
statsDiff->emplace_back(updateData[i].size);
}
m_frontend->heapStatsUpdate(std::move(statsDiff));
return kContinue;
......@@ -337,10 +337,10 @@ namespace {
std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode>
buildSampingHeapProfileNode(v8::Isolate* isolate,
const v8::AllocationProfile::Node* node) {
auto children = protocol::Array<
protocol::HeapProfiler::SamplingHeapProfileNode>::create();
auto children = v8::base::make_unique<
protocol::Array<protocol::HeapProfiler::SamplingHeapProfileNode>>();
for (const auto* child : node->children)
children->addItem(buildSampingHeapProfileNode(isolate, child));
children->emplace_back(buildSampingHeapProfileNode(isolate, child));
size_t selfSize = 0;
for (const auto& allocation : node->allocations)
selfSize += allocation.size * allocation.count;
......@@ -384,14 +384,15 @@ Response V8HeapProfilerAgentImpl::getSamplingProfile(
if (!v8Profile)
return Response::Error("V8 sampling heap profiler was not started.");
v8::AllocationProfile::Node* root = v8Profile->GetRootNode();
auto samples = protocol::Array<
protocol::HeapProfiler::SamplingHeapProfileSample>::create();
auto samples = v8::base::make_unique<
protocol::Array<protocol::HeapProfiler::SamplingHeapProfileSample>>();
for (const auto& sample : v8Profile->GetSamples()) {
samples->addItem(protocol::HeapProfiler::SamplingHeapProfileSample::create()
.setSize(sample.size * sample.count)
.setNodeId(sample.node_id)
.setOrdinal(static_cast<double>(sample.sample_id))
.build());
samples->emplace_back(
protocol::HeapProfiler::SamplingHeapProfileSample::create()
.setSize(sample.size * sample.count)
.setNodeId(sample.node_id)
.setOrdinal(static_cast<double>(sample.sample_id))
.build());
}
*profile = protocol::HeapProfiler::SamplingHeapProfile::create()
.setHead(buildSampingHeapProfileNode(m_isolate, root))
......
......@@ -44,7 +44,8 @@ std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>>
buildInspectorObjectForPositionTicks(const v8::CpuProfileNode* node) {
unsigned lineCount = node->GetHitLineCount();
if (!lineCount) return nullptr;
auto array = protocol::Array<protocol::Profiler::PositionTickInfo>::create();
auto array = v8::base::make_unique<
protocol::Array<protocol::Profiler::PositionTickInfo>>();
std::vector<v8::CpuProfileNode::LineTick> entries(lineCount);
if (node->GetLineTicks(&entries[0], lineCount)) {
for (unsigned i = 0; i < lineCount; i++) {
......@@ -53,7 +54,7 @@ buildInspectorObjectForPositionTicks(const v8::CpuProfileNode* node) {
.setLine(entries[i].line)
.setTicks(entries[i].hit_count)
.build();
array->addItem(std::move(line));
array->emplace_back(std::move(line));
}
}
return array;
......@@ -79,9 +80,9 @@ std::unique_ptr<protocol::Profiler::ProfileNode> buildInspectorObjectFor(
const int childrenCount = node->GetChildrenCount();
if (childrenCount) {
auto children = protocol::Array<int>::create();
auto children = v8::base::make_unique<protocol::Array<int>>();
for (int i = 0; i < childrenCount; i++)
children->addItem(node->GetChild(i)->GetNodeId());
children->emplace_back(node->GetChild(i)->GetNodeId());
result->setChildren(std::move(children));
}
......@@ -97,21 +98,21 @@ std::unique_ptr<protocol::Profiler::ProfileNode> buildInspectorObjectFor(
std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(
v8::CpuProfile* v8profile) {
auto array = protocol::Array<int>::create();
auto array = v8::base::make_unique<protocol::Array<int>>();
int count = v8profile->GetSamplesCount();
for (int i = 0; i < count; i++)
array->addItem(v8profile->GetSample(i)->GetNodeId());
array->emplace_back(v8profile->GetSample(i)->GetNodeId());
return array;
}
std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(
v8::CpuProfile* v8profile) {
auto array = protocol::Array<int>::create();
auto array = v8::base::make_unique<protocol::Array<int>>();
int count = v8profile->GetSamplesCount();
uint64_t lastTime = v8profile->GetStartTime();
for (int i = 0; i < count; i++) {
uint64_t ts = v8profile->GetSampleTimestamp(i);
array->addItem(static_cast<int>(ts - lastTime));
array->emplace_back(static_cast<int>(ts - lastTime));
lastTime = ts;
}
return array;
......@@ -120,7 +121,7 @@ std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(
void flattenNodesTree(V8InspectorImpl* inspector,
const v8::CpuProfileNode* node,
protocol::Array<protocol::Profiler::ProfileNode>* list) {
list->addItem(buildInspectorObjectFor(inspector, node));
list->emplace_back(buildInspectorObjectFor(inspector, node));
const int childrenCount = node->GetChildrenCount();
for (int i = 0; i < childrenCount; i++)
flattenNodesTree(inspector, node->GetChild(i), list);
......@@ -128,7 +129,8 @@ void flattenNodesTree(V8InspectorImpl* inspector,
std::unique_ptr<protocol::Profiler::Profile> createCPUProfile(
V8InspectorImpl* inspector, v8::CpuProfile* v8profile) {
auto nodes = protocol::Array<protocol::Profiler::ProfileNode>::create();
auto nodes =
v8::base::make_unique<protocol::Array<protocol::Profiler::ProfileNode>>();
flattenNodesTree(inspector, v8profile->GetTopDownRoot(), nodes.get());
return protocol::Profiler::Profile::create()
.setNodes(std::move(nodes))
......@@ -336,36 +338,35 @@ Response coverageToProtocol(
V8InspectorImpl* inspector, const v8::debug::Coverage& coverage,
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>*
out_result) {
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>> result =
protocol::Array<protocol::Profiler::ScriptCoverage>::create();
auto result = v8::base::make_unique<
protocol::Array<protocol::Profiler::ScriptCoverage>>();
v8::Isolate* isolate = inspector->isolate();
for (size_t i = 0; i < coverage.ScriptCount(); i++) {
v8::debug::Coverage::ScriptData script_data = coverage.GetScriptData(i);
v8::Local<v8::debug::Script> script = script_data.GetScript();
std::unique_ptr<protocol::Array<protocol::Profiler::FunctionCoverage>>
functions =
protocol::Array<protocol::Profiler::FunctionCoverage>::create();
auto functions = v8::base::make_unique<
protocol::Array<protocol::Profiler::FunctionCoverage>>();
for (size_t j = 0; j < script_data.FunctionCount(); j++) {
v8::debug::Coverage::FunctionData function_data =
script_data.GetFunctionData(j);
std::unique_ptr<protocol::Array<protocol::Profiler::CoverageRange>>
ranges = protocol::Array<protocol::Profiler::CoverageRange>::create();
auto ranges = v8::base::make_unique<
protocol::Array<protocol::Profiler::CoverageRange>>();
// Add function range.
ranges->addItem(createCoverageRange(function_data.StartOffset(),
function_data.EndOffset(),
function_data.Count()));
ranges->emplace_back(createCoverageRange(function_data.StartOffset(),
function_data.EndOffset(),
function_data.Count()));
// Process inner blocks.
for (size_t k = 0; k < function_data.BlockCount(); k++) {
v8::debug::Coverage::BlockData block_data =
function_data.GetBlockData(k);
ranges->addItem(createCoverageRange(block_data.StartOffset(),
block_data.EndOffset(),
block_data.Count()));
ranges->emplace_back(createCoverageRange(block_data.StartOffset(),
block_data.EndOffset(),
block_data.Count()));
}
functions->addItem(
functions->emplace_back(
protocol::Profiler::FunctionCoverage::create()
.setFunctionName(toProtocolString(
isolate,
......@@ -381,11 +382,11 @@ Response coverageToProtocol(
} else if (script->Name().ToLocal(&name) && name->Length()) {
url = resourceNameToUrl(inspector, name);
}
result->addItem(protocol::Profiler::ScriptCoverage::create()
.setScriptId(String16::fromInteger(script->Id()))
.setUrl(url)
.setFunctions(std::move(functions))
.build());
result->emplace_back(protocol::Profiler::ScriptCoverage::create()
.setScriptId(String16::fromInteger(script->Id()))
.setUrl(url)
.setFunctions(std::move(functions))
.build());
}
*out_result = std::move(result);
return Response::OK();
......@@ -417,31 +418,30 @@ namespace {
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>
typeProfileToProtocol(V8InspectorImpl* inspector,
const v8::debug::TypeProfile& type_profile) {
std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>
result = protocol::Array<protocol::Profiler::ScriptTypeProfile>::create();
auto result = v8::base::make_unique<
protocol::Array<protocol::Profiler::ScriptTypeProfile>>();
v8::Isolate* isolate = inspector->isolate();
for (size_t i = 0; i < type_profile.ScriptCount(); i++) {
v8::debug::TypeProfile::ScriptData script_data =
type_profile.GetScriptData(i);
v8::Local<v8::debug::Script> script = script_data.GetScript();
std::unique_ptr<protocol::Array<protocol::Profiler::TypeProfileEntry>>
entries =
protocol::Array<protocol::Profiler::TypeProfileEntry>::create();
auto entries = v8::base::make_unique<
protocol::Array<protocol::Profiler::TypeProfileEntry>>();
for (const auto& entry : script_data.Entries()) {
std::unique_ptr<protocol::Array<protocol::Profiler::TypeObject>> types =
protocol::Array<protocol::Profiler::TypeObject>::create();
auto types = v8::base::make_unique<
protocol::Array<protocol::Profiler::TypeObject>>();
for (const auto& type : entry.Types()) {
types->addItem(
types->emplace_back(
protocol::Profiler::TypeObject::create()
.setName(toProtocolString(
isolate, type.FromMaybe(v8::Local<v8::String>())))
.build());
}
entries->addItem(protocol::Profiler::TypeProfileEntry::create()
.setOffset(entry.SourcePosition())
.setTypes(std::move(types))
.build());
entries->emplace_back(protocol::Profiler::TypeProfileEntry::create()
.setOffset(entry.SourcePosition())
.setTypes(std::move(types))
.build());
}
String16 url;
v8::Local<v8::String> name;
......@@ -450,11 +450,11 @@ typeProfileToProtocol(V8InspectorImpl* inspector,
} else if (script->Name().ToLocal(&name) && name->Length()) {
url = resourceNameToUrl(inspector, name);
}
result->addItem(protocol::Profiler::ScriptTypeProfile::create()
.setScriptId(String16::fromInteger(script->Id()))
.setUrl(url)
.setEntries(std::move(entries))
.build());
result->emplace_back(protocol::Profiler::ScriptTypeProfile::create()
.setScriptId(String16::fromInteger(script->Id()))
.setUrl(url)
.setEntries(std::move(entries))
.build());
}
return result;
}
......
......@@ -120,12 +120,12 @@ void innerCallFunctionOn(
if (optionalArguments.isJust()) {
protocol::Array<protocol::Runtime::CallArgument>* arguments =
optionalArguments.fromJust();
argc = static_cast<int>(arguments->length());
argc = static_cast<int>(arguments->size());
argv.reset(new v8::Local<v8::Value>[argc]);
for (int i = 0; i < argc; ++i) {
v8::Local<v8::Value> argumentValue;
Response response = scope.injectedScript()->resolveCallArgument(
arguments->get(i), &argumentValue);
(*arguments)[i].get(), &argumentValue);
if (!response.isSuccess()) {
callback->sendFailure(response);
return;
......@@ -419,9 +419,9 @@ Response V8RuntimeAgentImpl::getProperties(
object, scope.objectGroupName(), &internalPropertiesProtocolArray,
&privatePropertiesProtocolArray);
if (!response.isSuccess()) return response;
if (internalPropertiesProtocolArray->length())
if (!internalPropertiesProtocolArray->empty())
*internalProperties = std::move(internalPropertiesProtocolArray);
if (privatePropertiesProtocolArray->length())
if (!privatePropertiesProtocolArray->empty())
*privateProperties = std::move(privatePropertiesProtocolArray);
return Response::OK();
}
......@@ -612,9 +612,9 @@ Response V8RuntimeAgentImpl::globalLexicalScopeNames(
v8::PersistentValueVector<v8::String> names(m_inspector->isolate());
v8::debug::GlobalLexicalScopeNames(scope.context(), &names);
*outNames = protocol::Array<String16>::create();
*outNames = v8::base::make_unique<protocol::Array<String16>>();
for (size_t i = 0; i < names.Size(); ++i) {
(*outNames)->addItem(
(*outNames)->emplace_back(
toProtocolString(m_inspector->isolate(), names.Get(i)));
}
return Response::OK();
......
......@@ -4,6 +4,7 @@
#include "src/inspector/v8-schema-agent-impl.h"
#include "src/base/template-utils.h"
#include "src/inspector/protocol/Protocol.h"
#include "src/inspector/v8-inspector-session-impl.h"
......@@ -18,11 +19,9 @@ V8SchemaAgentImpl::~V8SchemaAgentImpl() = default;
Response V8SchemaAgentImpl::getDomains(
std::unique_ptr<protocol::Array<protocol::Schema::Domain>>* result) {
std::vector<std::unique_ptr<protocol::Schema::Domain>> domains =
m_session->supportedDomainsImpl();
*result = protocol::Array<protocol::Schema::Domain>::create();
for (size_t i = 0; i < domains.size(); ++i)
(*result)->addItem(std::move(domains[i]));
*result = v8::base::make_unique<
std::vector<std::unique_ptr<protocol::Schema::Domain>>>(
m_session->supportedDomainsImpl());
return Response::OK();
}
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include "src/base/template-utils.h"
#include "src/inspector/v8-debugger.h"
#include "src/inspector/v8-inspector-impl.h"
#include "src/inspector/wasm-translation.h"
......@@ -72,13 +73,13 @@ std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectCommon(
return asyncParent->buildInspectorObject(debugger, maxAsyncDepth);
}
std::unique_ptr<protocol::Array<protocol::Runtime::CallFrame>>
inspectorFrames = protocol::Array<protocol::Runtime::CallFrame>::create();
for (size_t i = 0; i < frames.size(); i++) {
auto inspectorFrames =
v8::base::make_unique<protocol::Array<protocol::Runtime::CallFrame>>();
for (const std::shared_ptr<StackFrame>& frame : frames) {
V8InspectorClient* client = nullptr;
if (debugger && debugger->inspector())
client = debugger->inspector()->client();
inspectorFrames->addItem(frames[i]->buildInspectorObject(client));
inspectorFrames->emplace_back(frame->buildInspectorObject(client));
}
std::unique_ptr<protocol::Runtime::StackTrace> stackTrace =
protocol::Runtime::StackTrace::create()
......
......@@ -351,7 +351,8 @@ class PrimitiveValueMirror final : public ValueMirror {
.setType(m_type)
.setDescription(descriptionForPrimitiveType(context, m_value))
.setOverflow(false)
.setProperties(protocol::Array<PropertyPreview>::create())
.setProperties(
v8::base::make_unique<protocol::Array<PropertyPreview>>())
.build();
if (m_value->IsNull())
(*preview)->setSubtype(RemoteObject::SubtypeEnum::Null);
......@@ -411,12 +412,14 @@ class NumberMirror final : public ValueMirror {
v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) const override {
bool unserializable = false;
*preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Number)
.setDescription(description(&unserializable))
.setOverflow(false)
.setProperties(protocol::Array<PropertyPreview>::create())
.build();
*preview =
ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Number)
.setDescription(description(&unserializable))
.setOverflow(false)
.setProperties(
v8::base::make_unique<protocol::Array<PropertyPreview>>())
.build();
}
private:
......@@ -467,12 +470,14 @@ class BigIntMirror final : public ValueMirror {
int* indexLimit,
std::unique_ptr<protocol::Runtime::ObjectPreview>*
preview) const override {
*preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Bigint)
.setDescription(descriptionForBigInt(context, m_value))
.setOverflow(false)
.setProperties(protocol::Array<PropertyPreview>::create())
.build();
*preview =
ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Bigint)
.setDescription(descriptionForBigInt(context, m_value))
.setOverflow(false)
.setProperties(
v8::base::make_unique<protocol::Array<PropertyPreview>>())
.build();
}
v8::Local<v8::Value> v8Value() const override { return m_value; }
......@@ -625,12 +630,14 @@ class FunctionMirror final : public ValueMirror {
void buildEntryPreview(
v8::Local<v8::Context> context, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* preview) const override {
*preview = ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Function)
.setDescription(descriptionForFunction(context, m_value))
.setOverflow(false)
.setProperties(protocol::Array<PropertyPreview>::create())
.build();
*preview =
ObjectPreview::create()
.setType(RemoteObject::TypeEnum::Function)
.setDescription(descriptionForFunction(context, m_value))
.setOverflow(false)
.setProperties(
v8::base::make_unique<protocol::Array<PropertyPreview>>())
.build();
}
private:
......@@ -824,7 +831,7 @@ void getPrivatePropertiesForPreview(
return;
}
--*nameLimit;
privateProperties->addItem(std::move(propertyPreview));
privateProperties->emplace_back(std::move(propertyPreview));
}
}
......@@ -911,8 +918,7 @@ class ObjectMirror final : public ValueMirror {
v8::Local<v8::Context> context, bool forEntry,
bool generatePreviewForTable, int* nameLimit, int* indexLimit,
std::unique_ptr<ObjectPreview>* result) const {
std::unique_ptr<protocol::Array<PropertyPreview>> properties =
protocol::Array<PropertyPreview>::create();
auto properties = v8::base::make_unique<protocol::Array<PropertyPreview>>();
std::unique_ptr<protocol::Array<EntryPreview>> entriesPreview;
bool overflow = false;
......@@ -929,7 +935,7 @@ class ObjectMirror final : public ValueMirror {
internalProperties[i].value->buildPropertyPreview(
context, internalProperties[i].name, &propertyPreview);
if (propertyPreview) {
properties->addItem(std::move(propertyPreview));
properties->emplace_back(std::move(propertyPreview));
}
}
......@@ -959,7 +965,7 @@ class ObjectMirror final : public ValueMirror {
if (valuePreview) {
preview->setValuePreview(std::move(valuePreview));
}
properties->addItem(std::move(preview));
properties->emplace_back(std::move(preview));
}
}
......@@ -969,7 +975,8 @@ class ObjectMirror final : public ValueMirror {
if (forEntry) {
overflow = true;
} else {
entriesPreview = protocol::Array<EntryPreview>::create();
entriesPreview =
v8::base::make_unique<protocol::Array<EntryPreview>>();
for (const auto& entry : entries) {
std::unique_ptr<ObjectPreview> valuePreview;
entry.value->buildEntryPreview(context, nameLimit, indexLimit,
......@@ -986,7 +993,7 @@ class ObjectMirror final : public ValueMirror {
.setValue(std::move(valuePreview))
.build();
if (keyPreview) entryPreview->setKey(std::move(keyPreview));
entriesPreview->addItem(std::move(entryPreview));
entriesPreview->emplace_back(std::move(entryPreview));
}
}
}
......
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 91eb1c8784ab3d88ca1e327ffa727d922dd2ce70
Revision: 83b1154a9661d22bba9a368d368214cc20880419
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -636,7 +636,6 @@ def main():
"Object_h.template",
"ValueConversions_h.template",
"Maybe_h.template",
"Array_h.template",
"DispatcherBase_h.template",
"Parser_h.template",
"encoding_h.template",
......
......@@ -36,7 +36,6 @@ template("inspector_protocol_generate") {
"$inspector_protocol_dir/lib/encoding_h.template",
"$inspector_protocol_dir/lib/encoding_cpp.template",
"$inspector_protocol_dir/lib/Allocator_h.template",
"$inspector_protocol_dir/lib/Array_h.template",
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_h.template",
"$inspector_protocol_dir/lib/ErrorSupport_cpp.template",
......
......@@ -8,7 +8,6 @@
'lib/encoding_h.template',
'lib/encoding_cpp.template',
'lib/Allocator_h.template',
'lib/Array_h.template',
'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template',
'lib/ErrorSupport_cpp.template',
......
// This file is generated by Array_h.template.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Array_h
#define {{"_".join(config.protocol.namespace)}}_Array_h
//#include "ErrorSupport.h"
//#include "Forward.h"
//#include "ValueConversions.h"
//#include "Values.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
template<typename T>
class Array {
public:
static std::unique_ptr<Array<T>> create()
{
return std::unique_ptr<Array<T>>(new Array<T>());
}
static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
{
protocol::ListValue* array = ListValue::cast(value);
if (!array) {
errors->addError("array expected");
return nullptr;
}
std::unique_ptr<Array<T>> result(new Array<T>());
errors->push();
for (size_t i = 0; i < array->size(); ++i) {
errors->setName(StringUtil::fromInteger(i));
std::unique_ptr<T> item = ValueConversions<T>::fromValue(array->at(i), errors);
result->m_vector.push_back(std::move(item));
}
errors->pop();
if (errors->hasErrors())
return nullptr;
return result;
}
void addItem(std::unique_ptr<T> value)
{
m_vector.push_back(std::move(value));
}
size_t length()
{
return m_vector.size();
}
T* get(size_t index)
{
return m_vector[index].get();
}
std::unique_ptr<protocol::ListValue> toValue()
{
std::unique_ptr<protocol::ListValue> result = ListValue::create();
for (auto& item : m_vector)
result->pushValue(ValueConversions<T>::toValue(item));
return result;
}
private:
std::vector<std::unique_ptr<T>> m_vector;
};
template<typename T>
class ArrayBase {
public:
static std::unique_ptr<Array<T>> create()
{
return std::unique_ptr<Array<T>>(new Array<T>());
}
static std::unique_ptr<Array<T>> fromValue(protocol::Value* value, ErrorSupport* errors)
{
protocol::ListValue* array = ListValue::cast(value);
if (!array) {
errors->addError("array expected");
return nullptr;
}
errors->push();
std::unique_ptr<Array<T>> result(new Array<T>());
for (size_t i = 0; i < array->size(); ++i) {
errors->setName(StringUtil::fromInteger(i));
T item = ValueConversions<T>::fromValue(array->at(i), errors);
result->m_vector.push_back(item);
}
errors->pop();
if (errors->hasErrors())
return nullptr;
return result;
}
void addItem(const T& value)
{
m_vector.push_back(value);
}
size_t length()
{
return m_vector.size();
}
T get(size_t index)
{
return m_vector[index];
}
std::unique_ptr<protocol::ListValue> toValue()
{
std::unique_ptr<protocol::ListValue> result = ListValue::create();
for (auto& item : m_vector)
result->pushValue(ValueConversions<T>::toValue(item));
return result;
}
private:
std::vector<T> m_vector;
};
template<> class Array<String> : public ArrayBase<String> {};
template<> class Array<int> : public ArrayBase<int> {};
template<> class Array<double> : public ArrayBase<double> {};
template<> class Array<bool> : public ArrayBase<bool> {};
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Array_h)
......@@ -22,7 +22,6 @@
namespace {{namespace}} {
{% endfor %}
template<typename T> class Array;
class DictionaryValue;
class DispatchResponse;
class ErrorSupport;
......@@ -35,6 +34,26 @@ class StringValue;
class UberDispatcher;
class Value;
namespace detail {
template <typename T>
struct ArrayTypedef { typedef std::vector<std::unique_ptr<T>> type; };
template <>
struct ArrayTypedef<String> { typedef std::vector<String> type; };
template <>
struct ArrayTypedef<int> { typedef std::vector<int> type; };
template <>
struct ArrayTypedef<double> { typedef std::vector<double> type; };
template <>
struct ArrayTypedef<bool> { typedef std::vector<bool> type; };
} // namespace detail
template <typename T>
using Array = typename detail::ArrayTypedef<T>::type;
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
......
......@@ -128,6 +128,72 @@ struct ValueConversions<Binary> {
}
};
template<typename T>
struct ValueConversions<std::vector<std::unique_ptr<T>>> {
static std::unique_ptr<std::vector<std::unique_ptr<T>>> fromValue(protocol::Value* value, ErrorSupport* errors) {
protocol::ListValue* array = ListValue::cast(value);
if (!array) {
errors->addError("array expected");
return nullptr;
}
errors->push();
std::unique_ptr<std::vector<std::unique_ptr<T>>> result(
new std::vector<std::unique_ptr<T>>());
result->reserve(array->size());
for (size_t i = 0; i < array->size(); ++i) {
errors->setName(StringUtil::fromInteger(i));
auto item = ValueConversions<T>::fromValue(array->at(i), errors);
result->emplace_back(std::move(item));
}
errors->pop();
if (errors->hasErrors())
return nullptr;
return result;
}
static std::unique_ptr<protocol::ListValue> toValue(std::vector<std::unique_ptr<T>>* v)
{
std::unique_ptr<protocol::ListValue> result = ListValue::create();
result->reserve(v->size());
for (auto& item : *v)
result->pushValue(ValueConversions<T>::toValue(item.get()));
return result;
}
};
template<typename T>
struct ValueConversions<std::vector<T>> {
static std::unique_ptr<std::vector<T>> fromValue(protocol::Value* value, ErrorSupport* errors) {
protocol::ListValue* array = ListValue::cast(value);
if (!array) {
errors->addError("array expected");
return nullptr;
}
errors->push();
std::unique_ptr<std::vector<T>> result(new std::vector<T>());
result->reserve(array->size());
for (size_t i = 0; i < array->size(); ++i) {
errors->setName(StringUtil::fromInteger(i));
auto item = ValueConversions<T>::fromValue(array->at(i), errors);
result->emplace_back(std::move(item));
}
errors->pop();
if (errors->hasErrors())
return nullptr;
return result;
}
static std::unique_ptr<protocol::ListValue> toValue(std::vector<T>* v)
{
std::unique_ptr<protocol::ListValue> result = ListValue::create();
result->reserve(v->size());
for (auto& item : *v)
result->pushValue(ValueConversions<T>::toValue(item));
return result;
}
};
template<>
struct ValueConversions<Value> {
static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
......
......@@ -271,6 +271,7 @@ public:
Value* at(size_t index);
size_t size() const { return m_data.size(); }
void reserve(size_t capacity) { m_data.reserve(capacity); }
private:
ListValue();
......
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