summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/implscope.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2015-09-16 18:18:46 -0400
committerJason Carey <jcarey@argv.me>2015-09-21 18:25:39 -0400
commitee4f910322988cb9ba4784472a38a16ce2c0cdc9 (patch)
treed06b26e9ef598b71937f1c6aab5f10488663556d /src/mongo/scripting/mozjs/implscope.cpp
parenta74ecb2a746e4d8a8ab78610c07d509788c4d8ad (diff)
downloadmongo-ee4f910322988cb9ba4784472a38a16ce2c0cdc9.tar.gz
SERVER-19607 no recursion in JS -> BSON conversion
Replace functional recursion in javascript object to bson conversion with an explicit stack to minimize the memory cost of processing very deep / cyclical objects. This prevents stack overflows on debug and non-optimized builds on some platforms.
Diffstat (limited to 'src/mongo/scripting/mozjs/implscope.cpp')
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 2f6cf57e2bd..384dd2ce83e 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -278,6 +278,9 @@ MozJSImplScope::MozJSImplScope(MozJSScriptEngine* engine)
_checkErrorState(JS_InitStandardClasses(_context, _global));
installBSONTypes();
+
+ JS_FireOnNewGlobalObject(_context, _global);
+
execSetup(JSFiles::assert);
execSetup(JSFiles::types);
@@ -425,10 +428,11 @@ BSONObj MozJSImplScope::callThreadArgs(const BSONObj& args) {
_checkErrorState(JS::Call(_context, thisv, function, argv, &out), false, true);
- BSONObjBuilder b;
- ValueWriter(_context, out).writeThis(&b, "ret");
+ JS::RootedObject rout(_context, JS_NewPlainObject(_context));
+ ObjectWrapper wout(_context, rout);
+ wout.setValue("ret", out);
- return b.obj();
+ return wout.toBSON();
}
bool hasFunctionIdentifier(StringData code) {