]> git.saurik.com Git - cycript.git/blobdiff - Execute.cpp
I really really want some kind of Error monad :(.
[cycript.git] / Execute.cpp
index 5df5f60f51ab94633b43bb7d540e7b4b204e09e9..ca0b6174f13a0e593cb08d258453e2b5ed3576fc 100644 (file)
@@ -443,27 +443,33 @@ const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSObjectRef object)
     bool comma(false);
 
     for (size_t index(0), count(JSPropertyNameArrayGetCount(names)); index != count; ++index) {
-        JSStringRef name(JSPropertyNameArrayGetNameAtIndex(names, index));
-        JSValueRef value(CYGetProperty(context, object, name));
-
         if (comma)
             str << ',';
         else
             comma = true;
 
+        JSStringRef name(JSPropertyNameArrayGetNameAtIndex(names, index));
         CYUTF8String string(CYPoolUTF8String(pool, context, name));
+
         if (CYIsKey(string))
             str << string.data;
         else
             CYStringify(str, string.data, string.size);
 
-        str << ':' << CYPoolCCYON(pool, context, value);
-    }
+        str << ':';
 
-    str << '}';
+        try {
+            JSValueRef value(CYGetProperty(context, object, name));
+            str << CYPoolCCYON(pool, context, value);
+        } catch (const CYException &error) {
+            str << "@error";
+        }
+    }
 
     JSPropertyNameArrayRelease(names);
 
+    str << '}';
+
     std::string string(str.str());
     return pool.strmemdup(string.c_str(), string.size());
 }
@@ -949,7 +955,7 @@ static void Struct_getPropertyNames(JSContextRef context, JSObjectRef object, JS
     }
 }
 
-JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)()) { CYTry {
+JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, sig::Signature *signature, ffi_cif *cif, void (*function)()) {
     if (setups + count != signature->count - 1)
         throw CYJSError(context, "incorrect number of arguments to ffi function");
 
@@ -973,12 +979,12 @@ JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, voi
         ffi_call(cif, function, value, values);
 
     return CYFromFFI(context, signature->elements[0].type, cif->rtype, value, initialize);
-} CYCatch(NULL) }
+}
 
 static JSValueRef Functor_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
     CYPool pool;
     cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(object)));
-    return CYCallFunction(pool, context, 0, NULL, count, arguments, false, exception, &internal->signature_, &internal->cif_, internal->GetValue());
+    return CYCallFunction(pool, context, 0, NULL, count, arguments, false, &internal->signature_, &internal->cif_, internal->GetValue());
 } CYCatch(NULL) }
 
 JSObjectRef CYMakeType(JSContextRef context, const char *type) {