X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/0d64cb32c6d51eac037c39bdb21a68ebdd69ee5e..51b6165e0dd24e4d40ff80e504922f705ddd7b62:/Execute.cpp diff --git a/Execute.cpp b/Execute.cpp index 61acaf2..a71d29f 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -342,8 +342,13 @@ static JSValueRef $cyq(JSContextRef context, JSObjectRef object, JSObjectRef _th return CYCastJSValue(context, name); } CYCatch(NULL) } -static JSValueRef Cycript_gc_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { + +void CYGarbageCollect(JSContextRef context) { JSGarbageCollect(context); +} + +static JSValueRef Cycript_gc_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry { + CYGarbageCollect(context); return CYJSUndefined(context); } CYCatch(NULL) } @@ -1763,11 +1768,11 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) { CYRunSetups(context); } +static JSGlobalContextRef context_; + JSGlobalContextRef CYGetJSContext() { CYInitializeDynamic(); - static JSGlobalContextRef context_; - if (context_ == NULL) { context_ = JSGlobalContextCreate(Global_); CYSetupContext(context_); @@ -1775,3 +1780,10 @@ JSGlobalContextRef CYGetJSContext() { return context_; } + +void CYDestroyContext() { + if (context_ == NULL) + return; + JSGlobalContextRelease(context_); + context_ = NULL; +}