Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: core/inspector/CodeGeneratorInspectorStrings.py

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/inspector/CodeGeneratorInspector.py ('k') | core/inspector/CodeGeneratorInstrumentation.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/inspector/CodeGeneratorInspectorStrings.py
diff --git a/core/inspector/CodeGeneratorInspectorStrings.py b/core/inspector/CodeGeneratorInspectorStrings.py
index 059178293245d97162fe1122671238b70f4b5705..e20c806b234e88ef746e710e2284598f8348e1d9 100644
--- a/core/inspector/CodeGeneratorInspectorStrings.py
+++ b/core/inspector/CodeGeneratorInspectorStrings.py
@@ -30,8 +30,9 @@
# Its syntax is a Python syntax subset, suitable for manual parsing.
frontend_domain_class = (
-""" class $domainClassName {
+""" class CORE_EXPORT $domainClassName {
public:
+ static $domainClassName* from(InspectorFrontend* frontend) { return &(frontend->m_$domainFieldName) ;}
$domainClassName(InspectorFrontendChannel* inspectorFrontendChannel) : m_inspectorFrontendChannel(inspectorFrontendChannel) { }
${frontendDomainMethodDeclarations}
void flush() { m_inspectorFrontendChannel->flush(); }
@@ -39,18 +40,16 @@ ${frontendDomainMethodDeclarations}
InspectorFrontendChannel* m_inspectorFrontendChannel;
};
- $domainClassName* $domainFieldName() { return &m_$domainFieldName; }
-
""")
backend_method = (
-"""void InspectorBackendDispatcherImpl::${domainName}_$methodName(long callId, JSONObject*$requestMessageObject, JSONArray* protocolErrors)
+"""void InspectorBackendDispatcherImpl::${domainName}_$methodName(int callId, JSONObject*$requestMessageObject, JSONArray* protocolErrors)
{
if (!$agentField)
protocolErrors->pushString("${domainName} handler is not available.");
$methodCode
if (protocolErrors->length()) {
- reportProtocolError(&callId, InvalidParams, String::format(InvalidParamsFormatString, commandName($commandNameIndex)), protocolErrors);
+ reportProtocolError(callId, InvalidParams, String::format(InvalidParamsFormatString, commandName($commandNameIndex)), protocolErrors);
return;
}
$agentCallParamsDeclaration
@@ -65,7 +64,7 @@ frontend_method = ("""void InspectorFrontend::$domainName::$eventName($parameter
RefPtr<JSONObject> jsonMessage = JSONObject::create();
jsonMessage->setString("method", "$domainName.$eventName");
$code if (m_inspectorFrontendChannel)
- m_inspectorFrontendChannel->sendMessageToFrontend(jsonMessage.release());
+ m_inspectorFrontendChannel->sendProtocolNotification(jsonMessage.release());
}
""")
@@ -97,6 +96,7 @@ frontend_h = (
#define InspectorFrontend_h
#include "InspectorTypeBuilder.h"
+#include "core/CoreExport.h"
#include "core/inspector/InspectorFrontendChannel.h"
#include "platform/JSONValues.h"
#include "wtf/PassRefPtr.h"
@@ -106,7 +106,7 @@ namespace blink {
typedef String ErrorString;
-class InspectorFrontend {
+class CORE_EXPORT InspectorFrontend {
public:
InspectorFrontend(InspectorFrontendChannel*);
InspectorFrontendChannel* channel() { return m_inspectorFrontendChannel; }
@@ -126,6 +126,7 @@ backend_h = (
#include "InspectorTypeBuilder.h"
+#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
@@ -141,17 +142,17 @@ typedef String ErrorString;
class InspectorBackendDispatcherImpl;
-class InspectorBackendDispatcher: public RefCountedWillBeGarbageCollectedFinalized<InspectorBackendDispatcher> {
+class CORE_EXPORT InspectorBackendDispatcher: public RefCountedWillBeGarbageCollectedFinalized<InspectorBackendDispatcher> {
public:
static PassRefPtrWillBeRawPtr<InspectorBackendDispatcher> create(InspectorFrontendChannel* inspectorFrontendChannel);
virtual ~InspectorBackendDispatcher() { }
- virtual void trace(Visitor*) { }
+ DEFINE_INLINE_VIRTUAL_TRACE() { }
- class CallbackBase: public RefCountedWillBeGarbageCollectedFinalized<CallbackBase> {
+ class CORE_EXPORT CallbackBase: public RefCountedWillBeGarbageCollectedFinalized<CallbackBase> {
public:
CallbackBase(PassRefPtrWillBeRawPtr<InspectorBackendDispatcherImpl> backendImpl, int id);
virtual ~CallbackBase();
- virtual void trace(Visitor*);
+ DECLARE_VIRTUAL_TRACE();
void sendFailure(const ErrorString&);
bool isActive();
@@ -183,8 +184,8 @@ $virtualSetters
LastEntry,
};
- void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage) const;
- virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const = 0;
+ void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage) const;
+ virtual void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const = 0;
virtual void dispatch(const String& message) = 0;
static bool getCommandName(const String& message, String* result);
@@ -198,7 +199,7 @@ $methodNamesEnumContent
private:
static const char commandNames[];
- static const size_t commandNamesIndex[];
+ static const unsigned short commandNamesIndex[];
};
} // namespace blink
@@ -225,12 +226,12 @@ const char InspectorBackendDispatcher::commandNames[] = {
$methodNameDeclarations
};
-const size_t InspectorBackendDispatcher::commandNamesIndex[] = {
+const unsigned short InspectorBackendDispatcher::commandNamesIndex[] = {
$methodNameDeclarationsIndex
};
const char* InspectorBackendDispatcher::commandName(MethodNames index) {
- COMPILE_ASSERT(static_cast<int>(kMethodNamesEnumSize) == WTF_ARRAY_LENGTH(commandNamesIndex), command_name_array_problem);
+ static_assert(static_cast<int>(kMethodNamesEnumSize) == WTF_ARRAY_LENGTH(commandNamesIndex), "MethodNames enum should have the same number of elements as commandNamesIndex");
return commandNames + commandNamesIndex[index];
}
@@ -239,18 +240,36 @@ public:
InspectorBackendDispatcherImpl(InspectorFrontendChannel* inspectorFrontendChannel)
: m_inspectorFrontendChannel(inspectorFrontendChannel)
$constructorInit
- { }
+ {
+ // Initialize dispatch map.
+ const CallHandler handlers[] = {
+ $messageHandlers
+ };
+ for (size_t i = 0; i < kMethodNamesEnumSize; ++i)
+ m_dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers[i]);
+
+ // Initialize common errors.
+ m_commonErrors.insert(ParseError, -32700);
+ m_commonErrors.insert(InvalidRequest, -32600);
+ m_commonErrors.insert(MethodNotFound, -32601);
+ m_commonErrors.insert(InvalidParams, -32602);
+ m_commonErrors.insert(InternalError, -32603);
+ m_commonErrors.insert(ServerError, -32000);
+ }
virtual void clearFrontend() { m_inspectorFrontendChannel = 0; }
virtual void dispatch(const String& message);
- virtual void reportProtocolError(const long* const callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const;
+ virtual void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage, PassRefPtr<JSONValue> data) const;
using InspectorBackendDispatcher::reportProtocolError;
- void sendResponse(long callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result);
+ void sendResponse(int callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result);
bool isActive() { return m_inspectorFrontendChannel; }
$setters
private:
+ using CallHandler = void (InspectorBackendDispatcherImpl::*)(int callId, JSONObject* messageObject, JSONArray* protocolErrors);
+ using DispatchMap = HashMap<String, CallHandler>;
+
$methodDeclarations
InspectorFrontendChannel* m_inspectorFrontendChannel;
@@ -266,15 +285,18 @@ $fieldDeclarations
static PassRefPtr<JSONObject> getObject(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors);
static PassRefPtr<JSONArray> getArray(JSONObject* object, const char* name, bool* valueFound, JSONArray* protocolErrors);
- void sendResponse(long callId, ErrorString invocationError, PassRefPtr<JSONObject> result)
+ void sendResponse(int callId, ErrorString invocationError, PassRefPtr<JSONObject> result)
{
sendResponse(callId, invocationError, RefPtr<JSONValue>(), result);
}
- void sendResponse(long callId, ErrorString invocationError)
+ void sendResponse(int callId, ErrorString invocationError)
{
sendResponse(callId, invocationError, RefPtr<JSONValue>(), JSONObject::create());
}
static const char InvalidParamsFormatString[];
+
+ DispatchMap m_dispatchMap;
+ Vector<int> m_commonErrors;
};
const char InspectorBackendDispatcherImpl::InvalidParamsFormatString[] = "Some arguments of method '%s' can't be processed";
@@ -290,57 +312,24 @@ PassRefPtrWillBeRawPtr<InspectorBackendDispatcher> InspectorBackendDispatcher::c
void InspectorBackendDispatcherImpl::dispatch(const String& message)
{
RefPtrWillBeRawPtr<InspectorBackendDispatcher> protect(this);
- typedef void (InspectorBackendDispatcherImpl::*CallHandler)(long callId, JSONObject* messageObject, JSONArray* protocolErrors);
- typedef HashMap<String, CallHandler> DispatchMap;
- DEFINE_STATIC_LOCAL(DispatchMap, dispatchMap, );
- long callId = 0;
-
- if (dispatchMap.isEmpty()) {
- static const CallHandler handlers[] = {
-$messageHandlers
- };
- for (size_t i = 0; i < kMethodNamesEnumSize; ++i)
- dispatchMap.add(commandName(static_cast<MethodNames>(i)), handlers[i]);
- }
-
+ int callId = 0;
RefPtr<JSONValue> parsedMessage = parseJSON(message);
- if (!parsedMessage) {
- reportProtocolError(0, ParseError, "Message must be in JSON format");
- return;
- }
-
+ ASSERT(parsedMessage);
RefPtr<JSONObject> messageObject = parsedMessage->asObject();
- if (!messageObject) {
- reportProtocolError(0, InvalidRequest, "Message must be a JSONified object");
- return;
- }
+ ASSERT(messageObject);
RefPtr<JSONValue> callIdValue = messageObject->get("id");
- if (!callIdValue) {
- reportProtocolError(0, InvalidRequest, "'id' property was not found");
- return;
- }
-
- if (!callIdValue->asNumber(&callId)) {
- reportProtocolError(0, InvalidRequest, "The type of 'id' property must be number");
- return;
- }
+ bool success = callIdValue->asNumber(&callId);
+ ASSERT_UNUSED(success, success);
RefPtr<JSONValue> methodValue = messageObject->get("method");
- if (!methodValue) {
- reportProtocolError(&callId, InvalidRequest, "'method' property wasn't found");
- return;
- }
-
String method;
- if (!methodValue->asString(&method)) {
- reportProtocolError(&callId, InvalidRequest, "The type of 'method' property must be string");
- return;
- }
+ success = methodValue && methodValue->asString(&method);
+ ASSERT_UNUSED(success, success);
- HashMap<String, CallHandler>::iterator it = dispatchMap.find(method);
- if (it == dispatchMap.end()) {
- reportProtocolError(&callId, MethodNotFound, "'" + method + "' wasn't found");
+ HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
+ if (it == m_dispatchMap.end()) {
+ reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't found");
return;
}
@@ -348,10 +337,10 @@ $messageHandlers
((*this).*it->value)(callId, messageObject.get(), protocolErrors.get());
}
-void InspectorBackendDispatcherImpl::sendResponse(long callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result)
+void InspectorBackendDispatcherImpl::sendResponse(int callId, const ErrorString& invocationError, PassRefPtr<JSONValue> errorData, PassRefPtr<JSONObject> result)
{
if (invocationError.length()) {
- reportProtocolError(&callId, ServerError, invocationError, errorData);
+ reportProtocolError(callId, ServerError, invocationError, errorData);
return;
}
@@ -359,42 +348,30 @@ void InspectorBackendDispatcherImpl::sendResponse(long callId, const ErrorString
responseMessage->setNumber("id", callId);
responseMessage->setObject("result", result);
if (m_inspectorFrontendChannel)
- m_inspectorFrontendChannel->sendMessageToFrontend(responseMessage.release());
+ m_inspectorFrontendChannel->sendProtocolResponse(callId, responseMessage.release());
}
-void InspectorBackendDispatcher::reportProtocolError(const long* const callId, CommonErrorCode code, const String& errorMessage) const
+void InspectorBackendDispatcher::reportProtocolError(int callId, CommonErrorCode code, const String& errorMessage) const
{
reportProtocolError(callId, code, errorMessage, PassRefPtr<JSONValue>());
}
-void InspectorBackendDispatcherImpl::reportProtocolError(const long* const callId, CommonErrorCode code, const String& errorMessage, PassRefPtr<JSONValue> data) const
+void InspectorBackendDispatcherImpl::reportProtocolError(int callId, CommonErrorCode code, const String& errorMessage, PassRefPtr<JSONValue> data) const
{
- DEFINE_STATIC_LOCAL(Vector<int>,s_commonErrors,);
- if (!s_commonErrors.size()) {
- s_commonErrors.insert(ParseError, -32700);
- s_commonErrors.insert(InvalidRequest, -32600);
- s_commonErrors.insert(MethodNotFound, -32601);
- s_commonErrors.insert(InvalidParams, -32602);
- s_commonErrors.insert(InternalError, -32603);
- s_commonErrors.insert(ServerError, -32000);
- }
ASSERT(code >=0);
- ASSERT((unsigned)code < s_commonErrors.size());
- ASSERT(s_commonErrors[code]);
+ ASSERT((unsigned)code < m_commonErrors.size());
+ ASSERT(m_commonErrors[code]);
RefPtr<JSONObject> error = JSONObject::create();
- error->setNumber("code", s_commonErrors[code]);
+ error->setNumber("code", m_commonErrors[code]);
error->setString("message", errorMessage);
ASSERT(error);
if (data)
error->setValue("data", data);
RefPtr<JSONObject> message = JSONObject::create();
message->setObject("error", error);
- if (callId)
- message->setNumber("id", *callId);
- else
- message->setValue("id", JSONValue::null());
+ message->setNumber("id", callId);
if (m_inspectorFrontendChannel)
- m_inspectorFrontendChannel->sendMessageToFrontend(message.release());
+ m_inspectorFrontendChannel->sendProtocolResponse(callId, message.release());
}
template<typename R, typename V, typename V0>
@@ -492,7 +469,7 @@ InspectorBackendDispatcher::CallbackBase::CallbackBase(PassRefPtrWillBeRawPtr<In
InspectorBackendDispatcher::CallbackBase::~CallbackBase() {}
-void InspectorBackendDispatcher::CallbackBase::trace(Visitor* visitor)
+DEFINE_TRACE(InspectorBackendDispatcher::CallbackBase)
{
visitor->trace(m_backendImpl);
}
@@ -550,6 +527,7 @@ typebuilder_h = (
#ifndef InspectorTypeBuilder_h
#define InspectorTypeBuilder_h
+#include "core/CoreExport.h"
#include "platform/JSONValues.h"
#include "wtf/Assertions.h"
#include "wtf/PassRefPtr.h"
@@ -611,7 +589,7 @@ private:
Array() { }
JSONArray* openAccessors() {
- COMPILE_ASSERT(sizeof(JSONArray) == sizeof(Array<T>), cannot_cast);
+ static_assert(sizeof(JSONArray) == sizeof(Array<T>), "JSONArray should be the same size as Array<T>");
return static_cast<JSONArray*>(static_cast<JSONArrayBase*>(this));
}
@@ -639,7 +617,7 @@ public:
#if $validatorIfdefName
assertCorrectValue(array.get());
#endif // $validatorIfdefName
- COMPILE_ASSERT(sizeof(Array<T>) == sizeof(JSONArray), type_cast_problem);
+ static_assert(sizeof(Array<T>) == sizeof(JSONArray), "Array<T> should be the same size as JSONArray");
return static_cast<Array<T>*>(static_cast<JSONArrayBase*>(array.get()));
}
@@ -819,7 +797,7 @@ struct ArrayItemHelper<TypeBuilder::Array<T> > {
${forwards}
-String getEnumConstantValue(int code);
+CORE_EXPORT String getEnumConstantValue(int code);
${typeBuilders}
} // namespace TypeBuilder
@@ -899,7 +877,7 @@ class_binding_builder_part_1 = (
Builder(PassRefPtr</*%s*/JSONObject> ptr)
{
- COMPILE_ASSERT(STATE == NoFieldsSet, builder_created_in_non_init_state);
+ static_assert(STATE == NoFieldsSet, "builder should not be created in non-init state");
m_result = ptr;
}
friend class %s;
@@ -909,7 +887,7 @@ class_binding_builder_part_1 = (
class_binding_builder_part_2 = ("""
Builder<STATE | %s>& set%s(%s value)
{
- COMPILE_ASSERT(!(STATE & %s), property_%s_already_set);
+ static_assert(!(STATE & %s), "property %s should not be set yet");
m_result->set%s("%s", %s);
return castState<%s>();
}
@@ -918,8 +896,8 @@ class_binding_builder_part_2 = ("""
class_binding_builder_part_3 = ("""
operator RefPtr<%s>& ()
{
- COMPILE_ASSERT(STATE == AllFieldsSet, result_is_not_ready);
- COMPILE_ASSERT(sizeof(%s) == sizeof(JSONObject), cannot_cast);
+ static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
+ static_assert(sizeof(%s) == sizeof(JSONObject), "%s should be the same size as JSONObject");
return *reinterpret_cast<RefPtr<%s>*>(&m_result);
}
« no previous file with comments | « core/inspector/CodeGeneratorInspector.py ('k') | core/inspector/CodeGeneratorInstrumentation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698