Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #pragma once | |
2 | |
3 #include <emscripten.h> | |
4 #include <emscripten/trace.h> | |
5 | |
6 #if defined(assert) | |
7 #undef assert | |
8 #endif | |
9 | |
10 class String; | |
11 | |
12 struct console_type | |
13 { | |
14 static void log(const String& str) | |
15 { | |
16 EM_ASM_ARGS(console.log(readString($0)), &str); | |
17 } | |
18 | |
19 static void log(int i) | |
20 { | |
21 EM_ASM_ARGS(console.log($0), i); | |
22 } | |
23 | |
24 static void log(void* ptr) | |
25 { | |
26 EM_ASM_ARGS(console.log($0), ptr); | |
27 } | |
28 | |
29 static void error(const String& str) | |
30 { | |
31 EM_ASM_ARGS(console.error(new Error(readString($0)).stack), &str); | |
32 } | |
33 }; | |
34 | |
35 static console_type console; | |
sergei
2017/01/10 15:58:12
Why do we need a global static variable of a class
Wladimir Palant
2017/03/13 17:42:32
Just so that one can call `console.log()` the way
sergei
2017/03/20 17:06:58
`console.log()` calls a method of `console` object
| |
36 | |
37 #if defined(DEBUG) | |
38 inline void assert(bool condition, const String& str) | |
39 { | |
40 if (!condition) | |
41 console.error(str); | |
42 } | |
43 #else | |
44 #define assert(condition, str) | |
45 #endif | |
46 | |
47 inline void annotate_address(void* address, const char* name) | |
48 { | |
49 #if defined(__EMSCRIPTEN_TRACING__) | |
50 emscripten_trace_annotate_address_type(address, name); | |
51 #endif | |
52 } | |
53 | |
54 inline void enter_context(const char* context) | |
55 { | |
56 #if defined(__EMSCRIPTEN_TRACING__) | |
57 emscripten_trace_enter_context(context); | |
58 #endif | |
59 } | |
60 | |
61 inline void exit_context() | |
62 { | |
63 #if defined(__EMSCRIPTEN_TRACING__) | |
64 emscripten_trace_exit_context(); | |
65 #endif | |
66 } | |
OLD | NEW |