]> git.saurik.com Git - cycript.git/commitdiff
Move Cydget* to ObjectiveC and @throw exceptions.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 17 Jan 2014 20:49:35 +0000 (12:49 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 17 Jan 2014 20:49:35 +0000 (12:49 -0800)
Execute.cpp
Library.cpp
ObjectiveC/Library.mm

index aff9a7e50cda572da73bb5bdd723d232112f29b6..be05f7b468ca1deee3a04284f1135141ba87e831 100644 (file)
@@ -1410,10 +1410,6 @@ const char *CYExecute(JSContextRef context, CYPool &pool, CYUTF8String code) {
     }
 }
 
-extern "C" void CydgetSetupContext(JSGlobalContextRef context) {
-    CYSetupContext(context);
-}
-
 static bool initialized_ = false;
 
 void CYInitializeDynamic() {
@@ -1590,8 +1586,10 @@ static void CYRunSetups(JSContextRef context) {
         CYUTF16String utf16(CYPoolUTF16String(pool, utf8));
         munmap(const_cast<char *>(utf8.data), utf8.size);
 
-        if (CydgetMemoryParse(&utf16.data, &utf16.size))
-            CYExecute(context, pool, CYPoolUTF8String(pool, utf16));
+        // XXX: this should not be used
+        CydgetMemoryParse(&utf16.data, &utf16.size);
+
+        CYExecute(context, pool, CYPoolUTF8String(pool, utf16));
         free(const_cast<uint16_t *>(utf16.data));
     }
 
index 5be04f4b03a5422b9c9e0a7cec65046ed7d75fbb..74df5029d99e83216df8e0128f78a1c273bb37cb 100644 (file)
@@ -210,28 +210,6 @@ CYUTF8String CYPoolCode(CYPool &pool, CYUTF8String code) {
     return $pool.strdup(str.str().c_str());
 }
 
-extern "C" bool CydgetMemoryParse(const uint16_t **data, size_t *size) {
-    CYPool pool;
-
-    CYUTF8String utf8(CYPoolUTF8String(pool, CYUTF16String(*data, *size)));
-    try {
-        utf8 = CYPoolCode(pool, utf8);
-    } catch (const CYException &) {
-        *data = NULL;
-        *size = 0;
-        return false;
-    }
-
-    CYUTF16String utf16(CYPoolUTF16String(pool, CYUTF8String(utf8.data, utf8.size)));
-    size_t bytes(utf16.size * sizeof(uint16_t));
-    uint16_t *copy(reinterpret_cast<uint16_t *>(malloc(bytes)));
-    memcpy(copy, utf16.data, bytes);
-
-    *data = copy;
-    *size = utf16.size;
-    return true;
-}
-
 CYPool &CYGetGlobalPool() {
     static CYPool pool;
     return pool;
index 268edcd87741811534fb09bd0cd7b9c304aa7dea..b6410c7471507cddbd3e158379ab6861bcac5ca2 100644 (file)
@@ -2988,3 +2988,25 @@ struct CYObjectiveC {
         _assert(hooks_ != NULL);
     }
 } CYObjectiveC;
+
+extern "C" void CydgetSetupContext(JSGlobalContextRef context) { CYObjectiveTry_ {
+    CYSetupContext(context);
+} CYObjectiveCatch }
+
+extern "C" void CydgetMemoryParse(const uint16_t **data, size_t *size) { try {
+    CYPool pool;
+
+    CYUTF8String utf8(CYPoolUTF8String(pool, CYUTF16String(*data, *size)));
+    utf8 = CYPoolCode(pool, utf8);
+
+    CYUTF16String utf16(CYPoolUTF16String(pool, CYUTF8String(utf8.data, utf8.size)));
+    size_t bytes(utf16.size * sizeof(uint16_t));
+    uint16_t *copy(reinterpret_cast<uint16_t *>(malloc(bytes)));
+    memcpy(copy, utf16.data, bytes);
+
+    *data = copy;
+    *size = utf16.size;
+} catch (const CYException &exception) {
+    CYPool pool;
+    @throw [NSException exceptionWithName:NSRangeException reason:[NSString stringWithFormat:@"%s", exception.PoolCString(pool)] userInfo:nil];
+} }