]> git.saurik.com Git - cycript.git/blobdiff - Exception.hpp
CYDisplay{Start,Finish} obsolete by rl_redisplay.
[cycript.git] / Exception.hpp
index 97c629cbd6e95496bbc0f3ced5f633e4e6895720..0410fd151398755ab8593cab38bf68e1b1b373f8 100644 (file)
 #include <JavaScriptCore/JSBase.h>
 #endif
 
-#include <apr_pools.h>
+// XXX: does _assert really need this?
+#include <errno.h>
+
 #include "Standard.hpp"
 
+class CYPool;
+
 struct CYException {
     virtual ~CYException() {
     }
 
-    virtual const char *PoolCString(apr_pool_t *pool) const = 0;
+    virtual const char *PoolCString(CYPool &pool) const = 0;
 #ifdef CY_EXECUTE
     virtual JSValueRef CastJSValue(JSContextRef context) const = 0;
 #endif
@@ -99,4 +103,28 @@ void CYThrow(JSContextRef context, JSValueRef value);
     _value; \
 })
 
+struct CYJSException {
+    JSContextRef context_;
+    JSValueRef value_;
+
+    CYJSException(JSContextRef context) :
+        context_(context),
+        value_(NULL)
+    {
+    }
+
+    ~CYJSException() {
+        CYThrow(context_, value_);
+    }
+
+    operator JSValueRef *() {
+        return &value_;
+    }
+};
+
+#define _jsccall(code, args...) ({ \
+    CYJSException _error(context); \
+    (code)(args, _error); \
+})
+
 #endif/*CYCRIPT_ERROR_HPP*/