⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 118652 in webkit


Ignore:
Timestamp:
May 28, 2012, 1:03:24 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: CodeGeneratorInspector.py: protect typed API from C++ implicit float to int cast
https://bugs.webkit.org/show_bug.cgi?id=87183

Patch by Peter Rybin <peter.rybin@gmail.com> on 2012-05-28
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):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r118651 r118652  
     12012-05-28  Peter Rybin  <peter.rybin@gmail.com>
     2
     3        Web Inspector: CodeGeneratorInspector.py: protect typed API from C++ implicit float to int cast
     4        https://bugs.webkit.org/show_bug.cgi?id=87183
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        An intermediate C++ class is introduced that uses C++ template technique to control actual type
     9        of its constructor argument.
     10        All input parameters of type "int" now have type ExactlyInt.
     11        All usage sites are fixed accordingly.
     12
     13        * inspector/CodeGeneratorInspector.py:
     14        (TypeModel.RefPtrBased):
     15        (TypeModel.Enum):
     16        (TypeModel.ValueType):
     17        (TypeModel.ValueType.get_opt_output_type_):
     18        (TypeModel.ValueType.ValueOptional.get_command_return_pass_model):
     19        (TypeModel.ExactlyInt):
     20        (TypeModel.ExactlyInt.__init__):
     21        (TypeModel.ExactlyInt.get_input_param_type_text):
     22        (TypeModel.ExactlyInt.get_opt_output_type_):
     23        (TypeModel.init_class):
     24        (ExactlyInt):
     25        * inspector/InspectorAgent.cpp:
     26        (WebCore::InspectorAgent::enable):
     27        (WebCore::InspectorAgent::didCreateWorker):
     28        (WebCore::InspectorAgent::didDestroyWorker):
     29        (WebCore::InspectorAgent::evaluateForTestInFrontend):
     30        * inspector/InspectorApplicationCacheAgent.cpp:
     31        (WebCore::InspectorApplicationCacheAgent::updateApplicationCacheStatus):
     32        (WebCore::InspectorApplicationCacheAgent::getFramesWithManifests):
     33        * inspector/InspectorDOMAgent.cpp:
     34        (WebCore::InspectorDOMAgent::buildObjectForNode):
     35        * inspector/InspectorMemoryAgent.cpp:
     36        (WebCore::jsHeapInfo):
     37        (WebCore::InspectorMemoryAgent::getProcessMemoryDistribution):
     38        * inspector/PageRuntimeAgent.cpp:
     39        (WebCore::PageRuntimeAgent::notifyContextCreated):
     40
    1412012-05-28  Kentaro Hara  <haraken@chromium.org>
    242
  • trunk/Source/WebCore/inspector/CodeGeneratorInspector.py

    r116744 r118652  
    623623
    624624class TypeModel:
    625     class RefPtrBased:
     625    class RefPtrBased(object):
    626626        def __init__(self, class_name):
    627627            self.class_name = class_name
     
    647647            return "%s"
    648648
    649     class Enum:
     649    class Enum(object):
    650650        def __init__(self, base_type_name):
    651651            self.type_name = base_type_name + "::Enum"
     
    680680            return "%s"
    681681
    682     class ValueType:
     682    class ValueType(object):
    683683        def __init__(self, type_name, is_heavy):
    684684            self.type_name = type_name
     
    697697                return self.type_name
    698698
     699        def get_opt_output_type_(self):
     700            return self.type_name
     701
    699702        @staticmethod
    700703        def get_event_setter_expression_pattern():
     
    709712
    710713            def get_command_return_pass_model(self):
    711                 return CommandReturnPassModel.OptOutput(self.base.type_name)
     714                return CommandReturnPassModel.OptOutput(self.base.get_opt_output_type_())
    712715
    713716            def get_input_param_type_text(self):
     
    718721                return "*%s"
    719722
     723    class ExactlyInt(ValueType):
     724        def __init__(self):
     725            TypeModel.ValueType.__init__(self, "int", False)
     726
     727        def get_input_param_type_text(self):
     728            return "TypeBuilder::ExactlyInt"
     729
     730        def get_opt_output_type_(self):
     731            return "TypeBuilder::ExactlyInt"
     732
    720733    @classmethod
    721734    def init_class(cls):
    722735        cls.Bool = cls.ValueType("bool", False)
    723         cls.Int = cls.ValueType("int", False)
     736        cls.Int = cls.ExactlyInt()
    724737        cls.Number = cls.ValueType("double", False)
    725         cls.String = cls.ValueType("String", True)
     738        cls.String = cls.ValueType("String", True,)
    726739        cls.Object = cls.RefPtrBased("InspectorObject")
    727740        cls.Array = cls.RefPtrBased("InspectorArray")
     
    22252238
    22262239
     2240// A small transient wrapper around int type, that can be used as a funciton parameter type
     2241// cleverly disallowing C++ implicit casts from float or double.
     2242class ExactlyInt {
     2243public:
     2244    template<typename T>
     2245    ExactlyInt(T t) : m_value(cast_to_int<T>(t)) {}
     2246
     2247    ExactlyInt() {}
     2248
     2249    operator int() { return m_value; }
     2250private:
     2251    int m_value;
     2252
     2253    template<typename T>
     2254    static int cast_to_int(T t) { return T::default_case_cast_is_not_supported(); }
     2255};
     2256
     2257template<>
     2258inline int ExactlyInt::cast_to_int<int>(int i) { return i; }
     2259
     2260template<>
     2261inline int ExactlyInt::cast_to_int<unsigned int>(unsigned int i) { return i; }
     2262
     2263
    22272264// This class provides "Traits" type for the input type T. It is programmed using C++ template specialization
    22282265// technique. By default it simply takes "ItemTraits" type from T, but it doesn't work with the base types.
  • trunk/Source/WebCore/inspector/InspectorAgent.cpp

    r116740 r118652  
    127127    for (WorkersMap::iterator it = m_workers.begin(); it != workersEnd; ++it) {
    128128        InspectorWorkerResource* worker = it->second.get();
    129         m_frontend->inspector()->didCreateWorker(worker->id(), worker->url(), worker->isSharedWorker());
     129        m_frontend->inspector()->didCreateWorker(static_cast<int>(worker->id()), worker->url(), worker->isSharedWorker());
    130130    }
    131131#endif
     
    135135
    136136    for (Vector<pair<long, String> >::iterator it = m_pendingEvaluateTestCommands.begin(); m_frontend && it != m_pendingEvaluateTestCommands.end(); ++it)
    137         m_frontend->inspector()->evaluateForTestInFrontend((*it).first, (*it).second);
     137        m_frontend->inspector()->evaluateForTestInFrontend(static_cast<int>((*it).first), (*it).second);
    138138    m_pendingEvaluateTestCommands.clear();
    139139}
     
    164164#if ENABLE(JAVASCRIPT_DEBUGGER)
    165165    if (m_inspectedPage && m_frontend && m_state->getBoolean(InspectorAgentState::inspectorAgentEnabled))
    166         m_frontend->inspector()->didCreateWorker(id, url, isSharedWorker);
     166        m_frontend->inspector()->didCreateWorker(static_cast<int>(id), url, isSharedWorker);
    167167#endif
    168168}
     
    178178#if ENABLE(JAVASCRIPT_DEBUGGER)
    179179    if (m_inspectedPage && m_frontend && m_state->getBoolean(InspectorAgentState::inspectorAgentEnabled))
    180         m_frontend->inspector()->didDestroyWorker(id);
     180        m_frontend->inspector()->didDestroyWorker(static_cast<int>(id));
    181181#endif
    182182    m_workers.remove(workerResource);
     
    187187{
    188188    if (m_state->getBoolean(InspectorAgentState::inspectorAgentEnabled))
    189         m_frontend->inspector()->evaluateForTestInFrontend(callId, script);
     189        m_frontend->inspector()->evaluateForTestInFrontend(static_cast<int>(callId), script);
    190190    else
    191191        m_pendingEvaluateTestCommands.append(pair<long, String>(callId, script));
  • trunk/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp

    r115965 r118652  
    9696
    9797    String manifestURL = info.m_manifest.string();
    98     m_frontend->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, status);
     98    m_frontend->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, static_cast<int>(status));
    9999}
    100100
     
    122122                .setFrameId(m_pageAgent->frameId(frame))
    123123                .setManifestURL(manifestURL)
    124                 .setStatus(host->status());
     124                .setStatus(static_cast<int>(host->status()));
    125125            result->addItem(value);
    126126        }
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp

    r117323 r118652  
    12201220    RefPtr<TypeBuilder::DOM::Node> value = TypeBuilder::DOM::Node::create()
    12211221        .setNodeId(id)
    1222         .setNodeType(node->nodeType())
     1222        .setNodeType(static_cast<int>(node->nodeType()))
    12231223        .setNodeName(nodeName)
    12241224        .setLocalName(localName)
  • trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp

    r118368 r118652  
    326326
    327327    RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> totalJsHeap = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::totalJsHeap);
    328     totalJsHeap->setSize(totalJSHeapSize);
     328    totalJsHeap->setSize(static_cast<int>(totalJSHeapSize));
    329329
    330330    RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
    331331    RefPtr<WebCore::TypeBuilder::Memory::MemoryBlock> usedJsHeap = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::usedJsHeap);
    332     usedJsHeap->setSize(usedJSHeapSize);
     332    usedJsHeap->setSize(static_cast<int>(usedJSHeapSize));
    333333    children->addItem(usedJsHeap);
    334334
     
    345345#endif
    346346    processMemory = WebCore::TypeBuilder::Memory::MemoryBlock::create().setName(MemoryBlockName::processPrivateMemory);
    347     processMemory->setSize(privateBytes);
     347    processMemory->setSize(static_cast<int>(privateBytes));
    348348
    349349    RefPtr<TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock> > children = TypeBuilder::Array<WebCore::TypeBuilder::Memory::MemoryBlock>::create();
  • trunk/Source/WebCore/inspector/PageRuntimeAgent.cpp

    r116744 r118652  
    155155    String name = securityOrigin ? securityOrigin->toString() : "";
    156156    m_frontend->isolatedContextCreated(ExecutionContextDescription::create()
    157         .setId(executionContextId)
     157        .setId(static_cast<int>(executionContextId))
    158158        .setIsPageContext(isPageContext)
    159159        .setName(name)
Note: See TracChangeset for help on using the changeset viewer.