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