summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/modules/js')
-rw-r--r--sca-cpp/trunk/modules/js/eval.hpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp
index b36c9e6119..f18c3e41c9 100644
--- a/sca-cpp/trunk/modules/js/eval.hpp
+++ b/sca-cpp/trunk/modules/js/eval.hpp
@@ -103,14 +103,23 @@ JSClass jsGlobalClass = { "global", JSCLASS_GLOBAL_FLAGS,
JSCLASS_NO_OPTIONAL_MEMBERS };
/**
- * Represents a JavaScript context. Create one per thread.
+ * Represents a JavaScript context. Maintains one context per thread.
*/
+#ifdef WANT_THREADS
+__thread
+#endif
+::JSContext* jsContext = NULL;
+
class JSContext {
public:
JSContext() {
- // Create JS context
+ // Create JS context if necessary
debug("js::jscontext");
- cx = JS_NewContext(jsRuntime, 8192);
+ if (jsContext != NULL) {
+ cx = jsContext;
+ return;
+ }
+ cx = JS_NewContext(jsRuntime, 32768);
if(cx == NULL)
return;
JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
@@ -129,10 +138,13 @@ public:
cleanup();
return;
}
+ jsContext = cx;
}
~JSContext() {
debug("js::~jscontext");
+ if (cx != NULL)
+ JS_GC(cx);
cleanup();
}
@@ -147,7 +159,8 @@ public:
private:
bool cleanup() {
if(cx != NULL) {
- JS_DestroyContext(cx);
+ if (cx != jsContext)
+ JS_DestroyContext(cx);
cx = NULL;
}
return true;