Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/debug.h

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/bindings.ipp ('k') | compiled/intrusive_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/debug.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/debug.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <emscripten.h>
+#include <emscripten/trace.h>
+
+#if defined(assert)
+#undef assert
+#endif
+
+class String;
+
+struct console_type
+{
+ static void log(const String& str)
+ {
+ EM_ASM_ARGS(console.log(readString($0)), &str);
+ }
+
+ static void log(int i)
+ {
+ EM_ASM_ARGS(console.log($0), i);
+ }
+
+ static void log(void* ptr)
+ {
+ EM_ASM_ARGS(console.log($0), ptr);
+ }
+
+ static void error(const String& str)
+ {
+ EM_ASM_ARGS(console.error(new Error(readString($0)).stack), &str);
+ }
+};
+
+static console_type console;
+
+#if defined(DEBUG)
+inline void assert(bool condition, const String& str)
+{
+ if (!condition)
+ console.error(str);
+}
+#else
+#define assert(condition, str)
+#endif
+
+inline void annotate_address(void* address, const char* name)
+{
+#if defined(__EMSCRIPTEN_TRACING__)
+ emscripten_trace_annotate_address_type(address, name);
+#endif
+}
+
+inline void enter_context(const char* context)
+{
+#if defined(__EMSCRIPTEN_TRACING__)
+ emscripten_trace_enter_context(context);
+#endif
+}
+
+inline void exit_context()
+{
+#if defined(__EMSCRIPTEN_TRACING__)
+ emscripten_trace_exit_context();
+#endif
+}
« no previous file with comments | « compiled/bindings.ipp ('k') | compiled/intrusive_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld