X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/994434e55343bbe6361a64213bb82eba7f312230..35fa52c0744c970af2daa3c494f21bbe55aec536:/Handler.mm diff --git a/Handler.mm b/Handler.mm index 2a42ef0..4e4ccfe 100644 --- a/Handler.mm +++ b/Handler.mm @@ -38,6 +38,7 @@ /* }}} */ #include "cycript.hpp" +#include "JavaScript.hpp" #include "Pooling.hpp" #include "Parser.hpp" @@ -49,6 +50,11 @@ #include #include +#include +#include +#include +#include + struct CYExecute_ { apr_pool_t *pool_; const char * volatile data_; @@ -93,6 +99,13 @@ struct CYClient : CYClient_ *client = [[[CYClient_ alloc] init] autorelease]; + bool dispatch; + if (CFStringRef mode = CFRunLoopCopyCurrentMode(CFRunLoopGetMain())) { + dispatch = true; + CFRelease(mode); + } else + dispatch = false; + for (;;) { size_t size; if (!CYRecvAll(socket_, &size, sizeof(size))) @@ -115,16 +128,25 @@ struct CYClient : json = NULL; size = _not(size_t); } else { - CYContext context(driver.pool_); + NSAutoreleasePool *ar = [[NSAutoreleasePool alloc] init]; + + CYOptions options; + CYContext context(driver.pool_, options); driver.program_->Replace(context); std::ostringstream str; - CYOutput out(str); + CYOutput out(str, options); out << *driver.program_; std::string code(str.str()); CYExecute_ execute = {pool, code.c_str()}; - [client performSelectorOnMainThread:@selector(execute:) withObject:[NSValue valueWithPointer:&execute] waitUntilDone:YES]; + NSValue *value([NSValue valueWithPointer:&execute]); + if (dispatch) + [client performSelectorOnMainThread:@selector(execute:) withObject:value waitUntilDone:YES]; + else + [client execute:value]; json = execute.data_; size = json == NULL ? _not(size_t) : strlen(json); + + [ar release]; } if (!CYSendAll(socket_, &size, sizeof(size))) @@ -153,7 +175,7 @@ extern "C" void CYHandleClient(apr_pool_t *pool, int socket) { } extern "C" void CYHandleServer(pid_t pid) { - CYInitialize(); + CYInitializeDynamic(); int socket(_syscall(::socket(PF_UNIX, SOCK_STREAM, 0))); try { struct sockaddr_un address;