[webkit-changes] cvs commit: JavaScriptCore/kxmlcore HashTraits.h
Geoffrey
ggaren at opensource.apple.com
Wed Dec 21 16:55:34 PST 2005
ggaren 05/12/21 16:55:34
Modified: . ChangeLog
JavaScriptCore.xcodeproj project.pbxproj
kjs testkjs.cpp
kxmlcore HashTraits.h
Log:
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.
Revision Changes Path
1.918 +15 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.917
retrieving revision 1.918
diff -u -r1.917 -r1.918
--- ChangeLog 20 Dec 2005 20:48:55 -0000 1.917
+++ ChangeLog 22 Dec 2005 00:55:31 -0000 1.918
@@ -1,3 +1,18 @@
+2005-12-21 Geoffrey Garen <ggaren at apple.com>
+
+ 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.
+
2005-12-20 Maciej Stachowiak <mjs at apple.com>
Reviewed by Darin.
1.30 +1 -1 JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Index: project.pbxproj
===================================================================
RCS file: /cvs/root/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- project.pbxproj 19 Dec 2005 19:53:09 -0000 1.29
+++ project.pbxproj 22 Dec 2005 00:55:33 -0000 1.30
@@ -277,7 +277,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
- 45E12D8806A49B0F00E9DF84 /* testkjs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = testkjs.cpp; sourceTree = "<group>"; };
+ 45E12D8806A49B0F00E9DF84 /* testkjs.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = testkjs.cpp; sourceTree = "<group>"; };
5114F47B05E4426200D1BBBD /* runtime_root.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = runtime_root.cpp; path = bindings/runtime_root.cpp; sourceTree = "<group>"; };
5114F47C05E4426200D1BBBD /* runtime_root.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = runtime_root.h; path = bindings/runtime_root.h; sourceTree = "<group>"; };
511B0870056468730080E486 /* runtime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = runtime.h; path = bindings/runtime.h; sourceTree = "<group>"; };
1.21 +25 -1 JavaScriptCore/kjs/testkjs.cpp
Index: testkjs.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/testkjs.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- testkjs.cpp 11 Dec 2005 02:05:49 -0000 1.20
+++ testkjs.cpp 22 Dec 2005 00:55:34 -0000 1.21
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
+#include "HashTraits.h"
#include "value.h"
#include "object.h"
#include "types.h"
@@ -34,6 +35,7 @@
#include "JSLock.h"
using namespace KJS;
+using namespace KXMLCore;
class TestFunctionImp : public JSObject {
public:
@@ -105,7 +107,29 @@
bool ret = true;
{
JSLock lock;
-
+
+ // Unit tests for KXMLCore::IsInteger. Don't have a better place for them now.
+ // FIXME: move these once we create a unit test directory for KXMLCore.
+ assert(IsInteger<bool>::value);
+ assert(IsInteger<char>::value);
+ assert(IsInteger<signed char>::value);
+ assert(IsInteger<unsigned char>::value);
+ assert(IsInteger<short>::value);
+ assert(IsInteger<unsigned short>::value);
+ assert(IsInteger<int>::value);
+ assert(IsInteger<unsigned int>::value);
+ assert(IsInteger<long>::value);
+ assert(IsInteger<unsigned long>::value);
+ assert(IsInteger<long long>::value);
+ assert(IsInteger<unsigned long long>::value);
+
+ assert(!IsInteger<char *>::value);
+ assert(!IsInteger<const char *>::value);
+ assert(!IsInteger<volatile char *>::value);
+ assert(!IsInteger<double>::value);
+ assert(!IsInteger<float>::value);
+ assert(!IsInteger<GlobalImp>::value);
+
JSObject *global(new GlobalImp());
// create interpreter
1.3 +16 -11 JavaScriptCore/kxmlcore/HashTraits.h
Index: HashTraits.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kxmlcore/HashTraits.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HashTraits.h 16 Dec 2005 20:33:21 -0000 1.2
+++ HashTraits.h 22 Dec 2005 00:55:34 -0000 1.3
@@ -24,24 +24,29 @@
#define KXMLCORE_HASH_TRAITS_H
#include <utility>
-#ifndef WIN32
-#include <bits/cpp_type_traits.h>
-#endif
namespace KXMLCore {
using std::pair;
-
- // FIXME: stop using this evil hack, use something supported or else specialize
- // for all numerit cypes by hand
+
+ template <typename T> struct IsInteger { static const bool value = false; };
+ template <> struct IsInteger<bool> { static const bool value = true; };
+ template <> struct IsInteger<char> { static const bool value = true; };
+ template <> struct IsInteger<signed char> { static const bool value = true; };
+ template <> struct IsInteger<unsigned char> { static const bool value = true; };
+ template <> struct IsInteger<short> { static const bool value = true; };
+ template <> struct IsInteger<unsigned short> { static const bool value = true; };
+ template <> struct IsInteger<int> { static const bool value = true; };
+ template <> struct IsInteger<unsigned int> { static const bool value = true; };
+ template <> struct IsInteger<long> { static const bool value = true; };
+ template <> struct IsInteger<unsigned long> { static const bool value = true; };
+ template <> struct IsInteger<long long> { static const bool value = true; };
+ template <> struct IsInteger<unsigned long long> { static const bool value = true; };
+
template<typename T>
struct HashTraits {
typedef T traitType;
-#ifdef __GLIBCXX__ // gcc 3.4 and greater:
- static const bool emptyValueIsZero = std::__is_integer<T>::__value;
-#else
- static const bool emptyValueIsZero = std::__is_integer<T>::_M_type;
-#endif
+ static const bool emptyValueIsZero = IsInteger<T>::value;
static traitType emptyValue() {
return traitType();
More information about the webkit-changes
mailing list