summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/implscope.cpp
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2015-10-07 13:50:46 -0400
committerAndrew Morrow <acm@mongodb.com>2015-10-12 12:25:23 -0400
commit644e0a886850763603de5c40498c26f78c1f4751 (patch)
tree10183e54ab450ee4175200cbf1cda65229d9fa25 /src/mongo/scripting/mozjs/implscope.cpp
parent86df469d26ef8482ffcf5753929b8a5102086b90 (diff)
downloadmongo-644e0a886850763603de5c40498c26f78c1f4751.tar.gz
SERVER-20678 Create a new JS scope for each mapreduce
Diffstat (limited to 'src/mongo/scripting/mozjs/implscope.cpp')
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 9c2412ef62f..aa2cd004d8f 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -204,6 +204,15 @@ void MozJSImplScope::_gcCallback(JSRuntime* rt, JSGCStatus status, void* data) {
MozJSImplScope::MozRuntime::MozRuntime() {
mongo::sm::reset(kMallocMemoryLimit);
+ // If this runtime isn't running on an NSPR thread, then it is
+ // running on a mongo thread. In that case, we need to insert a
+ // fake NSPR thread so that the SM runtime can call PR functions
+ // without falling over.
+ auto thread = PR_GetCurrentThread();
+ if (!thread) {
+ PR_BindThread(_thread = PR_CreateFakeThread());
+ }
+
{
stdx::unique_lock<stdx::mutex> lk(gRuntimeCreationMutex);
@@ -232,6 +241,12 @@ MozJSImplScope::MozRuntime::MozRuntime() {
MozJSImplScope::MozRuntime::~MozRuntime() {
JS_DestroyContext(_context);
JS_DestroyRuntime(_runtime);
+
+ if (_thread) {
+ invariant(PR_GetCurrentThread() == _thread);
+ PR_DestroyFakeThread(_thread);
+ PR_BindThread(nullptr);
+ }
}
MozJSImplScope::MozJSImplScope(MozJSScriptEngine* engine)