X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b09da87b6557610325d46e3294ea0b6aba69ebf0..9e20b0b79b102486480071b3b898d5e64c30e01d:/Application.mm?ds=sidebyside diff --git a/Application.mm b/Application.mm index aaf1d5e..4982830 100644 --- a/Application.mm +++ b/Application.mm @@ -24,10 +24,12 @@ static jmp_buf ctrlc_; -void sigint(int) { +static void sigint(int) { longjmp(ctrlc_, 1); } +static JSStringRef Result_; + void Run(const char *code, FILE *fout) { _pooled JSStringRef script(JSStringCreateWithUTF8CString(code)); @@ -37,30 +39,30 @@ void Run(const char *code, FILE *fout) { _pooled JSValueRef result(JSEvaluateScript(context, script, NULL, NULL, 0, &exception)); JSStringRelease(script); - if (exception != NULL) + if (exception != NULL) { error: result = exception; + exception = NULL; + } if (!JSValueIsUndefined(context, result)) { - CFStringRef json; + CYPool pool; + const char *json; - @try { json: - json = CYCopyJSONString(context, result); - } @catch (id error) { - CYThrow(context, error, &result); - goto json; - } + json = CYPoolJSONString(pool, context, result, &exception); + if (exception != NULL) + goto error; + + CYSetProperty(context, CYGetGlobalObject(context), Result_, result); if (fout != NULL) { - fputs([reinterpret_cast(json) UTF8String], fout); + fputs(json, fout); fputs("\n", fout); fflush(fout); } - - CFRelease(json); } } -void Console() { +static void Console() { bool bypass(false); bool debug(false); @@ -162,7 +164,7 @@ void Console() { fflush(fout); } -void *Map(const char *path, size_t *psize) { +static void *Map(const char *path, size_t *psize) { int fd; _syscall(fd = open(path, O_RDONLY)); @@ -189,6 +191,8 @@ int main(int argc, const char *argv[]) { script = argv[1]; } + Result_ = CYCopyJSString("_"); + if (script == NULL || strcmp(script, "-") == 0) Console(); else {