From 8fab8594db1ad0dd8d0cfe1270993d5aa49215f5 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 20 Jan 2014 04:40:43 -0800 Subject: [PATCH] Provide a new ?destroy to release the JSContext. --- Console.cpp | 2 ++ Execute.cpp | 11 +++++++++-- JavaScript.hpp | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) 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_; -- 2.50.0