00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_CHECKS_H_
00029 #define V8_CHECKS_H_
00030
00031 #include <string.h>
00032
00033 #include "flags.h"
00034
00035 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
00036 void API_Fatal(const char* location, const char* format, ...);
00037
00038
00039
00040 #ifdef DEBUG
00041 #define FATAL(msg) \
00042 V8_Fatal(__FILE__, __LINE__, "%s", (msg))
00043 #define UNIMPLEMENTED() \
00044 V8_Fatal(__FILE__, __LINE__, "unimplemented code")
00045 #define UNREACHABLE() \
00046 V8_Fatal(__FILE__, __LINE__, "unreachable code")
00047 #else
00048 #define FATAL(msg) \
00049 V8_Fatal("", 0, "%s", (msg))
00050 #define UNIMPLEMENTED() \
00051 V8_Fatal("", 0, "unimplemented code")
00052 #define UNREACHABLE() ((void) 0)
00053 #endif
00054
00055
00056
00057 static inline void CheckHelper(const char* file,
00058 int line,
00059 const char* source,
00060 bool condition) {
00061 if (!condition)
00062 V8_Fatal(file, line, "CHECK(%s) failed", source);
00063 }
00064
00065
00066
00067
00068 #define CHECK(condition) CheckHelper(__FILE__, __LINE__, #condition, condition)
00069
00070
00071
00072
00073 static inline void CheckEqualsHelper(const char* file, int line,
00074 const char* expected_source, int expected,
00075 const char* value_source, int value) {
00076 if (expected != value) {
00077 V8_Fatal(file, line,
00078 "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i",
00079 expected_source, value_source, expected, value);
00080 }
00081 }
00082
00083
00084
00085
00086 static inline void CheckNonEqualsHelper(const char* file,
00087 int line,
00088 const char* unexpected_source,
00089 int unexpected,
00090 const char* value_source,
00091 int value) {
00092 if (unexpected == value) {
00093 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i",
00094 unexpected_source, value_source, value);
00095 }
00096 }
00097
00098
00099
00100
00101 static inline void CheckEqualsHelper(const char* file,
00102 int line,
00103 const char* expected_source,
00104 const char* expected,
00105 const char* value_source,
00106 const char* value) {
00107 if (strcmp(expected, value) != 0) {
00108 V8_Fatal(file, line,
00109 "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s",
00110 expected_source, value_source, expected, value);
00111 }
00112 }
00113
00114
00115 static inline void CheckNonEqualsHelper(const char* file,
00116 int line,
00117 const char* expected_source,
00118 const char* expected,
00119 const char* value_source,
00120 const char* value) {
00121 if (expected == value ||
00122 (expected != NULL && value != NULL && strcmp(expected, value) == 0)) {
00123 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s",
00124 expected_source, value_source, value);
00125 }
00126 }
00127
00128
00129
00130
00131 static inline void CheckEqualsHelper(const char* file,
00132 int line,
00133 const char* expected_source,
00134 void* expected,
00135 const char* value_source,
00136 void* value) {
00137 if (expected != value) {
00138 V8_Fatal(file, line,
00139 "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i",
00140 expected_source, value_source,
00141 reinterpret_cast<int>(expected), reinterpret_cast<int>(value));
00142 }
00143 }
00144
00145
00146 static inline void CheckNonEqualsHelper(const char* file,
00147 int line,
00148 const char* expected_source,
00149 void* expected,
00150 const char* value_source,
00151 void* value) {
00152 if (expected == value) {
00153 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i",
00154 expected_source, value_source, reinterpret_cast<int>(value));
00155 }
00156 }
00157
00158
00159
00160
00161 static inline void CheckEqualsHelper(const char* file,
00162 int line,
00163 const char* expected_source,
00164 double expected,
00165 const char* value_source,
00166 double value) {
00167
00168 volatile double* exp = new double[1];
00169 *exp = expected;
00170 volatile double* val = new double[1];
00171 *val = value;
00172 if (*exp != *val) {
00173 V8_Fatal(file, line,
00174 "CHECK_EQ(%s, %s) failed\n# Expected: %f\n# Found: %f",
00175 expected_source, value_source, *exp, *val);
00176 }
00177 delete[] exp;
00178 delete[] val;
00179 }
00180
00181
00182 namespace v8 {
00183 class Value;
00184 template <class T> class Handle;
00185 }
00186
00187
00188 void CheckNonEqualsHelper(const char* file,
00189 int line,
00190 const char* unexpected_source,
00191 v8::Handle<v8::Value> unexpected,
00192 const char* value_source,
00193 v8::Handle<v8::Value> value);
00194
00195
00196 void CheckEqualsHelper(const char* file,
00197 int line,
00198 const char* expected_source,
00199 v8::Handle<v8::Value> expected,
00200 const char* value_source,
00201 v8::Handle<v8::Value> value);
00202
00203
00204 #define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \
00205 #expected, expected, #value, value)
00206
00207
00208 #define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \
00209 #unexpected, unexpected, #value, value)
00210
00211
00212 #define CHECK_GT(a, b) CHECK((a) > (b))
00213 #define CHECK_GE(a, b) CHECK((a) >= (b))
00214
00215
00216
00217
00218
00219 template <bool> class StaticAssertion;
00220 template <> class StaticAssertion<true> { };
00221
00222
00223 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b)
00224 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b
00225
00226
00227
00228
00229
00230 template <int> class StaticAssertionHelper { };
00231 #define STATIC_CHECK(test) \
00232 typedef \
00233 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>(test)>)> \
00234 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__)
00235
00236
00237
00238
00239 #ifdef DEBUG
00240 #define ASSERT(condition) CHECK(condition)
00241 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2)
00242 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2)
00243 #define STATIC_ASSERT(test) STATIC_CHECK(test)
00244 #define SLOW_ASSERT(condition) if (FLAG_enable_slow_asserts) CHECK(condition)
00245 #else
00246 #define ASSERT(condition) ((void) 0)
00247 #define ASSERT_EQ(v1, v2) ((void) 0)
00248 #define ASSERT_NE(v1, v2) ((void) 0)
00249 #define STATIC_ASSERT(test) ((void) 0)
00250 #define SLOW_ASSERT(condition) ((void) 0)
00251 #endif
00252
00253
00254 #define ASSERT_TAG_ALIGNED(address) \
00255 ASSERT((reinterpret_cast<int>(address) & kHeapObjectTagMask) == 0)
00256
00257 #define ASSERT_SIZE_TAG_ALIGNED(size) ASSERT((size & kHeapObjectTagMask) == 0)
00258
00259 #endif // V8_CHECKS_H_