LEFT | RIGHT |
1 #ifndef ADBLOCK_PLUS_DEBUG_H | 1 #pragma once |
2 #define ADBLOCK_PLUS_DEBUG_H | |
3 | 2 |
4 #include <emscripten.h> | 3 #include <emscripten.h> |
5 #include <emscripten/trace.h> | 4 #include <emscripten/trace.h> |
6 | 5 |
7 #if defined(assert) | 6 #if defined(assert) |
8 #undef assert | 7 #undef assert |
9 #endif | 8 #endif |
10 | 9 |
11 class String; | 10 class String; |
12 | 11 |
13 struct console_type | 12 struct console_type |
14 { | 13 { |
15 static void log(const String& str) | 14 static void log(const String& str) |
16 { | 15 { |
17 EM_ASM_ARGS(console.log(getStringData($0)), &str); | 16 EM_ASM_ARGS(console.log(readString($0)), &str); |
18 } | 17 } |
19 | 18 |
20 static void log(int i) | 19 static void log(int i) |
21 { | 20 { |
22 EM_ASM_ARGS(console.log($0), i); | 21 EM_ASM_ARGS(console.log($0), i); |
23 } | 22 } |
24 | 23 |
25 static void log(void* ptr) | 24 static void log(void* ptr) |
26 { | 25 { |
27 EM_ASM_ARGS(console.log($0), ptr); | 26 EM_ASM_ARGS(console.log($0), ptr); |
28 } | 27 } |
29 | 28 |
30 static void error(const String& str) | 29 static void error(const String& str) |
31 { | 30 { |
32 EM_ASM_ARGS(console.error(new Error(getStringData($0)).stack), &str); | 31 EM_ASM_ARGS(console.error(new Error(readString($0)).stack), &str); |
33 } | 32 } |
34 }; | 33 }; |
35 | 34 |
36 static console_type console; | 35 static console_type console; |
37 | 36 |
| 37 #if defined(DEBUG) |
38 inline void assert(bool condition, const String& str) | 38 inline void assert(bool condition, const String& str) |
39 { | 39 { |
40 #if defined(DEBUG) | |
41 if (!condition) | 40 if (!condition) |
42 console.error(str); | 41 console.error(str); |
| 42 } |
| 43 #else |
| 44 #define assert(condition, str) |
43 #endif | 45 #endif |
44 } | |
45 | 46 |
46 inline void annotate_address(void* address, const char* name) | 47 inline void annotate_address(void* address, const char* name) |
47 { | 48 { |
48 #if defined(__EMSCRIPTEN_TRACING__) | 49 #if defined(__EMSCRIPTEN_TRACING__) |
49 emscripten_trace_annotate_address_type(address, name); | 50 emscripten_trace_annotate_address_type(address, name); |
50 #endif | 51 #endif |
51 } | 52 } |
52 | 53 |
53 inline void enter_context(const char* context) | 54 inline void enter_context(const char* context) |
54 { | 55 { |
55 #if defined(__EMSCRIPTEN_TRACING__) | 56 #if defined(__EMSCRIPTEN_TRACING__) |
56 emscripten_trace_enter_context(context); | 57 emscripten_trace_enter_context(context); |
57 #endif | 58 #endif |
58 } | 59 } |
59 | 60 |
60 inline void exit_context() | 61 inline void exit_context() |
61 { | 62 { |
62 #if defined(__EMSCRIPTEN_TRACING__) | 63 #if defined(__EMSCRIPTEN_TRACING__) |
63 emscripten_trace_exit_context(); | 64 emscripten_trace_exit_context(); |
64 #endif | 65 #endif |
65 } | 66 } |
66 | |
67 #endif | |
LEFT | RIGHT |