Changeset 11719 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Dec 21, 2005, 4:55:34 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Darin.

Removed evil hack for determining if a type is an integer, replaced
with template metaprogramming.

  • JavaScriptCore.xcodeproj/project.pbxproj: Set tab size to 2 for testkjs.cpp
  • kjs/testkjs.cpp: (main): Inserted asserts to test IsInteger. FIXME: Move these to KXMLCore unit tests directory when we create one.
  • kxmlcore/HashTraits.h: (KXMLCore::): Added IsInteger class for querying types.
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r11690 r11719  
     12005-12-21  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Darin.
     4
     5        Removed evil hack for determining if a type is an integer, replaced
     6        with template metaprogramming.
     7
     8        * JavaScriptCore.xcodeproj/project.pbxproj: Set tab size to 2 for
     9        testkjs.cpp
     10        * kjs/testkjs.cpp:
     11        (main): Inserted asserts to test IsInteger. FIXME: Move these to
     12        KXMLCore unit tests directory when we create one.
     13        * kxmlcore/HashTraits.h:
     14        (KXMLCore::): Added IsInteger class for querying types.
     15
    1162005-12-20  Maciej Stachowiak  <[email protected]>
    217
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r11667 r11719  
    278278
    279279/* Begin PBXFileReference section */
    280                 45E12D8806A49B0F00E9DF84 /* testkjs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = testkjs.cpp; sourceTree = "<group>"; };
     280                45E12D8806A49B0F00E9DF84 /* testkjs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = testkjs.cpp; sourceTree = "<group>"; };
    281281                5114F47B05E4426200D1BBBD /* runtime_root.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = runtime_root.cpp; path = bindings/runtime_root.cpp; sourceTree = "<group>"; };
    282282                5114F47C05E4426200D1BBBD /* runtime_root.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = runtime_root.h; path = bindings/runtime_root.h; sourceTree = "<group>"; };
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r11527 r11719  
    2727#include <string.h>
    2828
     29#include "HashTraits.h"
    2930#include "value.h"
    3031#include "object.h"
     
    3536
    3637using namespace KJS;
     38using namespace KXMLCore;
    3739
    3840class TestFunctionImp : public JSObject {
     
    106108  {
    107109    JSLock lock;
    108 
     110   
     111    // Unit tests for KXMLCore::IsInteger. Don't have a better place for them now.
     112    // FIXME: move these once we create a unit test directory for KXMLCore.
     113    assert(IsInteger<bool>::value);
     114    assert(IsInteger<char>::value);
     115    assert(IsInteger<signed char>::value);
     116    assert(IsInteger<unsigned char>::value);
     117    assert(IsInteger<short>::value);
     118    assert(IsInteger<unsigned short>::value);
     119    assert(IsInteger<int>::value);
     120    assert(IsInteger<unsigned int>::value);
     121    assert(IsInteger<long>::value);
     122    assert(IsInteger<unsigned long>::value);
     123    assert(IsInteger<long long>::value);
     124    assert(IsInteger<unsigned long long>::value);
     125
     126    assert(!IsInteger<char *>::value);
     127    assert(!IsInteger<const char *>::value);
     128    assert(!IsInteger<volatile char *>::value);
     129    assert(!IsInteger<double>::value);
     130    assert(!IsInteger<float>::value);
     131    assert(!IsInteger<GlobalImp>::value);
     132   
    109133    JSObject *global(new GlobalImp());
    110134
  • trunk/JavaScriptCore/kxmlcore/HashTraits.h

    r11628 r11719  
    2525
    2626#include <utility>
    27 #ifndef WIN32
    28 #include <bits/cpp_type_traits.h>
    29 #endif
    3027
    3128namespace KXMLCore {
    3229
    3330    using std::pair;
    34  
    35     // FIXME: stop using this evil hack, use something supported or else specialize
    36     // for all numerit cypes by hand
     31   
     32    template <typename T> struct IsInteger           { static const bool value = false; };
     33    template <> struct IsInteger<bool>               { static const bool value = true; };
     34    template <> struct IsInteger<char>               { static const bool value = true; };
     35    template <> struct IsInteger<signed char>        { static const bool value = true; };
     36    template <> struct IsInteger<unsigned char>      { static const bool value = true; };
     37    template <> struct IsInteger<short>              { static const bool value = true; };
     38    template <> struct IsInteger<unsigned short>     { static const bool value = true; };
     39    template <> struct IsInteger<int>                { static const bool value = true; };
     40    template <> struct IsInteger<unsigned int>       { static const bool value = true; };
     41    template <> struct IsInteger<long>               { static const bool value = true; };
     42    template <> struct IsInteger<unsigned long>      { static const bool value = true; };
     43    template <> struct IsInteger<long long>          { static const bool value = true; };
     44    template <> struct IsInteger<unsigned long long> { static const bool value = true; };
     45       
    3746    template<typename T>
    3847    struct HashTraits {
    3948        typedef T traitType;
    40 #ifdef __GLIBCXX__ // gcc 3.4 and greater:
    41         static const bool emptyValueIsZero = std::__is_integer<T>::__value;
    42 #else
    43         static const bool emptyValueIsZero = std::__is_integer<T>::_M_type;
    44 #endif
     49        static const bool emptyValueIsZero = IsInteger<T>::value;
    4550       
    4651        static traitType emptyValue() {
Note: See TracChangeset for help on using the changeset viewer.