Diff
Modified: trunk/Source/WebCore/ChangeLog (118651 => 118652)
--- trunk/Source/WebCore/ChangeLog 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/ChangeLog 2012-05-28 08:03:24 UTC (rev 118652)
@@ -1,3 +1,43 @@
+2012-05-28 Peter Rybin <[email protected]>
+
+ Web Inspector: CodeGeneratorInspector.py: protect typed API from C++ implicit float to int cast
+ https://bugs.webkit.org/show_bug.cgi?id=87183
+
+ Reviewed by Yury Semikhatsky.
+
+ An intermediate C++ class is introduced that uses C++ template technique to control actual type
+ of its constructor argument.
+ All input parameters of type "int" now have type ExactlyInt.
+ All usage sites are fixed accordingly.
+
+ * inspector/CodeGeneratorInspector.py:
+ (TypeModel.RefPtrBased):
+ (TypeModel.Enum):
+ (TypeModel.ValueType):
+ (TypeModel.ValueType.get_opt_output_type_):
+ (TypeModel.ValueType.ValueOptional.get_command_return_pass_model):
+ (TypeModel.ExactlyInt):
+ (TypeModel.ExactlyInt.__init__):
+ (TypeModel.ExactlyInt.get_input_param_type_text):
+ (TypeModel.ExactlyInt.get_opt_output_type_):
+ (TypeModel.init_class):
+ (ExactlyInt):
+ * inspector/InspectorAgent.cpp:
+ (WebCore::InspectorAgent::enable):
+ (WebCore::InspectorAgent::didCreateWorker):
+ (WebCore::InspectorAgent::didDestroyWorker):
+ (WebCore::InspectorAgent::evaluateForTestInFrontend):
+ * inspector/InspectorApplicationCacheAgent.cpp:
+ (WebCore::InspectorApplicationCacheAgent::updateApplicationCacheStatus):
+ (WebCore::InspectorApplicationCacheAgent::getFramesWithManifests):
+ * inspector/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::buildObjectForNode):
+ * inspector/InspectorMemoryAgent.cpp:
+ (WebCore::jsHeapInfo):
+ (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
+ * inspector/PageRuntimeAgent.cpp:
+ (WebCore::PageRuntimeAgent::notifyContextCreated):
+
2012-05-28 Kentaro Hara <[email protected]>
Unreviewed. Rebaselined run-binding-tests results.
Modified: trunk/Source/WebCore/inspector/CodeGeneratorInspector.py (118651 => 118652)
--- trunk/Source/WebCore/inspector/CodeGeneratorInspector.py 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/inspector/CodeGeneratorInspector.py 2012-05-28 08:03:24 UTC (rev 118652)
@@ -622,7 +622,7 @@
class TypeModel:
- class RefPtrBased:
+ class RefPtrBased(object):
def __init__(self, class_name):
self.class_name = class_name
self.optional = False
@@ -646,7 +646,7 @@
def get_event_setter_expression_pattern():
return "%s"
- class Enum:
+ class Enum(object):
def __init__(self, base_type_name):
self.type_name = base_type_name + "::Enum"
@@ -679,7 +679,7 @@
def get_event_setter_expression_pattern():
return "%s"
- class ValueType:
+ class ValueType(object):
def __init__(self, type_name, is_heavy):
self.type_name = type_name
self.is_heavy = is_heavy
@@ -696,6 +696,9 @@
else:
return self.type_name
+ def get_opt_output_type_(self):
+ return self.type_name
+
@staticmethod
def get_event_setter_expression_pattern():
return "%s"
@@ -708,7 +711,7 @@
return self
def get_command_return_pass_model(self):
- return CommandReturnPassModel.OptOutput(self.base.type_name)
+ return CommandReturnPassModel.OptOutput(self.base.get_opt_output_type_())
def get_input_param_type_text(self):
return "const %s* const" % self.base.type_name
@@ -717,12 +720,22 @@
def get_event_setter_expression_pattern():
return "*%s"
+ class ExactlyInt(ValueType):
+ def __init__(self):
+ TypeModel.ValueType.__init__(self, "int", False)
+
+ def get_input_param_type_text(self):
+ return "TypeBuilder::ExactlyInt"
+
+ def get_opt_output_type_(self):
+ return "TypeBuilder::ExactlyInt"
+
@classmethod
def init_class(cls):
cls.Bool = cls.ValueType("bool", False)
- cls.Int = cls.ValueType("int", False)
+ cls.Int = cls.ExactlyInt()
cls.Number = cls.ValueType("double", False)
- cls.String = cls.ValueType("String", True)
+ cls.String = cls.ValueType("String", True,)
cls.Object = cls.RefPtrBased("InspectorObject")
cls.Array = cls.RefPtrBased("InspectorArray")
cls.Any = cls.RefPtrBased("InspectorValue")
@@ -2224,6 +2237,30 @@
};
+// A small transient wrapper around int type, that can be used as a funciton parameter type
+// cleverly disallowing C++ implicit casts from float or double.
+class ExactlyInt {
+public:
+ template<typename T>
+ ExactlyInt(T t) : m_value(cast_to_int<T>(t)) {}
+
+ ExactlyInt() {}
+
+ operator int() { return m_value; }
+private:
+ int m_value;
+
+ template<typename T>
+ static int cast_to_int(T t) { return T::default_case_cast_is_not_supported(); }
+};
+
+template<>
+inline int ExactlyInt::cast_to_int<int>(int i) { return i; }
+
+template<>
+inline int ExactlyInt::cast_to_int<unsigned int>(unsigned int i) { return i; }
+
+
// This class provides "Traits" type for the input type T. It is programmed using C++ template specialization
// technique. By default it simply takes "ItemTraits" type from T, but it doesn't work with the base types.
template<typename T>
Modified: trunk/Source/WebCore/inspector/InspectorAgent.cpp (118651 => 118652)
--- trunk/Source/WebCore/inspector/InspectorAgent.cpp 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/inspector/InspectorAgent.cpp 2012-05-28 08:03:24 UTC (rev 118652)
@@ -126,7 +126,7 @@
WorkersMap::iterator workersEnd = m_workers.end();
for (WorkersMap::iterator it = m_workers.begin(); it != workersEnd; ++it) {
InspectorWorkerResource* worker = it->second.get();
- m_frontend->inspector()->didCreateWorker(worker->id(), worker->url(), worker->isSharedWorker());
+ m_frontend->inspector()->didCreateWorker(static_cast<int>(worker->id()), worker->url(), worker->isSharedWorker());
}
#endif
@@ -134,7 +134,7 @@
inspect(m_pendingInspectData.first, m_pendingInspectData.second);
for (Vector<pair<long, String> >::iterator it = m_pendingEvaluateTestCommands.begin(); m_frontend && it != m_pendingEvaluateTestCommands.end(); ++it)
- m_frontend->inspector()->evaluateForTestInFrontend((*it).first, (*it).second);
+ m_frontend->inspector()->evaluateForTestInFrontend(static_cast<int>((*it).first), (*it).second);
m_pendingEvaluateTestCommands.clear();
}
@@ -163,7 +163,7 @@
m_workers.set(id, workerResource);
#if ENABLE(_javascript__DEBUGGER)
if (m_inspectedPage && m_frontend && m_state->getBoolean(InspectorAgentState::inspectorAgentEnabled))
- m_frontend->inspector()->didCreateWorker(id, url, isSharedWorker);
+ m_frontend->inspector()->didCreateWorker(static_cast<int>(id), url, isSharedWorker);
#endif
}
@@ -177,7 +177,7 @@
return;
#if ENABLE(_javascript__DEBUGGER)
if (m_inspectedPage && m_frontend && m_state->getBoolean(InspectorAgentState::inspectorAgentEnabled))
- m_frontend->inspector()->didDestroyWorker(id);
+ m_frontend->inspector()->didDestroyWorker(static_cast<int>(id));
#endif
m_workers.remove(workerResource);
}
@@ -186,7 +186,7 @@
void InspectorAgent::evaluateForTestInFrontend(long callId, const String& script)
{
if (m_state->getBoolean(InspectorAgentState::inspectorAgentEnabled))
- m_frontend->inspector()->evaluateForTestInFrontend(callId, script);
+ m_frontend->inspector()->evaluateForTestInFrontend(static_cast<int>(callId), script);
else
m_pendingEvaluateTestCommands.append(pair<long, String>(callId, script));
}
Modified: trunk/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp (118651 => 118652)
--- trunk/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp 2012-05-28 08:03:24 UTC (rev 118652)
@@ -95,7 +95,7 @@
ApplicationCacheHost::CacheInfo info = host->applicationCacheInfo();
String manifestURL = info.m_manifest.string();
- m_frontend->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, status);
+ m_frontend->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, static_cast<int>(status));
}
void InspectorApplicationCacheAgent::networkStateChanged()
@@ -121,7 +121,7 @@
RefPtr<TypeBuilder::ApplicationCache::FrameWithManifest> value = TypeBuilder::ApplicationCache::FrameWithManifest::create()
.setFrameId(m_pageAgent->frameId(frame))
.setManifestURL(manifestURL)
- .setStatus(host->status());
+ .setStatus(static_cast<int>(host->status()));
result->addItem(value);
}
}
Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (118651 => 118652)
--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp 2012-05-28 08:03:24 UTC (rev 118652)
@@ -1219,7 +1219,7 @@
RefPtr<TypeBuilder::DOM::Node> value = TypeBuilder::DOM::Node::create()
.setNodeId(id)
- .setNodeType(node->nodeType())
+ .setNodeType(static_cast<int>(node->nodeType()))
.setNodeName(nodeName)
.setLocalName(localName)
.setNodeValue(nodeValue);
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (118651 => 118652)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2012-05-28 08:03:24 UTC (rev 118652)
@@ -325,11 +325,11 @@
ScriptGCEvent::getHeapSize(usedJSHeapSize, totalJSHeapSize, jsHeapSizeLimit);
RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> totalJsHeap = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::totalJsHeap);
- totalJsHeap->setSize(totalJSHeapSize);
+ totalJsHeap->setSize(static_cast<int>(totalJSHeapSize));
RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> usedJsHeap = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::usedJsHeap);
- usedJsHeap->setSize(usedJSHeapSize);
+ usedJsHeap->setSize(static_cast<int>(usedJSHeapSize));
children->addItem(usedJsHeap);
totalJsHeap->setChildren(children);
@@ -344,7 +344,7 @@
PlatformSupport::getProcessMemorySize(&privateBytes, &sharedBytes);
#endif
processMemory = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::processPrivateMemory);
- processMemory->setSize(privateBytes);
+ processMemory->setSize(static_cast<int>(privateBytes));
RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
children->addItem(jsHeapInfo());
Modified: trunk/Source/WebCore/inspector/PageRuntimeAgent.cpp (118651 => 118652)
--- trunk/Source/WebCore/inspector/PageRuntimeAgent.cpp 2012-05-28 07:48:23 UTC (rev 118651)
+++ trunk/Source/WebCore/inspector/PageRuntimeAgent.cpp 2012-05-28 08:03:24 UTC (rev 118652)
@@ -154,7 +154,7 @@
long executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState);
String name = securityOrigin ? securityOrigin->toString() : "";
m_frontend->isolatedContextCreated(ExecutionContextDescription::create()
- .setId(executionContextId)
+ .setId(static_cast<int>(executionContextId))
.setIsPageContext(isPageContext)
.setName(name)
.setFrameId(frameId)