OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 static void CheckCast(v8::Value* obj); | 1056 static void CheckCast(v8::Value* obj); |
1057 }; | 1057 }; |
1058 | 1058 |
1059 | 1059 |
1060 /** | 1060 /** |
1061 * A JavaScript value representing a signed integer. | 1061 * A JavaScript value representing a signed integer. |
1062 */ | 1062 */ |
1063 class V8EXPORT Integer : public Number { | 1063 class V8EXPORT Integer : public Number { |
1064 public: | 1064 public: |
1065 static Local<Integer> New(int32_t value); | 1065 static Local<Integer> New(int32_t value); |
1066 static inline Local<Integer> New(uint32_t value); | |
1067 int64_t Value() const; | 1066 int64_t Value() const; |
1068 static inline Integer* Cast(v8::Value* obj); | 1067 static inline Integer* Cast(v8::Value* obj); |
1069 private: | 1068 private: |
1070 Integer(); | 1069 Integer(); |
1071 static void CheckCast(v8::Value* obj); | 1070 static void CheckCast(v8::Value* obj); |
1072 }; | 1071 }; |
1073 | 1072 |
1074 | 1073 |
1075 /** | 1074 /** |
1076 * A JavaScript value representing a 32-bit signed integer. | 1075 * A JavaScript value representing a 32-bit signed integer. |
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3020 | 3019 |
3021 | 3020 |
3022 Number* Number::Cast(v8::Value* value) { | 3021 Number* Number::Cast(v8::Value* value) { |
3023 #ifdef V8_ENABLE_CHECKS | 3022 #ifdef V8_ENABLE_CHECKS |
3024 CheckCast(value); | 3023 CheckCast(value); |
3025 #endif | 3024 #endif |
3026 return static_cast<Number*>(value); | 3025 return static_cast<Number*>(value); |
3027 } | 3026 } |
3028 | 3027 |
3029 | 3028 |
3030 Local<Integer> Integer::New(uint32_t value) { | |
3031 // If highest bit is not set, chances are it's SMI. | |
3032 bool could_be_smi = (value & (1 << 31)) == 0; | |
3033 if (could_be_smi) { | |
3034 return Integer::New(static_cast<int32_t>(value)); | |
3035 } | |
3036 return Local<Integer>::Cast(Number::New(value)); | |
3037 } | |
3038 | |
3039 | |
3040 Integer* Integer::Cast(v8::Value* value) { | 3029 Integer* Integer::Cast(v8::Value* value) { |
3041 #ifdef V8_ENABLE_CHECKS | 3030 #ifdef V8_ENABLE_CHECKS |
3042 CheckCast(value); | 3031 CheckCast(value); |
3043 #endif | 3032 #endif |
3044 return static_cast<Integer*>(value); | 3033 return static_cast<Integer*>(value); |
3045 } | 3034 } |
3046 | 3035 |
3047 | 3036 |
3048 Date* Date::Cast(v8::Value* value) { | 3037 Date* Date::Cast(v8::Value* value) { |
3049 #ifdef V8_ENABLE_CHECKS | 3038 #ifdef V8_ENABLE_CHECKS |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3114 | 3103 |
3115 } // namespace v8 | 3104 } // namespace v8 |
3116 | 3105 |
3117 | 3106 |
3118 #undef V8EXPORT | 3107 #undef V8EXPORT |
3119 #undef V8EXPORT_INLINE | 3108 #undef V8EXPORT_INLINE |
3120 #undef TYPE_CHECK | 3109 #undef TYPE_CHECK |
3121 | 3110 |
3122 | 3111 |
3123 #endif // V8_H_ | 3112 #endif // V8_H_ |
OLD | NEW |