Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1068)

Side by Side Diff: include/v8.h

Issue 260002: Add a method to convert unsigned C integer into V8 Integer. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/checks.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
1066 int64_t Value() const; 1067 int64_t Value() const;
1067 static inline Integer* Cast(v8::Value* obj); 1068 static inline Integer* Cast(v8::Value* obj);
1068 private: 1069 private:
1069 Integer(); 1070 Integer();
1070 static void CheckCast(v8::Value* obj); 1071 static void CheckCast(v8::Value* obj);
1071 }; 1072 };
1072 1073
1073 1074
1074 /** 1075 /**
1075 * A JavaScript value representing a 32-bit signed integer. 1076 * A JavaScript value representing a 32-bit signed integer.
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after
3019 3020
3020 3021
3021 Number* Number::Cast(v8::Value* value) { 3022 Number* Number::Cast(v8::Value* value) {
3022 #ifdef V8_ENABLE_CHECKS 3023 #ifdef V8_ENABLE_CHECKS
3023 CheckCast(value); 3024 CheckCast(value);
3024 #endif 3025 #endif
3025 return static_cast<Number*>(value); 3026 return static_cast<Number*>(value);
3026 } 3027 }
3027 3028
3028 3029
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
3029 Integer* Integer::Cast(v8::Value* value) { 3040 Integer* Integer::Cast(v8::Value* value) {
3030 #ifdef V8_ENABLE_CHECKS 3041 #ifdef V8_ENABLE_CHECKS
3031 CheckCast(value); 3042 CheckCast(value);
3032 #endif 3043 #endif
3033 return static_cast<Integer*>(value); 3044 return static_cast<Integer*>(value);
3034 } 3045 }
3035 3046
3036 3047
3037 Date* Date::Cast(v8::Value* value) { 3048 Date* Date::Cast(v8::Value* value) {
3038 #ifdef V8_ENABLE_CHECKS 3049 #ifdef V8_ENABLE_CHECKS
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3103 3114
3104 } // namespace v8 3115 } // namespace v8
3105 3116
3106 3117
3107 #undef V8EXPORT 3118 #undef V8EXPORT
3108 #undef V8EXPORT_INLINE 3119 #undef V8EXPORT_INLINE
3109 #undef TYPE_CHECK 3120 #undef TYPE_CHECK
3110 3121
3111 3122
3112 #endif // V8_H_ 3123 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/checks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698