X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/51a72a9d652bf1b478bffc842feb68dee5d8744e..5a2ae41928193b489e490abb580abc2fa53181ea:/Library.cpp diff --git a/Library.cpp b/Library.cpp index cbeeb2a..cccd69b 100644 --- a/Library.cpp +++ b/Library.cpp @@ -145,7 +145,7 @@ _finline size_t iconv_(size_t (*iconv)(iconv_t, Type_, size_t *, char **, size_t return iconv(cd, const_cast(inbuf), inbytesleft, outbuf, outbytesleft); } -static CYUTF8String CYPoolUTF8String(apr_pool_t *pool, JSContextRef context, JSStringRef value) { +CYUTF8String CYPoolUTF8String(apr_pool_t *pool, JSContextRef context, JSStringRef value) { _assert(pool != NULL); CYUTF16String utf16(CYCastUTF16String(value)); @@ -1302,19 +1302,24 @@ static JSStaticFunction Type_staticFunctions[4] = { {NULL, NULL, 0} }; +static JSObjectRef (*$JSObjectMakeArray)(JSContextRef, size_t, const JSValueRef[], JSValueRef *); + void CYSetArgs(int argc, const char *argv[]) { JSContextRef context(CYGetJSContext()); JSValueRef args[argc]; for (int i(0); i != argc; ++i) args[i] = CYCastJSValue(context, argv[i]); -#ifdef __APPLE__ - JSValueRef exception(NULL); - JSObjectRef array(JSObjectMakeArray(context, argc, args, &exception)); - CYThrow(context, exception); -#else - JSValueRef value(CYCallAsFunction(context, Array_, NULL, argc, args)); - JSObjectRef array(CYCastJSObject(context, value)); -#endif + + JSObjectRef array; + if ($JSObjectMakeArray != NULL) { + JSValueRef exception(NULL); + array = (*$JSObjectMakeArray)(context, argc, args, &exception); + CYThrow(context, exception); + } else { + JSValueRef value(CYCallAsFunction(context, Array_, NULL, argc, args)); + array = CYCastJSObject(context, value); + } + CYSetProperty(context, System_, CYJSString("args"), array); } @@ -1376,6 +1381,8 @@ void CYInitialize() { _aprcall(apr_initialize()); _aprcall(apr_pool_create(&Pool_, NULL)); _sqlcall(sqlite3_open("/usr/lib/libcycript.db", &Bridge_)); + + $JSObjectMakeArray = reinterpret_cast(dlsym(RTLD_DEFAULT, "JSObjectMakeArray")); } apr_pool_t *CYGetGlobalPool() { @@ -1442,8 +1449,6 @@ CYJSError::CYJSError(JSContextRef context, const char *format, ...) { CYThrow(context, exception); } -void CYObjectiveC(JSContextRef context, JSObjectRef global); - JSGlobalContextRef CYGetJSContext() { CYInitialize(); @@ -1562,10 +1567,8 @@ JSGlobalContextRef CYGetJSContext() { Result_ = JSStringCreateWithUTF8CString("_"); -// XXX: this is very wrong and sad -#ifdef __APPLE__ - CYObjectiveC(context, global); -#endif + if (hooks_ != NULL && hooks_->SetupContext != NULL) + (*hooks_->SetupContext)(context); } return Context_;