diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index bed659f028a265a4dbfb713e0a8a243c0736737f..597e14932e3d65777c8031f73f5a42cd7c226e7d 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,18 @@ +2012-01-06 Sam Weinig + + Add a DecayArray type trait as a first step towards merging OwnPtr and OwnArrayPtr + https://bugs.webkit.org/show_bug.cgi?id=75737 + + Reviewed by Anders Carlsson. + + * wtf/TypeTraits.cpp: + * wtf/TypeTraits.h: + Added a DecayArray trait, that can convert T[] and T[3] -> T*. DecayArray + is composed of some helpers which are also exposed, Conditional<>, which + can provide one type or another based on a boolean predicate, IsArray<> + which can deduce array types, and RemoveExtent<>, which removes the extent + from an array type. + 2012-01-06 Oliver Hunt GetByteArrayLength is incorrect diff --git a/Source/JavaScriptCore/wtf/TypeTraits.cpp b/Source/JavaScriptCore/wtf/TypeTraits.cpp index afeaa5e4cd8ead3a2715bfcb1485ad9ce3cb7ee6..b89a76a94a83c07e468ebf700caaf1f85ee434e1 100644 --- a/Source/JavaScriptCore/wtf/TypeTraits.cpp +++ b/Source/JavaScriptCore/wtf/TypeTraits.cpp @@ -139,4 +139,20 @@ COMPILE_ASSERT((!IsSameType::Type>::value), WTF_Test_R COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveReference_int); COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveReference_int_reference); + +typedef int IntArray[]; +typedef int IntArraySized[4]; + +COMPILE_ASSERT((IsArray::value), WTF_Test_IsArray_int_array); +COMPILE_ASSERT((IsArray::value), WTF_Test_IsArray_int_sized_array); + +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveExtent_int_array); +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveReference_int_sized_array); + +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_array); +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_sized_array); + +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_array_reference); +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_sized_array_reference); + } // namespace WTF diff --git a/Source/JavaScriptCore/wtf/TypeTraits.h b/Source/JavaScriptCore/wtf/TypeTraits.h index 6c7466acc3508308943e4815870bb9b71ad34f17..34e8b79a3c5ec79f25c443edec1acfb99e92d5fa 100644 --- a/Source/JavaScriptCore/wtf/TypeTraits.h +++ b/Source/JavaScriptCore/wtf/TypeTraits.h @@ -35,10 +35,14 @@ namespace WTF { // The following are provided in this file: // + // Conditional::Type + // // IsInteger::value // IsPod::value, see the definition for a note about its limitations // IsConvertibleToInteger::value // + // IsArray::value + // // IsSameType::value // // RemovePointer::Type @@ -46,9 +50,15 @@ namespace WTF { // RemoveConst::Type // RemoveVolatile::Type // RemoveConstVolatile::Type + // RemoveExtent::Type + // + // DecayArray::Type // // COMPILE_ASSERT's in TypeTraits.cpp illustrate their usage and what they do. + template struct Conditional { typedef If Type; }; + template struct Conditional { typedef Then Type; }; + template struct IsInteger { static const bool value = false; }; template<> struct IsInteger { static const bool value = true; }; template<> struct IsInteger { static const bool value = true; }; @@ -104,6 +114,20 @@ namespace WTF { static const bool value = IsInteger::value || IsConvertibleToDouble::value, T>::value; }; + + template struct IsArray { + static const bool value = false; + }; + + template struct IsArray { + static const bool value = true; + }; + + template struct IsArray { + static const bool value = true; + }; + + template struct IsSameType { static const bool value = false; }; @@ -182,6 +206,28 @@ namespace WTF { typedef T Type; }; + template struct RemoveExtent { + typedef T Type; + }; + + template struct RemoveExtent { + typedef T Type; + }; + + template struct RemoveExtent { + typedef T Type; + }; + + template struct DecayArray { + typedef typename RemoveReference::Type U; + public: + typedef typename Conditional< + IsArray::value, + typename RemoveExtent::Type*, + typename RemoveConstVolatile::Type + >::Type Type; + }; + #if (defined(__GLIBCXX__) && (__GLIBCXX__ >= 20070724) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || (defined(_MSC_VER) && (_MSC_VER >= 1600)) // GCC's libstdc++ 20070724 and later supports C++ TR1 type_traits in the std namespace.