Commit 211a6a86 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

Roll third_party/inspector_protocol to 73028acaa3646789fd2a3bfd0d79eb2d91b696b3

This roll includes:
  - Support config.protocol.options which defines which part of protocol definition should be generated. [1]
  - [inspector_protocol] Allow custom json parser. [2]
  - [inspector_protocol] Allow overriding specific config values. [3]
  - [inspector_protocol] Fix NoneType error when parsing config_values. [4]
  - [inspector_protocol] Support chromium code style. [5]
  - [inspector_protocol] Support features for content/ generator. [6]
  - [inspector_protocol] Fixed domain_json["has_exports"] flag for exported domains [7]

[1] https://codereview.chromium.org/2482993002
[2] https://codereview.chromium.org/2490733002
[3] https://codereview.chromium.org/2482093004
[4] https://codereview.chromium.org/2490823002
[5] https://codereview.chromium.org/2495353004
[6] https://codereview.chromium.org/2509573006
[7] https://codereview.chromium.org/2515343005

BUG=none
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2523743003
Cr-Commit-Position: refs/heads/master@{#41195}
parent 292c4a0a
...@@ -140,7 +140,6 @@ v8_source_set("inspector") { ...@@ -140,7 +140,6 @@ v8_source_set("inspector") {
"inspected-context.h", "inspected-context.h",
"java-script-call-frame.cc", "java-script-call-frame.cc",
"java-script-call-frame.h", "java-script-call-frame.h",
"protocol-platform.h",
"remote-object-id.cc", "remote-object-id.cc",
"remote-object-id.h", "remote-object-id.h",
"script-breakpoint.h", "script-breakpoint.h",
......
...@@ -44,8 +44,8 @@ int InjectedScriptNative::bind(v8::Local<v8::Value> value, ...@@ -44,8 +44,8 @@ int InjectedScriptNative::bind(v8::Local<v8::Value> value,
const String16& groupName) { const String16& groupName) {
if (m_lastBoundObjectId <= 0) m_lastBoundObjectId = 1; if (m_lastBoundObjectId <= 0) m_lastBoundObjectId = 1;
int id = m_lastBoundObjectId++; int id = m_lastBoundObjectId++;
m_idToWrappedObject[id] = m_idToWrappedObject[id] = std::unique_ptr<v8::Global<v8::Value>>(
wrapUnique(new v8::Global<v8::Value>(m_isolate, value)); new v8::Global<v8::Value>(m_isolate, value));
addObjectToGroup(id, groupName); addObjectToGroup(id, groupName);
return id; return id;
} }
......
...@@ -105,8 +105,8 @@ std::unique_ptr<InjectedScript> InjectedScript::create( ...@@ -105,8 +105,8 @@ std::unique_ptr<InjectedScript> InjectedScript::create(
if (inspector->getContext(contextGroupId, contextId) != inspectedContext) if (inspector->getContext(contextGroupId, contextId) != inspectedContext)
return nullptr; return nullptr;
if (!injectedScriptValue->IsObject()) return nullptr; if (!injectedScriptValue->IsObject()) return nullptr;
return wrapUnique(new InjectedScript(inspectedContext, return std::unique_ptr<InjectedScript>(
injectedScriptValue.As<v8::Object>(), new InjectedScript(inspectedContext, injectedScriptValue.As<v8::Object>(),
std::move(injectedScriptNative))); std::move(injectedScriptNative)));
} }
...@@ -158,7 +158,7 @@ Response InjectedScript::getProperties( ...@@ -158,7 +158,7 @@ Response InjectedScript::getProperties(
void InjectedScript::releaseObject(const String16& objectId) { void InjectedScript::releaseObject(const String16& objectId) {
std::unique_ptr<protocol::Value> parsedObjectId = std::unique_ptr<protocol::Value> parsedObjectId =
protocol::parseJSON(objectId); protocol::StringUtil::parseJSON(objectId);
if (!parsedObjectId) return; if (!parsedObjectId) return;
protocol::DictionaryValue* object = protocol::DictionaryValue* object =
protocol::DictionaryValue::cast(parsedObjectId.get()); protocol::DictionaryValue::cast(parsedObjectId.get());
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
'inspector/inspected-context.h', 'inspector/inspected-context.h',
'inspector/java-script-call-frame.cc', 'inspector/java-script-call-frame.cc',
'inspector/java-script-call-frame.h', 'inspector/java-script-call-frame.h',
'inspector/protocol-platform.h',
'inspector/remote-object-id.cc', 'inspector/remote-object-id.cc',
'inspector/remote-object-id.h', 'inspector/remote-object-id.h',
'inspector/script-breakpoint.h', 'inspector/script-breakpoint.h',
......
...@@ -3,7 +3,28 @@ ...@@ -3,7 +3,28 @@
"path": "js_protocol.json", "path": "js_protocol.json",
"package": "src/inspector/protocol", "package": "src/inspector/protocol",
"output": "protocol", "output": "protocol",
"namespace": ["v8_inspector", "protocol"] "namespace": ["v8_inspector", "protocol"],
"options": [
{
"domain": "Schema"
},
{
"domain": "Runtime",
"async": ["evaluate", "awaitPromise", "callFunctionOn", "runScript"]
},
{
"domain": "Debugger"
},
{
"domain": "Console"
},
{
"domain": "Profiler"
},
{
"domain": "HeapProfiler"
}
]
}, },
"exported": { "exported": {
...@@ -19,7 +40,6 @@ ...@@ -19,7 +40,6 @@
"lib": { "lib": {
"package": "src/inspector/protocol", "package": "src/inspector/protocol",
"output": "protocol", "output": "protocol",
"string_header": "src/inspector/string-util.h", "string_header": "src/inspector/string-util.h"
"platform_header": "src/inspector/protocol-platform.h"
} }
} }
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
#ifndef V8_INSPECTOR_JAVASCRIPTCALLFRAME_H_ #ifndef V8_INSPECTOR_JAVASCRIPTCALLFRAME_H_
#define V8_INSPECTOR_JAVASCRIPTCALLFRAME_H_ #define V8_INSPECTOR_JAVASCRIPTCALLFRAME_H_
#include <memory>
#include <vector> #include <vector>
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/inspector/protocol-platform.h"
#include "include/v8.h" #include "include/v8.h"
...@@ -44,7 +44,8 @@ class JavaScriptCallFrame { ...@@ -44,7 +44,8 @@ class JavaScriptCallFrame {
public: public:
static std::unique_ptr<JavaScriptCallFrame> create( static std::unique_ptr<JavaScriptCallFrame> create(
v8::Local<v8::Context> debuggerContext, v8::Local<v8::Object> callFrame) { v8::Local<v8::Context> debuggerContext, v8::Local<v8::Object> callFrame) {
return wrapUnique(new JavaScriptCallFrame(debuggerContext, callFrame)); return std::unique_ptr<JavaScriptCallFrame>(
new JavaScriptCallFrame(debuggerContext, callFrame));
} }
~JavaScriptCallFrame(); ~JavaScriptCallFrame();
......
...@@ -211,7 +211,6 @@ ...@@ -211,7 +211,6 @@
"commands": [ "commands": [
{ {
"name": "evaluate", "name": "evaluate",
"async": true,
"parameters": [ "parameters": [
{ "name": "expression", "type": "string", "description": "Expression to evaluate." }, { "name": "expression", "type": "string", "description": "Expression to evaluate." },
{ "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }, { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." },
...@@ -231,7 +230,6 @@ ...@@ -231,7 +230,6 @@
}, },
{ {
"name": "awaitPromise", "name": "awaitPromise",
"async": true,
"parameters": [ "parameters": [
{ "name": "promiseObjectId", "$ref": "RemoteObjectId", "description": "Identifier of the promise." }, { "name": "promiseObjectId", "$ref": "RemoteObjectId", "description": "Identifier of the promise." },
{ "name": "returnByValue", "type": "boolean", "optional": true, "description": "Whether the result is expected to be a JSON object that should be sent by value." }, { "name": "returnByValue", "type": "boolean", "optional": true, "description": "Whether the result is expected to be a JSON object that should be sent by value." },
...@@ -245,7 +243,6 @@ ...@@ -245,7 +243,6 @@
}, },
{ {
"name": "callFunctionOn", "name": "callFunctionOn",
"async": true,
"parameters": [ "parameters": [
{ "name": "objectId", "$ref": "RemoteObjectId", "description": "Identifier of the object to call function on." }, { "name": "objectId", "$ref": "RemoteObjectId", "description": "Identifier of the object to call function on." },
{ "name": "functionDeclaration", "type": "string", "description": "Declaration of the function to call." }, { "name": "functionDeclaration", "type": "string", "description": "Declaration of the function to call." },
...@@ -333,7 +330,6 @@ ...@@ -333,7 +330,6 @@
}, },
{ {
"name": "runScript", "name": "runScript",
"async": true,
"parameters": [ "parameters": [
{ "name": "scriptId", "$ref": "ScriptId", "description": "Id of the script to run." }, { "name": "scriptId", "$ref": "ScriptId", "description": "Id of the script to run." },
{ "name": "executionContextId", "$ref": "ExecutionContextId", "optional": true, "description": "Specifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page." }, { "name": "executionContextId", "$ref": "ExecutionContextId", "optional": true, "description": "Specifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page." },
......
// Copyright 2016 the V8 project 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 V8_INSPECTOR_PROTOCOLPLATFORM_H_
#define V8_INSPECTOR_PROTOCOLPLATFORM_H_
#include <memory>
#include "src/base/logging.h"
namespace v8_inspector {
template <typename T>
std::unique_ptr<T> wrapUnique(T* ptr) {
return std::unique_ptr<T>(ptr);
}
} // namespace v8_inspector
#endif // V8_INSPECTOR_PROTOCOLPLATFORM_H_
...@@ -13,7 +13,8 @@ RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {} ...@@ -13,7 +13,8 @@ RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {}
std::unique_ptr<protocol::DictionaryValue> std::unique_ptr<protocol::DictionaryValue>
RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) { RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) {
std::unique_ptr<protocol::Value> parsedValue = protocol::parseJSON(objectId); std::unique_ptr<protocol::Value> parsedValue =
protocol::StringUtil::parseJSON(objectId);
if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject) if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject)
return nullptr; return nullptr;
......
...@@ -132,7 +132,8 @@ std::unique_ptr<V8Regex> createSearchRegex(V8InspectorImpl* inspector, ...@@ -132,7 +132,8 @@ std::unique_ptr<V8Regex> createSearchRegex(V8InspectorImpl* inspector,
const String16& query, const String16& query,
bool caseSensitive, bool isRegex) { bool caseSensitive, bool isRegex) {
String16 regexSource = isRegex ? query : createSearchRegexSource(query); String16 regexSource = isRegex ? query : createSearchRegexSource(query);
return wrapUnique(new V8Regex(inspector, regexSource, caseSensitive)); return std::unique_ptr<V8Regex>(
new V8Regex(inspector, regexSource, caseSensitive));
} }
} // namespace } // namespace
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <string> #include <string>
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/inspector/protocol-platform.h"
namespace v8_inspector { namespace v8_inspector {
......
...@@ -93,19 +93,20 @@ bool stringViewStartsWith(const StringView& string, const char* prefix) { ...@@ -93,19 +93,20 @@ bool stringViewStartsWith(const StringView& string, const char* prefix) {
namespace protocol { namespace protocol {
std::unique_ptr<protocol::Value> parseJSON(const StringView& string) { std::unique_ptr<protocol::Value> StringUtil::parseJSON(
const StringView& string) {
if (!string.length()) return nullptr; if (!string.length()) return nullptr;
if (string.is8Bit()) { if (string.is8Bit()) {
return protocol::parseJSON(string.characters8(), return parseJSONCharacters(string.characters8(),
static_cast<int>(string.length())); static_cast<int>(string.length()));
} }
return protocol::parseJSON(string.characters16(), return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length())); static_cast<int>(string.length()));
} }
std::unique_ptr<protocol::Value> parseJSON(const String16& string) { std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String16& string) {
if (!string.length()) return nullptr; if (!string.length()) return nullptr;
return protocol::parseJSON(string.characters16(), return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length())); static_cast<int>(string.length()));
} }
...@@ -119,7 +120,7 @@ std::unique_ptr<StringBuffer> StringBuffer::create(const StringView& string) { ...@@ -119,7 +120,7 @@ std::unique_ptr<StringBuffer> StringBuffer::create(const StringView& string) {
// static // static
std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) { std::unique_ptr<StringBufferImpl> StringBufferImpl::adopt(String16& string) {
return wrapUnique(new StringBufferImpl(string)); return std::unique_ptr<StringBufferImpl>(new StringBufferImpl(string));
} }
StringBufferImpl::StringBufferImpl(String16& string) { StringBufferImpl::StringBufferImpl(String16& string) {
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef V8_INSPECTOR_STRINGUTIL_H_ #ifndef V8_INSPECTOR_STRINGUTIL_H_
#define V8_INSPECTOR_STRINGUTIL_H_ #define V8_INSPECTOR_STRINGUTIL_H_
#include <memory>
#include "src/base/logging.h"
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/inspector/string-16.h" #include "src/inspector/string-16.h"
...@@ -33,11 +36,10 @@ class StringUtil { ...@@ -33,11 +36,10 @@ class StringUtil {
static void builderReserve(StringBuilder& builder, size_t capacity) { static void builderReserve(StringBuilder& builder, size_t capacity) {
builder.reserveCapacity(capacity); builder.reserveCapacity(capacity);
} }
static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
}; };
std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
std::unique_ptr<protocol::Value> parseJSON(const String16& json);
} // namespace protocol } // namespace protocol
v8::Local<v8::String> toV8String(v8::Isolate*, const String16&); v8::Local<v8::String> toV8String(v8::Isolate*, const String16&);
......
...@@ -361,7 +361,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI( ...@@ -361,7 +361,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
V8InspectorImpl* inspector = inspectedContext->inspector(); V8InspectorImpl* inspector = inspectedContext->inspector();
v8::Local<v8::Context> context = inspectedContext->context(); v8::Local<v8::Context> context = inspectedContext->context();
std::unique_ptr<V8ConsoleMessage> message = wrapUnique( std::unique_ptr<V8ConsoleMessage> message(
new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16())); new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16()));
if (stackTrace && !stackTrace->isEmpty()) { if (stackTrace && !stackTrace->isEmpty()) {
message->m_url = toString16(stackTrace->topSourceURL()); message->m_url = toString16(stackTrace->topSourceURL());
...@@ -372,8 +372,8 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI( ...@@ -372,8 +372,8 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
message->m_type = type; message->m_type = type;
message->m_contextId = contextId; message->m_contextId = contextId;
for (size_t i = 0; i < arguments.size(); ++i) for (size_t i = 0; i < arguments.size(); ++i)
message->m_arguments.push_back( message->m_arguments.push_back(std::unique_ptr<v8::Global<v8::Value>>(
wrapUnique(new v8::Global<v8::Value>(isolate, arguments.at(i)))); new v8::Global<v8::Value>(isolate, arguments.at(i))));
if (arguments.size()) if (arguments.size())
message->m_message = V8ValueStringBuilder::toString(arguments[0], context); message->m_message = V8ValueStringBuilder::toString(arguments[0], context);
...@@ -404,7 +404,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException( ...@@ -404,7 +404,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(
std::unique_ptr<V8StackTraceImpl> stackTrace, int scriptId, std::unique_ptr<V8StackTraceImpl> stackTrace, int scriptId,
v8::Isolate* isolate, const String16& message, int contextId, v8::Isolate* isolate, const String16& message, int contextId,
v8::Local<v8::Value> exception, unsigned exceptionId) { v8::Local<v8::Value> exception, unsigned exceptionId) {
std::unique_ptr<V8ConsoleMessage> consoleMessage = wrapUnique( std::unique_ptr<V8ConsoleMessage> consoleMessage(
new V8ConsoleMessage(V8MessageOrigin::kException, timestamp, message)); new V8ConsoleMessage(V8MessageOrigin::kException, timestamp, message));
consoleMessage->setLocation(url, lineNumber, columnNumber, consoleMessage->setLocation(url, lineNumber, columnNumber,
std::move(stackTrace), scriptId); std::move(stackTrace), scriptId);
...@@ -413,7 +413,8 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException( ...@@ -413,7 +413,8 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(
if (contextId && !exception.IsEmpty()) { if (contextId && !exception.IsEmpty()) {
consoleMessage->m_contextId = contextId; consoleMessage->m_contextId = contextId;
consoleMessage->m_arguments.push_back( consoleMessage->m_arguments.push_back(
wrapUnique(new v8::Global<v8::Value>(isolate, exception))); std::unique_ptr<v8::Global<v8::Value>>(
new v8::Global<v8::Value>(isolate, exception)));
} }
return consoleMessage; return consoleMessage;
} }
...@@ -422,7 +423,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException( ...@@ -422,7 +423,7 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(
std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForRevokedException( std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForRevokedException(
double timestamp, const String16& messageText, double timestamp, const String16& messageText,
unsigned revokedExceptionId) { unsigned revokedExceptionId) {
std::unique_ptr<V8ConsoleMessage> message = wrapUnique(new V8ConsoleMessage( std::unique_ptr<V8ConsoleMessage> message(new V8ConsoleMessage(
V8MessageOrigin::kRevokedException, timestamp, messageText)); V8MessageOrigin::kRevokedException, timestamp, messageText));
message->m_revokedExceptionId = revokedExceptionId; message->m_revokedExceptionId = revokedExceptionId;
return message; return message;
......
...@@ -1056,7 +1056,7 @@ void V8DebuggerAgentImpl::didParseSource( ...@@ -1056,7 +1056,7 @@ void V8DebuggerAgentImpl::didParseSource(
std::unique_ptr<protocol::DictionaryValue> executionContextAuxData; std::unique_ptr<protocol::DictionaryValue> executionContextAuxData;
if (!script->executionContextAuxData().isEmpty()) if (!script->executionContextAuxData().isEmpty())
executionContextAuxData = protocol::DictionaryValue::cast( executionContextAuxData = protocol::DictionaryValue::cast(
protocol::parseJSON(script->executionContextAuxData())); protocol::StringUtil::parseJSON(script->executionContextAuxData()));
bool isLiveEdit = script->isLiveEdit(); bool isLiveEdit = script->isLiveEdit();
bool hasSourceURL = script->hasSourceURL(); bool hasSourceURL = script->hasSourceURL();
String16 scriptId = script->scriptId(); String16 scriptId = script->scriptId();
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "src/inspector/v8-debugger-script.h" #include "src/inspector/v8-debugger-script.h"
#include "src/inspector/protocol-platform.h"
#include "src/inspector/string-util.h" #include "src/inspector/string-util.h"
namespace v8_inspector { namespace v8_inspector {
......
...@@ -130,8 +130,8 @@ void V8Debugger::getCompiledScripts( ...@@ -130,8 +130,8 @@ void V8Debugger::getCompiledScripts(
if (!script->ContextData().ToLocal(&v8ContextData)) continue; if (!script->ContextData().ToLocal(&v8ContextData)) continue;
String16 contextData = toProtocolString(v8ContextData); String16 contextData = toProtocolString(v8ContextData);
if (contextData.find(contextPrefix) != 0) continue; if (contextData.find(contextPrefix) != 0) continue;
result.push_back( result.push_back(std::unique_ptr<V8DebuggerScript>(
wrapUnique(new V8DebuggerScript(m_isolate, script, false))); new V8DebuggerScript(m_isolate, script, false)));
} }
} }
...@@ -354,7 +354,7 @@ Response V8Debugger::setScriptSource( ...@@ -354,7 +354,7 @@ Response V8Debugger::setScriptSource(
std::unique_ptr<v8::Context::Scope> contextScope; std::unique_ptr<v8::Context::Scope> contextScope;
if (!isPaused()) if (!isPaused())
contextScope = wrapUnique(new v8::Context::Scope(debuggerContext())); contextScope.reset(new v8::Context::Scope(debuggerContext()));
v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource, v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource,
v8Boolean(dryRun, m_isolate)}; v8Boolean(dryRun, m_isolate)};
...@@ -596,7 +596,8 @@ void V8Debugger::handleV8DebugEvent( ...@@ -596,7 +596,8 @@ void V8Debugger::handleV8DebugEvent(
m_wasmTranslation.AddScript(scriptWrapper.As<v8::Object>()); m_wasmTranslation.AddScript(scriptWrapper.As<v8::Object>());
} else if (m_ignoreScriptParsedEventsCounter == 0) { } else if (m_ignoreScriptParsedEventsCounter == 0) {
agent->didParseSource( agent->didParseSource(
wrapUnique(new V8DebuggerScript(m_isolate, script, inLiveEditScope)), std::unique_ptr<V8DebuggerScript>(
new V8DebuggerScript(m_isolate, script, inLiveEditScope)),
event == v8::AfterCompile); event == v8::AfterCompile);
} }
} else if (event == v8::Exception) { } else if (event == v8::Exception) {
......
...@@ -216,7 +216,7 @@ Response V8HeapProfilerAgentImpl::takeHeapSnapshot(Maybe<bool> reportProgress) { ...@@ -216,7 +216,7 @@ Response V8HeapProfilerAgentImpl::takeHeapSnapshot(Maybe<bool> reportProgress) {
if (!profiler) return Response::Error("Cannot access v8 heap profiler"); if (!profiler) return Response::Error("Cannot access v8 heap profiler");
std::unique_ptr<HeapSnapshotProgress> progress; std::unique_ptr<HeapSnapshotProgress> progress;
if (reportProgress.fromMaybe(false)) if (reportProgress.fromMaybe(false))
progress = wrapUnique(new HeapSnapshotProgress(&m_frontend)); progress.reset(new HeapSnapshotProgress(&m_frontend));
GlobalObjectNameResolver resolver(m_session); GlobalObjectNameResolver resolver(m_session);
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
...@@ -260,7 +260,8 @@ Response V8HeapProfilerAgentImpl::addInspectedHeapObject( ...@@ -260,7 +260,8 @@ Response V8HeapProfilerAgentImpl::addInspectedHeapObject(
if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject))
return Response::Error("Object is not available"); return Response::Error("Object is not available");
m_session->addInspectedObject(wrapUnique(new InspectableHeapObject(id))); m_session->addInspectedObject(
std::unique_ptr<InspectableHeapObject>(new InspectableHeapObject(id)));
return Response::OK(); return Response::OK();
} }
......
...@@ -45,7 +45,7 @@ namespace v8_inspector { ...@@ -45,7 +45,7 @@ namespace v8_inspector {
std::unique_ptr<V8Inspector> V8Inspector::create(v8::Isolate* isolate, std::unique_ptr<V8Inspector> V8Inspector::create(v8::Isolate* isolate,
V8InspectorClient* client) { V8InspectorClient* client) {
return wrapUnique(new V8InspectorImpl(isolate, client)); return std::unique_ptr<V8Inspector>(new V8InspectorImpl(isolate, client));
} }
V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate, V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate,
...@@ -163,11 +163,11 @@ V8ConsoleMessageStorage* V8InspectorImpl::ensureConsoleMessageStorage( ...@@ -163,11 +163,11 @@ V8ConsoleMessageStorage* V8InspectorImpl::ensureConsoleMessageStorage(
ConsoleStorageMap::iterator storageIt = ConsoleStorageMap::iterator storageIt =
m_consoleStorageMap.find(contextGroupId); m_consoleStorageMap.find(contextGroupId);
if (storageIt == m_consoleStorageMap.end()) if (storageIt == m_consoleStorageMap.end())
storageIt = storageIt = m_consoleStorageMap
m_consoleStorageMap
.insert(std::make_pair( .insert(std::make_pair(
contextGroupId, contextGroupId,
wrapUnique(new V8ConsoleMessageStorage(this, contextGroupId)))) std::unique_ptr<V8ConsoleMessageStorage>(
new V8ConsoleMessageStorage(this, contextGroupId))))
.first; .first;
return storageIt->second.get(); return storageIt->second.get();
} }
...@@ -217,15 +217,16 @@ void V8InspectorImpl::contextCreated(const V8ContextInfo& info) { ...@@ -217,15 +217,16 @@ void V8InspectorImpl::contextCreated(const V8ContextInfo& info) {
ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId); ContextsByGroupMap::iterator contextIt = m_contexts.find(info.contextGroupId);
if (contextIt == m_contexts.end()) if (contextIt == m_contexts.end())
contextIt = m_contexts contextIt = m_contexts
.insert(std::make_pair(info.contextGroupId, .insert(std::make_pair(
wrapUnique(new ContextByIdMap()))) info.contextGroupId,
std::unique_ptr<ContextByIdMap>(new ContextByIdMap())))
.first; .first;
const auto& contextById = contextIt->second; const auto& contextById = contextIt->second;
DCHECK(contextById->find(contextId) == contextById->cend()); DCHECK(contextById->find(contextId) == contextById->cend());
InspectedContext* context = new InspectedContext(this, info, contextId); InspectedContext* context = new InspectedContext(this, info, contextId);
(*contextById)[contextId] = wrapUnique(context); (*contextById)[contextId].reset(context);
SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId); SessionMap::iterator sessionIt = m_sessions.find(info.contextGroupId);
if (sessionIt != m_sessions.end()) if (sessionIt != m_sessions.end())
sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context); sessionIt->second->runtimeAgent()->reportExecutionContextCreated(context);
...@@ -291,8 +292,8 @@ unsigned V8InspectorImpl::exceptionThrown( ...@@ -291,8 +292,8 @@ unsigned V8InspectorImpl::exceptionThrown(
std::unique_ptr<V8StackTrace> stackTrace, int scriptId) { std::unique_ptr<V8StackTrace> stackTrace, int scriptId) {
int contextGroupId = V8Debugger::getGroupId(context); int contextGroupId = V8Debugger::getGroupId(context);
if (!contextGroupId || m_muteExceptionsMap[contextGroupId]) return 0; if (!contextGroupId || m_muteExceptionsMap[contextGroupId]) return 0;
std::unique_ptr<V8StackTraceImpl> stackTraceImpl = std::unique_ptr<V8StackTraceImpl> stackTraceImpl(
wrapUnique(static_cast<V8StackTraceImpl*>(stackTrace.release())); static_cast<V8StackTraceImpl*>(stackTrace.release()));
unsigned exceptionId = nextExceptionId(); unsigned exceptionId = nextExceptionId();
std::unique_ptr<V8ConsoleMessage> consoleMessage = std::unique_ptr<V8ConsoleMessage> consoleMessage =
V8ConsoleMessage::createForException( V8ConsoleMessage::createForException(
......
...@@ -40,7 +40,7 @@ bool V8InspectorSession::canDispatchMethod(const StringView& method) { ...@@ -40,7 +40,7 @@ bool V8InspectorSession::canDispatchMethod(const StringView& method) {
std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create( std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(
V8InspectorImpl* inspector, int contextGroupId, V8InspectorImpl* inspector, int contextGroupId,
V8Inspector::Channel* channel, const StringView& state) { V8Inspector::Channel* channel, const StringView& state) {
return wrapUnique( return std::unique_ptr<V8InspectorSessionImpl>(
new V8InspectorSessionImpl(inspector, contextGroupId, channel, state)); new V8InspectorSessionImpl(inspector, contextGroupId, channel, state));
} }
...@@ -62,35 +62,35 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, ...@@ -62,35 +62,35 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector,
m_schemaAgent(nullptr) { m_schemaAgent(nullptr) {
if (savedState.length()) { if (savedState.length()) {
std::unique_ptr<protocol::Value> state = std::unique_ptr<protocol::Value> state =
protocol::parseJSON(toString16(savedState)); protocol::StringUtil::parseJSON(toString16(savedState));
if (state) m_state = protocol::DictionaryValue::cast(std::move(state)); if (state) m_state = protocol::DictionaryValue::cast(std::move(state));
if (!m_state) m_state = protocol::DictionaryValue::create(); if (!m_state) m_state = protocol::DictionaryValue::create();
} else { } else {
m_state = protocol::DictionaryValue::create(); m_state = protocol::DictionaryValue::create();
} }
m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl( m_runtimeAgent.reset(new V8RuntimeAgentImpl(
this, this, agentState(protocol::Runtime::Metainfo::domainName))); this, this, agentState(protocol::Runtime::Metainfo::domainName)));
protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get());
m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl( m_debuggerAgent.reset(new V8DebuggerAgentImpl(
this, this, agentState(protocol::Debugger::Metainfo::domainName))); this, this, agentState(protocol::Debugger::Metainfo::domainName)));
protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get());
m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl( m_profilerAgent.reset(new V8ProfilerAgentImpl(
this, this, agentState(protocol::Profiler::Metainfo::domainName))); this, this, agentState(protocol::Profiler::Metainfo::domainName)));
protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get()); protocol::Profiler::Dispatcher::wire(&m_dispatcher, m_profilerAgent.get());
m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl( m_heapProfilerAgent.reset(new V8HeapProfilerAgentImpl(
this, this, agentState(protocol::HeapProfiler::Metainfo::domainName))); this, this, agentState(protocol::HeapProfiler::Metainfo::domainName)));
protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher, protocol::HeapProfiler::Dispatcher::wire(&m_dispatcher,
m_heapProfilerAgent.get()); m_heapProfilerAgent.get());
m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl( m_consoleAgent.reset(new V8ConsoleAgentImpl(
this, this, agentState(protocol::Console::Metainfo::domainName))); this, this, agentState(protocol::Console::Metainfo::domainName)));
protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get()); protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get());
m_schemaAgent = wrapUnique(new V8SchemaAgentImpl( m_schemaAgent.reset(new V8SchemaAgentImpl(
this, this, agentState(protocol::Schema::Metainfo::domainName))); this, this, agentState(protocol::Schema::Metainfo::domainName)));
protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get()); protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get());
...@@ -305,7 +305,7 @@ void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) { ...@@ -305,7 +305,7 @@ void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) {
void V8InspectorSessionImpl::dispatchProtocolMessage( void V8InspectorSessionImpl::dispatchProtocolMessage(
const StringView& message) { const StringView& message) {
m_dispatcher.dispatch(protocol::parseJSON(message)); m_dispatcher.dispatch(protocol::StringUtil::parseJSON(message));
} }
std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() { std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() {
...@@ -366,7 +366,8 @@ void V8InspectorSessionImpl::schedulePauseOnNextStatement( ...@@ -366,7 +366,8 @@ void V8InspectorSessionImpl::schedulePauseOnNextStatement(
const StringView& breakReason, const StringView& breakDetails) { const StringView& breakReason, const StringView& breakDetails) {
m_debuggerAgent->schedulePauseOnNextStatement( m_debuggerAgent->schedulePauseOnNextStatement(
toString16(breakReason), toString16(breakReason),
protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(breakDetails)));
} }
void V8InspectorSessionImpl::cancelPauseOnNextStatement() { void V8InspectorSessionImpl::cancelPauseOnNextStatement() {
...@@ -377,7 +378,8 @@ void V8InspectorSessionImpl::breakProgram(const StringView& breakReason, ...@@ -377,7 +378,8 @@ void V8InspectorSessionImpl::breakProgram(const StringView& breakReason,
const StringView& breakDetails) { const StringView& breakDetails) {
m_debuggerAgent->breakProgram( m_debuggerAgent->breakProgram(
toString16(breakReason), toString16(breakReason),
protocol::DictionaryValue::cast(protocol::parseJSON(breakDetails))); protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(breakDetails)));
} }
void V8InspectorSessionImpl::setSkipAllPauses(bool skip) { void V8InspectorSessionImpl::setSkipAllPauses(bool skip) {
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "src/inspector/v8-internal-value-type.h" #include "src/inspector/v8-internal-value-type.h"
#include "src/inspector/protocol-platform.h"
#include "src/inspector/string-util.h" #include "src/inspector/string-util.h"
namespace v8_inspector { namespace v8_inspector {
......
...@@ -706,7 +706,7 @@ void V8RuntimeAgentImpl::reportExecutionContextCreated( ...@@ -706,7 +706,7 @@ void V8RuntimeAgentImpl::reportExecutionContextCreated(
.build(); .build();
if (!context->auxData().isEmpty()) if (!context->auxData().isEmpty())
description->setAuxData(protocol::DictionaryValue::cast( description->setAuxData(protocol::DictionaryValue::cast(
protocol::parseJSON(context->auxData()))); protocol::StringUtil::parseJSON(context->auxData())));
m_frontend.executionContextCreated(std::move(description)); m_frontend.executionContextCreated(std::move(description));
} }
......
...@@ -180,7 +180,7 @@ std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( ...@@ -180,7 +180,7 @@ std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture(
std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() {
std::vector<Frame> framesCopy(m_frames); std::vector<Frame> framesCopy(m_frames);
return wrapUnique( return std::unique_ptr<V8StackTraceImpl>(
new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy,
m_parent ? m_parent->cloneImpl() : nullptr)); m_parent ? m_parent->cloneImpl() : nullptr));
} }
...@@ -189,7 +189,7 @@ std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { ...@@ -189,7 +189,7 @@ std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() {
std::vector<Frame> frames; std::vector<Frame> frames;
for (size_t i = 0; i < m_frames.size(); i++) for (size_t i = 0; i < m_frames.size(); i++)
frames.push_back(m_frames.at(i).clone()); frames.push_back(m_frames.at(i).clone());
return wrapUnique( return std::unique_ptr<V8StackTraceImpl>(
new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr)); new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr));
} }
......
...@@ -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: ebda02bf94a742a2e26e4f818df1fc77517ac44c Revision: ef8aa4e19e53a105843cd469e8122d098d902b47
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -67,6 +67,15 @@ template("inspector_protocol_generate") { ...@@ -67,6 +67,15 @@ template("inspector_protocol_generate") {
rebase_path(invoker.config_file, root_build_dir), rebase_path(invoker.config_file, root_build_dir),
] ]
if (defined(invoker.config_values)) {
foreach(value, invoker.config_values) {
args += [
"--config_value",
value,
]
}
}
outputs = get_path_info(rebase_path(invoker.outputs, ".", invoker.out_dir), outputs = get_path_info(rebase_path(invoker.outputs, ".", invoker.out_dir),
"abspath") "abspath")
......
...@@ -19,7 +19,7 @@ class Array { ...@@ -19,7 +19,7 @@ class Array {
public: public:
static std::unique_ptr<Array<T>> create() static std::unique_ptr<Array<T>> create()
{ {
return wrapUnique(new Array<T>()); return std::unique_ptr<Array<T>>(new Array<T>());
} }
static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors) static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
...@@ -74,7 +74,7 @@ class ArrayBase { ...@@ -74,7 +74,7 @@ class ArrayBase {
public: public:
static std::unique_ptr<Array<T>> create() static std::unique_ptr<Array<T>> create()
{ {
return wrapUnique(new Array<T>()); return std::unique_ptr<Array<T>>(new Array<T>());
} }
static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors) static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef {{"_".join(config.protocol.namespace)}}_Collections_h #ifndef {{"_".join(config.protocol.namespace)}}_Collections_h
#define {{"_".join(config.protocol.namespace)}}_Collections_h #define {{"_".join(config.protocol.namespace)}}_Collections_h
#include "{{config.protocol.package}}/Forward.h" #include {{format_include(config.protocol.package, "Forward")}}
#include <cstddef> #include <cstddef>
#if defined(__APPLE__) && !defined(_LIBCPP_VERSION) #if defined(__APPLE__) && !defined(_LIBCPP_VERSION)
......
...@@ -38,6 +38,16 @@ DispatchResponse DispatchResponse::InternalError() ...@@ -38,6 +38,16 @@ DispatchResponse DispatchResponse::InternalError()
return result; return result;
} }
// static
DispatchResponse DispatchResponse::InvalidParams(const String& error)
{
DispatchResponse result;
result.m_status = kError;
result.m_errorCode = kInvalidParams;
result.m_errorMessage = error;
return result;
}
// static // static
DispatchResponse DispatchResponse::FallThrough() DispatchResponse DispatchResponse::FallThrough()
{ {
...@@ -58,9 +68,10 @@ DispatcherBase::WeakPtr::~WeakPtr() ...@@ -58,9 +68,10 @@ DispatcherBase::WeakPtr::~WeakPtr()
m_dispatcher->m_weakPtrs.erase(this); m_dispatcher->m_weakPtrs.erase(this);
} }
DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId) DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
: m_backendImpl(std::move(backendImpl)) : m_backendImpl(std::move(backendImpl))
, m_callId(callId) { } , m_callId(callId)
, m_callbackId(callbackId) { }
DispatcherBase::Callback::~Callback() = default; DispatcherBase::Callback::~Callback() = default;
...@@ -77,18 +88,40 @@ void DispatcherBase::Callback::sendIfActive(std::unique_ptr<protocol::Dictionary ...@@ -77,18 +88,40 @@ void DispatcherBase::Callback::sendIfActive(std::unique_ptr<protocol::Dictionary
m_backendImpl = nullptr; m_backendImpl = nullptr;
} }
void DispatcherBase::Callback::fallThroughIfActive()
{
if (!m_backendImpl || !m_backendImpl->get())
return;
m_backendImpl->get()->markFallThrough(m_callbackId);
m_backendImpl = nullptr;
}
DispatcherBase::DispatcherBase(FrontendChannel* frontendChannel) DispatcherBase::DispatcherBase(FrontendChannel* frontendChannel)
: m_frontendChannel(frontendChannel) { } : m_frontendChannel(frontendChannel)
, m_lastCallbackId(0)
, m_lastCallbackFallThrough(false) { }
DispatcherBase::~DispatcherBase() DispatcherBase::~DispatcherBase()
{ {
clearFrontend(); clearFrontend();
} }
int DispatcherBase::nextCallbackId()
{
m_lastCallbackFallThrough = false;
return ++m_lastCallbackId;
}
void DispatcherBase::markFallThrough(int callbackId)
{
DCHECK(callbackId == m_lastCallbackId);
m_lastCallbackFallThrough = true;
}
// static // static
bool DispatcherBase::getCommandName(const String& message, String* result) bool DispatcherBase::getCommandName(const String& message, String* result)
{ {
std::unique_ptr<protocol::Value> value = parseJSON(message); std::unique_ptr<protocol::Value> value = StringUtil::parseJSON(message);
if (!value) if (!value)
return false; return false;
...@@ -169,7 +202,13 @@ std::unique_ptr<DispatcherBase::WeakPtr> DispatcherBase::weakPtr() ...@@ -169,7 +202,13 @@ std::unique_ptr<DispatcherBase::WeakPtr> DispatcherBase::weakPtr()
} }
UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel) UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel)
: m_frontendChannel(frontendChannel) { } : m_frontendChannel(frontendChannel)
, m_fallThroughForNotFound(false) { }
void UberDispatcher::setFallThroughForNotFound(bool fallThroughForNotFound)
{
m_fallThroughForNotFound = fallThroughForNotFound;
}
void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase> dispatcher) void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase> dispatcher)
{ {
...@@ -206,12 +245,16 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM ...@@ -206,12 +245,16 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
size_t dotIndex = method.find("."); size_t dotIndex = method.find(".");
if (dotIndex == StringUtil::kNotFound) { if (dotIndex == StringUtil::kNotFound) {
if (m_fallThroughForNotFound)
return DispatchResponse::kFallThrough;
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr); reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return DispatchResponse::kError; return DispatchResponse::kError;
} }
String domain = StringUtil::substring(method, 0, dotIndex); String domain = StringUtil::substring(method, 0, dotIndex);
auto it = m_dispatchers.find(domain); auto it = m_dispatchers.find(domain);
if (it == m_dispatchers.end()) { if (it == m_dispatchers.end()) {
if (m_fallThroughForNotFound)
return DispatchResponse::kFallThrough;
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr); reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return DispatchResponse::kError; return DispatchResponse::kError;
} }
......
...@@ -42,6 +42,7 @@ public: ...@@ -42,6 +42,7 @@ public:
static DispatchResponse OK(); static DispatchResponse OK();
static DispatchResponse Error(const String&); static DispatchResponse Error(const String&);
static DispatchResponse InternalError(); static DispatchResponse InternalError();
static DispatchResponse InvalidParams(const String&);
static DispatchResponse FallThrough(); static DispatchResponse FallThrough();
private: private:
...@@ -67,16 +68,18 @@ public: ...@@ -67,16 +68,18 @@ public:
class {{config.lib.export_macro}} Callback { class {{config.lib.export_macro}} Callback {
public: public:
Callback(std::unique_ptr<WeakPtr> backendImpl, int callId); Callback(std::unique_ptr<WeakPtr> backendImpl, int callId, int callbackId);
virtual ~Callback(); virtual ~Callback();
void dispose(); void dispose();
protected: protected:
void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response); void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response);
void fallThroughIfActive();
private: private:
std::unique_ptr<WeakPtr> m_backendImpl; std::unique_ptr<WeakPtr> m_backendImpl;
int m_callId; int m_callId;
int m_callbackId;
}; };
explicit DispatcherBase(FrontendChannel*); explicit DispatcherBase(FrontendChannel*);
...@@ -94,9 +97,15 @@ public: ...@@ -94,9 +97,15 @@ public:
std::unique_ptr<WeakPtr> weakPtr(); std::unique_ptr<WeakPtr> weakPtr();
int nextCallbackId();
void markFallThrough(int callbackId);
bool lastCallbackFallThrough() { return m_lastCallbackFallThrough; }
private: private:
FrontendChannel* m_frontendChannel; FrontendChannel* m_frontendChannel;
protocol::HashSet<WeakPtr*> m_weakPtrs; protocol::HashSet<WeakPtr*> m_weakPtrs;
int m_lastCallbackId;
bool m_lastCallbackFallThrough;
}; };
class {{config.lib.export_macro}} UberDispatcher { class {{config.lib.export_macro}} UberDispatcher {
...@@ -106,10 +115,13 @@ public: ...@@ -106,10 +115,13 @@ public:
void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>); void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
DispatchResponse::Status dispatch(std::unique_ptr<Value> message); DispatchResponse::Status dispatch(std::unique_ptr<Value> message);
FrontendChannel* channel() { return m_frontendChannel; } FrontendChannel* channel() { return m_frontendChannel; }
bool fallThroughForNotFound() { return m_fallThroughForNotFound; }
void setFallThroughForNotFound(bool);
virtual ~UberDispatcher(); virtual ~UberDispatcher();
private: private:
FrontendChannel* m_frontendChannel; FrontendChannel* m_frontendChannel;
bool m_fallThroughForNotFound;
protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers; protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
}; };
......
...@@ -42,7 +42,7 @@ void ErrorSupport::addError(const String& error) ...@@ -42,7 +42,7 @@ void ErrorSupport::addError(const String& error)
bool ErrorSupport::hasErrors() bool ErrorSupport::hasErrors()
{ {
return m_errors.size(); return !!m_errors.size();
} }
String ErrorSupport::errors() String ErrorSupport::errors()
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
{% if config.lib.export_header %} {% if config.lib.export_header %}
#include {{format_include(config.lib.export_header)}} #include {{format_include(config.lib.export_header)}}
{% endif %} {% endif %}
#include {{format_include(config.lib.platform_header)}}
#include {{format_include(config.lib.string_header)}} #include {{format_include(config.lib.string_header)}}
#include <vector> #include <vector>
......
...@@ -10,12 +10,13 @@ namespace {{namespace}} { ...@@ -10,12 +10,13 @@ namespace {{namespace}} {
std::unique_ptr<Object> Object::parse(protocol::Value* value, ErrorSupport* errors) std::unique_ptr<Object> Object::parse(protocol::Value* value, ErrorSupport* errors)
{ {
protocol::DictionaryValue* object = DictionaryValue::cast(value); protocol::DictionaryValue* dictionary = DictionaryValue::cast(value);
if (!object) { if (!dictionary) {
errors->addError("object expected"); errors->addError("object expected");
return nullptr; return nullptr;
} }
return wrapUnique(new Object(wrapUnique(static_cast<DictionaryValue*>(object->clone().release())))); dictionary = static_cast<protocol::DictionaryValue*>(dictionary->clone().release());
return std::unique_ptr<Object>(new Object(std::unique_ptr<DictionaryValue>(dictionary)));
} }
std::unique_ptr<protocol::DictionaryValue> Object::serialize() const std::unique_ptr<protocol::DictionaryValue> Object::serialize() const
...@@ -25,7 +26,7 @@ std::unique_ptr<protocol::DictionaryValue> Object::serialize() const ...@@ -25,7 +26,7 @@ std::unique_ptr<protocol::DictionaryValue> Object::serialize() const
std::unique_ptr<Object> Object::clone() const std::unique_ptr<Object> Object::clone() const
{ {
return wrapUnique(new Object(DictionaryValue::cast(m_object->clone()))); return std::unique_ptr<Object>(new Object(DictionaryValue::cast(m_object->clone())));
} }
Object::Object(std::unique_ptr<protocol::DictionaryValue> object) : m_object(std::move(object)) { } Object::Object(std::unique_ptr<protocol::DictionaryValue> object) : m_object(std::move(object)) { }
......
...@@ -538,12 +538,12 @@ std::unique_ptr<Value> parseJSONInternal(const Char* start, unsigned length) ...@@ -538,12 +538,12 @@ std::unique_ptr<Value> parseJSONInternal(const Char* start, unsigned length)
} // anonymous namespace } // anonymous namespace
std::unique_ptr<Value> parseJSON(const uint16_t* characters, unsigned length) std::unique_ptr<Value> parseJSONCharacters(const uint16_t* characters, unsigned length)
{ {
return parseJSONInternal<uint16_t>(characters, length); return parseJSONInternal<uint16_t>(characters, length);
} }
std::unique_ptr<Value> parseJSON(const uint8_t* characters, unsigned length) std::unique_ptr<Value> parseJSONCharacters(const uint8_t* characters, unsigned length)
{ {
return parseJSONInternal<uint8_t>(characters, length); return parseJSONInternal<uint8_t>(characters, length);
} }
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
namespace {{namespace}} { namespace {{namespace}} {
{% endfor %} {% endfor %}
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSON(const uint8_t*, unsigned); {{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSON(const uint16_t*, unsigned); {{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "{{config.protocol.package}}/Protocol.h" #include {{format_include(config.protocol.package, "Protocol")}}
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
......
...@@ -24,7 +24,7 @@ public: ...@@ -24,7 +24,7 @@ public:
static std::unique_ptr<Value> null() static std::unique_ptr<Value> null()
{ {
return wrapUnique(new Value()); return std::unique_ptr<Value>(new Value());
} }
enum ValueType { enum ValueType {
...@@ -67,17 +67,17 @@ class {{config.lib.export_macro}} FundamentalValue : public Value { ...@@ -67,17 +67,17 @@ class {{config.lib.export_macro}} FundamentalValue : public Value {
public: public:
static std::unique_ptr<FundamentalValue> create(bool value) static std::unique_ptr<FundamentalValue> create(bool value)
{ {
return wrapUnique(new FundamentalValue(value)); return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
} }
static std::unique_ptr<FundamentalValue> create(int value) static std::unique_ptr<FundamentalValue> create(int value)
{ {
return wrapUnique(new FundamentalValue(value)); return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
} }
static std::unique_ptr<FundamentalValue> create(double value) static std::unique_ptr<FundamentalValue> create(double value)
{ {
return wrapUnique(new FundamentalValue(value)); return std::unique_ptr<FundamentalValue>(new FundamentalValue(value));
} }
bool asBoolean(bool* output) const override; bool asBoolean(bool* output) const override;
...@@ -102,12 +102,12 @@ class {{config.lib.export_macro}} StringValue : public Value { ...@@ -102,12 +102,12 @@ class {{config.lib.export_macro}} StringValue : public Value {
public: public:
static std::unique_ptr<StringValue> create(const String& value) static std::unique_ptr<StringValue> create(const String& value)
{ {
return wrapUnique(new StringValue(value)); return std::unique_ptr<StringValue>(new StringValue(value));
} }
static std::unique_ptr<StringValue> create(const char* value) static std::unique_ptr<StringValue> create(const char* value)
{ {
return wrapUnique(new StringValue(value)); return std::unique_ptr<StringValue>(new StringValue(value));
} }
bool asString(String* output) const override; bool asString(String* output) const override;
...@@ -125,7 +125,7 @@ class {{config.lib.export_macro}} SerializedValue : public Value { ...@@ -125,7 +125,7 @@ class {{config.lib.export_macro}} SerializedValue : public Value {
public: public:
static std::unique_ptr<SerializedValue> create(const String& value) static std::unique_ptr<SerializedValue> create(const String& value)
{ {
return wrapUnique(new SerializedValue(value)); return std::unique_ptr<SerializedValue>(new SerializedValue(value));
} }
bool asSerialized(String* output) const override; bool asSerialized(String* output) const override;
...@@ -143,7 +143,7 @@ public: ...@@ -143,7 +143,7 @@ public:
using Entry = std::pair<String, Value*>; using Entry = std::pair<String, Value*>;
static std::unique_ptr<DictionaryValue> create() static std::unique_ptr<DictionaryValue> create()
{ {
return wrapUnique(new DictionaryValue()); return std::unique_ptr<DictionaryValue>(new DictionaryValue());
} }
static DictionaryValue* cast(Value* value) static DictionaryValue* cast(Value* value)
...@@ -155,7 +155,7 @@ public: ...@@ -155,7 +155,7 @@ public:
static std::unique_ptr<DictionaryValue> cast(std::unique_ptr<Value> value) static std::unique_ptr<DictionaryValue> cast(std::unique_ptr<Value> value)
{ {
return wrapUnique(DictionaryValue::cast(value.release())); return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
} }
void writeJSON(StringBuilder* output) const override; void writeJSON(StringBuilder* output) const override;
...@@ -209,7 +209,7 @@ class {{config.lib.export_macro}} ListValue : public Value { ...@@ -209,7 +209,7 @@ class {{config.lib.export_macro}} ListValue : public Value {
public: public:
static std::unique_ptr<ListValue> create() static std::unique_ptr<ListValue> create()
{ {
return wrapUnique(new ListValue()); return std::unique_ptr<ListValue>(new ListValue());
} }
static ListValue* cast(Value* value) static ListValue* cast(Value* value)
...@@ -221,7 +221,7 @@ public: ...@@ -221,7 +221,7 @@ public:
static std::unique_ptr<ListValue> cast(std::unique_ptr<Value> value) static std::unique_ptr<ListValue> cast(std::unique_ptr<Value> value)
{ {
return wrapUnique(ListValue::cast(value.release())); return std::unique_ptr<ListValue>(ListValue::cast(value.release()));
} }
~ListValue() override; ~ListValue() override;
......
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
#ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h #ifndef {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h
#define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h #define {{"_".join(config.protocol.namespace)}}_{{domain.domain}}_imported_h
#include "{{config.protocol.package}}/Protocol.h" #include {{format_include(config.protocol.package, "Protocol")}}
#include {{format_include(config.imported.header if config.imported.header else "\"%s/%s.h\"" % (config.imported.package, domain.domain))}} {% if config.imported.header %}
#include {{format_include(config.imported.header)}}
{% else %}
#include {{format_include(config.imported.package, domain.domain)}}
{% endif %}
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
namespace {{namespace}} { namespace {{namespace}} {
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "{{config.protocol.package}}/{{domain.domain}}.h" #include {{format_include(config.protocol.package, domain.domain)}}
#include "{{config.protocol.package}}/Protocol.h" #include {{format_include(config.protocol.package, "Protocol")}}
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
namespace {{namespace}} { namespace {{namespace}} {
...@@ -106,7 +106,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const ...@@ -106,7 +106,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromJSONString(const {{config.exported.string_in}}& json) std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromJSONString(const {{config.exported.string_in}}& json)
{ {
ErrorSupport errors; ErrorSupport errors;
std::unique_ptr<Value> value = parseJSON(json); std::unique_ptr<Value> value = StringUtil::parseJSON(json);
if (!value) if (!value)
return nullptr; return nullptr;
return protocol::{{domain.domain}}::{{type.id}}::parse(value.get(), &errors); return protocol::{{domain.domain}}::{{type.id}}::parse(value.get(), &errors);
...@@ -145,9 +145,9 @@ const char* {{ literal | to_title_case}} = "{{literal}}"; ...@@ -145,9 +145,9 @@ const char* {{ literal | to_title_case}} = "{{literal}}";
// ------------- Frontend notifications. // ------------- Frontend notifications.
{% for event in domain.events %} {% for event in domain.events %}
{% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% continue %}{% endif %} {% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif %}
void Frontend::{{event.name}}( void Frontend::{{event.name | to_method_case}}(
{%- for parameter in event.parameters %} {%- for parameter in event.parameters %}
{% if "optional" in parameter -%} {% if "optional" in parameter -%}
Maybe<{{resolve_type(parameter).raw_type}}> Maybe<{{resolve_type(parameter).raw_type}}>
...@@ -178,16 +178,22 @@ void Frontend::flush() ...@@ -178,16 +178,22 @@ void Frontend::flush()
m_frontendChannel->flushProtocolNotifications(); m_frontendChannel->flushProtocolNotifications();
} }
void Frontend::sendRawNotification(const String& notification)
{
m_frontendChannel->sendProtocolNotification(notification);
}
// --------------------- Dispatcher. // --------------------- Dispatcher.
class DispatcherImpl : public protocol::DispatcherBase { class DispatcherImpl : public protocol::DispatcherBase {
public: public:
DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
: DispatcherBase(frontendChannel) : DispatcherBase(frontendChannel)
, m_backend(backend) { , m_backend(backend)
, m_fallThroughForNotFound(fallThroughForNotFound) {
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
{% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} {% if not generate_command(domain.domain, command.name) %}{% continue %}{% endif %}
m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{{command.name}}; m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{{command.name}};
{% endfor %} {% endfor %}
} }
...@@ -201,17 +207,20 @@ protected: ...@@ -201,17 +207,20 @@ protected:
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
{% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} {% if not generate_command(domain.domain, command.name) %}{% continue %}{% endif %}
DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*); DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
{% endfor %} {% endfor %}
Backend* m_backend; Backend* m_backend;
bool m_fallThroughForNotFound;
}; };
DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
{ {
protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method); protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
if (it == m_dispatchMap.end()) { if (it == m_dispatchMap.end()) {
if (m_fallThroughForNotFound)
return DispatchResponse::kFallThrough;
reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr); reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return DispatchResponse::kError; return DispatchResponse::kError;
} }
...@@ -222,13 +231,13 @@ DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& meth ...@@ -222,13 +231,13 @@ DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& meth
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
{% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} {% if not generate_command(domain.domain, command.name) %}{% continue %}{% endif %}
{% if "async" in command %} {% if is_async_command(domain.domain, command.name) %}
class {{command.name | to_title_case}}CallbackImpl : public Backend::{{command.name | to_title_case}}Callback, public DispatcherBase::Callback { class {{command.name | to_title_case}}CallbackImpl : public Backend::{{command.name | to_title_case}}Callback, public DispatcherBase::Callback {
public: public:
{{command.name | to_title_case}}CallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId) {{command.name | to_title_case}}CallbackImpl(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
: DispatcherBase::Callback(std::move(backendImpl), callId) { } : DispatcherBase::Callback(std::move(backendImpl), callId, callbackId) { }
void sendSuccess( void sendSuccess(
{%- for parameter in command.returns -%} {%- for parameter in command.returns -%}
...@@ -252,6 +261,11 @@ public: ...@@ -252,6 +261,11 @@ public:
sendIfActive(std::move(resultObject), DispatchResponse::OK()); sendIfActive(std::move(resultObject), DispatchResponse::OK());
} }
void fallThrough() override
{
fallThroughIfActive();
}
void sendFailure(const DispatchResponse& response) override void sendFailure(const DispatchResponse& response) override
{ {
DCHECK(response.status() == DispatchResponse::kError); DCHECK(response.status() == DispatchResponse::kError);
...@@ -285,7 +299,7 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -285,7 +299,7 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
return DispatchResponse::kError; return DispatchResponse::kError;
} }
{% endif %} {% endif %}
{% if "returns" in command and not ("async" in command) %} {% if "returns" in command and not is_async_command(domain.domain, command.name) %}
// Declare output parameters. // Declare output parameters.
{% for property in command.returns %} {% for property in command.returns %}
{% if "optional" in property %} {% if "optional" in property %}
...@@ -296,9 +310,9 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -296,9 +310,9 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if not("async" in command) %} {% if not is_async_command(domain.domain, command.name) %}
std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr(); std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
DispatchResponse response = m_backend->{{command.name}}( DispatchResponse response = m_backend->{{command.name | to_method_case}}(
{%- for property in command.parameters -%} {%- for property in command.parameters -%}
{%- if not loop.first -%}, {% endif -%} {%- if not loop.first -%}, {% endif -%}
{%- if "optional" in property -%} {%- if "optional" in property -%}
...@@ -335,8 +349,8 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -335,8 +349,8 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
{% endif %} {% endif %}
return response.status(); return response.status();
{% else %} {% else %}
std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new {{command.name | to_title_case}}CallbackImpl(weakPtr(), callId)); std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new {{command.name | to_title_case}}CallbackImpl(weakPtr(), callId, nextCallbackId()));
m_backend->{{command.name}}( m_backend->{{command.name | to_method_case}}(
{%- for property in command.parameters -%} {%- for property in command.parameters -%}
{%- if not loop.first -%}, {% endif -%} {%- if not loop.first -%}, {% endif -%}
{%- if "optional" in property -%} {%- if "optional" in property -%}
...@@ -347,7 +361,7 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -347,7 +361,7 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
{%- endfor -%} {%- endfor -%}
{%- if command.parameters -%}, {% endif -%} {%- if command.parameters -%}, {% endif -%}
std::move(callback)); std::move(callback));
return DispatchResponse::kAsync; return lastCallbackFallThrough() ? DispatchResponse::kFallThrough : DispatchResponse::kAsync;
{% endif %} {% endif %}
} }
{% endfor %} {% endfor %}
...@@ -355,7 +369,7 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -355,7 +369,7 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
// static // static
void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
{ {
dispatcher->registerBackend("{{domain.domain}}", wrapUnique(new DispatcherImpl(dispatcher->channel(), backend))); dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::DispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fallThroughForNotFound())));
} }
} // {{domain.domain}} } // {{domain.domain}}
......
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
{% if config.protocol.export_header %} {% if config.protocol.export_header %}
#include {{format_include(config.protocol.export_header)}} #include {{format_include(config.protocol.export_header)}}
{% endif %} {% endif %}
#include "{{config.protocol.package}}/Protocol.h" #include {{format_include(config.protocol.package, "Protocol")}}
// For each imported domain we generate a ValueConversions struct instead of a full domain definition // For each imported domain we generate a ValueConversions struct instead of a full domain definition
// and include Domain::API version from there. // and include Domain::API version from there.
{% for name in domain.dependencies %} {% for name in domain.dependencies %}
#include "{{config.protocol.package}}/{{name}}.h" #include {{format_include(config.protocol.package, name)}}
{% endfor %} {% endfor %}
{% if domain["has_exports"] %} {% if domain["has_exports"] %}
#include "{{config.exported.package}}/{{domain.domain}}.h" #include {{format_include(config.exported.package, domain.domain)}}
{% endif %} {% endif %}
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
...@@ -88,12 +88,12 @@ public: ...@@ -88,12 +88,12 @@ public:
{% endif %} {% endif %}
{% if property.optional %} {% if property.optional %}
bool has{{property.name | to_title_case}}() { return m_{{property.name}}.isJust(); } bool {{"has" | to_method_case}}{{property.name | to_title_case}}() { return m_{{property.name}}.isJust(); }
{{resolve_type(property).raw_return_type}} get{{property.name | to_title_case}}({{resolve_type(property).raw_pass_type}} defaultValue) { return m_{{property.name}}.isJust() ? m_{{property.name}}.fromJust() : defaultValue; } {{resolve_type(property).raw_return_type}} {{"get" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).raw_pass_type}} defaultValue) { return m_{{property.name}}.isJust() ? m_{{property.name}}.fromJust() : defaultValue; }
{% else %} {% else %}
{{resolve_type(property).raw_return_type}} get{{property.name | to_title_case}}() { return {{resolve_type(property).to_raw_type % ("m_" + property.name)}}; } {{resolve_type(property).raw_return_type}} {{"get" | to_method_case}}{{property.name | to_title_case}}() { return {{resolve_type(property).to_raw_type % ("m_" + property.name)}}; }
{% endif %} {% endif %}
void set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { m_{{property.name}} = {{resolve_type(property).to_rvalue % "value"}}; } void {{"set" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { m_{{property.name}} = {{resolve_type(property).to_rvalue % "value"}}; }
{% endfor %} {% endfor %}
std::unique_ptr<protocol::DictionaryValue> serialize() const; std::unique_ptr<protocol::DictionaryValue> serialize() const;
...@@ -122,22 +122,22 @@ public: ...@@ -122,22 +122,22 @@ public:
{% for property in type.properties %} {% for property in type.properties %}
{% if property.optional %} {% if property.optional %}
{{type.id}}Builder<STATE>& set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) {{type.id}}Builder<STATE>& {{"set" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value)
{ {
m_result->set{{property.name | to_title_case}}({{resolve_type(property).to_rvalue % "value"}}); m_result->{{"set" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).to_rvalue % "value"}});
return *this; return *this;
} }
{% else %} {% else %}
{{type.id}}Builder<STATE | {{property.name | to_title_case}}Set>& set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) {{type.id}}Builder<STATE | {{property.name | to_title_case}}Set>& {{"set" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value)
{ {
static_assert(!(STATE & {{property.name | to_title_case}}Set), "property {{property.name}} should not be set yet"); static_assert(!(STATE & {{property.name | to_title_case}}Set), "property {{property.name}} should not be set yet");
m_result->set{{property.name | to_title_case}}({{resolve_type(property).to_rvalue % "value"}}); m_result->{{"set" | to_method_case}}{{property.name | to_title_case}}({{resolve_type(property).to_rvalue % "value"}});
return castState<{{property.name | to_title_case}}Set>(); return castState<{{property.name | to_title_case}}Set>();
} }
{% endif %} {% endif %}
{% endfor %} {% endfor %}
std::unique_ptr<{{type.id}}> build() std::unique_ptr<{{type.id}}> {{"build" | to_method_case}}()
{ {
static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet"); static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
return std::move(m_result); return std::move(m_result);
...@@ -155,7 +155,7 @@ public: ...@@ -155,7 +155,7 @@ public:
{{type_def.type}} m_result; {{type_def.type}} m_result;
}; };
static {{type.id}}Builder<0> create() static {{type.id}}Builder<0> {{"create" | to_method_case}}()
{ {
return {{type.id}}Builder<0>(); return {{type.id}}Builder<0>();
} }
...@@ -189,8 +189,8 @@ public: ...@@ -189,8 +189,8 @@ public:
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
{% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} {% if not generate_command(domain.domain, command.name) %}{% continue %}{% endif %}
{% if "async" in command %} {% if is_async_command(domain.domain, command.name) %}
class {{config.protocol.export_macro}} {{command.name | to_title_case}}Callback { class {{config.protocol.export_macro}} {{command.name | to_title_case}}Callback {
public: public:
virtual void sendSuccess( virtual void sendSuccess(
...@@ -204,13 +204,14 @@ public: ...@@ -204,13 +204,14 @@ public:
{%- endfor -%} {%- endfor -%}
) = 0; ) = 0;
virtual void sendFailure(const DispatchResponse&) = 0; virtual void sendFailure(const DispatchResponse&) = 0;
virtual void fallThrough() = 0;
virtual ~{{command.name | to_title_case}}Callback() { } virtual ~{{command.name | to_title_case}}Callback() { }
}; };
{% endif %} {% endif %}
{%- if not("async" in command) %} {%- if not is_async_command(domain.domain, command.name) %}
virtual DispatchResponse {{command.name}}( virtual DispatchResponse {{command.name | to_method_case}}(
{%- else %} {%- else %}
virtual void {{command.name}}( virtual void {{command.name | to_method_case}}(
{%- endif %} {%- endif %}
{%- for parameter in command.parameters -%} {%- for parameter in command.parameters -%}
{%- if not loop.first -%}, {% endif -%} {%- if not loop.first -%}, {% endif -%}
...@@ -220,7 +221,7 @@ public: ...@@ -220,7 +221,7 @@ public:
{{resolve_type(parameter).pass_type}} in_{{parameter.name}} {{resolve_type(parameter).pass_type}} in_{{parameter.name}}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- if "async" in command -%} {%- if is_async_command(domain.domain, command.name) -%}
{%- if command.parameters -%}, {% endif -%} {%- if command.parameters -%}, {% endif -%}
std::unique_ptr<{{command.name | to_title_case}}Callback> callback std::unique_ptr<{{command.name | to_title_case}}Callback> callback
{%- else -%} {%- else -%}
...@@ -236,8 +237,8 @@ public: ...@@ -236,8 +237,8 @@ public:
) = 0; ) = 0;
{% endfor %} {% endfor %}
{% if not has_disable(domain.commands) %} {% if generate_disable(domain) %}
virtual DispatchResponse disable() virtual DispatchResponse {{"disable" | to_method_case}}()
{ {
return DispatchResponse::OK(); return DispatchResponse::OK();
} }
...@@ -248,10 +249,10 @@ public: ...@@ -248,10 +249,10 @@ public:
class {{config.protocol.export_macro}} Frontend { class {{config.protocol.export_macro}} Frontend {
public: public:
Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { } explicit Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { }
{% for event in domain.events %} {% for event in domain.events %}
{% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% continue %}{% endif %} {% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif %}
void {{event.name}}( void {{event.name | to_method_case}}(
{%- for parameter in event.parameters -%} {%- for parameter in event.parameters -%}
{%- if "optional" in parameter -%} {%- if "optional" in parameter -%}
Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>() Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
...@@ -263,6 +264,7 @@ public: ...@@ -263,6 +264,7 @@ public:
{% endfor %} {% endfor %}
void flush(); void flush();
void sendRawNotification(const String&);
private: private:
FrontendChannel* m_frontendChannel; FrontendChannel* m_frontendChannel;
}; };
......
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