From: Jay Freeman (saurik) Date: Mon, 20 Jan 2014 12:40:43 +0000 (-0800) Subject: Provide a new ?destroy to release the JSContext. X-Git-Tag: v0.9.500~26 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/8fab8594db1ad0dd8d0cfe1270993d5aa49215f5?ds=sidebyside Provide a new ?destroy to release the JSContext. --- diff --git a/Console.cpp b/Console.cpp index dbb8baa..ec849fe 100644 --- a/Console.cpp +++ b/Console.cpp @@ -497,6 +497,8 @@ static void Console(CYOptions &options) { } else if (data == "debug") { debug = !debug; *out_ << "debug == " << (debug ? "true" : "false") << std::endl; + } else if (data == "destroy") { + CYDestroyContext(); } else if (data == "expand") { expand = !expand; *out_ << "expand == " << (expand ? "true" : "false") << std::endl; diff --git a/Execute.cpp b/Execute.cpp index 61acaf2..b2e0e0a 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1763,11 +1763,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 +1775,10 @@ JSGlobalContextRef CYGetJSContext() { return context_; } + +void CYDestroyContext() { + if (context_ == NULL) + return; + JSGlobalContextRelease(context_); + context_ = NULL; +} diff --git a/JavaScript.hpp b/JavaScript.hpp index 4ce43b6..b863a93 100644 --- a/JavaScript.hpp +++ b/JavaScript.hpp @@ -143,6 +143,8 @@ JSStringRef CYCopyJSString(JSStringRef value); JSStringRef CYCopyJSString(CYUTF8String value); JSStringRef CYCopyJSString(JSContextRef context, JSValueRef value); +void CYDestroyContext(); + class CYJSString { private: JSStringRef string_;