Source/WebCore/ChangeLog

 12012-05-22 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 NOBODY (OOPS!).
 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
 12 * inspector/CodeGeneratorInspector.py:
 13 (TypeModel.RefPtrBased):
 14 (TypeModel.Enum):
 15 (TypeModel.ValueType):
 16 (TypeModel.ExactlyInt):
 17 (TypeModel.ExactlyInt.__init__):
 18 (TypeModel.ExactlyInt.get_input_param_type_text):
 19 (TypeModel.init_class):
 20 (ExactlyInt):
 21 (that):
 22 (ExactlyIntHelper):
 23
1242012-05-21 Joshua Bell <jsbell@chromium.org>
225
326 IndexedDB: Store key paths in IDBKeyPath type instead of String

Source/WebCore/inspector/CodeGeneratorInspector.py

@@class CommandReturnPassModel:
622622
623623
624624class TypeModel:
625  class RefPtrBased:
 625 class RefPtrBased(object):
626626 def __init__(self, class_name):
627627 self.class_name = class_name
628628 self.optional = False

@@class TypeModel:
646646 def get_event_setter_expression_pattern():
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"
652652

@@class TypeModel:
679679 def get_event_setter_expression_pattern():
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
685685 self.is_heavy = is_heavy

@@class TypeModel:
696696 else:
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():
701704 return "%s"

@@class TypeModel:
708711 return self
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):
714717 return "const %s* const" % self.base.type_name

@@class TypeModel:
717720 def get_event_setter_expression_pattern():
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")
728741 cls.Any = cls.RefPtrBased("InspectorValue")

@@private:
22242237};
22252238
22262239
 2240// A small trancient wrapper around int type, that can be used as a funciton parameter type
 2241// cleverly diallowing C++ implicit casts from float or double.
 2242class ExactlyInt {
 2243public:
 2244 template<typename T>
 2245 ExactlyInt(T t);
 2246
 2247 ExactlyInt() {}
 2248
 2249 operator int() { return m_value; }
 2250private:
 2251 int m_value;
 2252};
 2253
 2254// A helper template class that has 'cast' method for all parameter types except float and double.
 2255template<typename T>
 2256class ExactlyIntHelper {
 2257public:
 2258 static inline int cast(T t) { return t; }
 2259};
 2260
 2261template<> class ExactlyIntHelper<float> { /* no cast method for float */ };
 2262template<> class ExactlyIntHelper<double> { /* no cast method for double */ };
 2263
 2264template<typename T>
 2265inline ExactlyInt::ExactlyInt(T t) : m_value(ExactlyIntHelper<T>::cast(t)) {}
 2266
 2267
22272268// This class provides "Traits" type for the input type T. It is programmed using C++ template specialization
22282269// technique. By default it simply takes "ItemTraits" type from T, but it doesn't work with the base types.
22292270template<typename T>