diff options
author | Jason Carey <jcarey@argv.me> | 2015-09-16 18:18:46 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2015-09-21 18:25:39 -0400 |
commit | ee4f910322988cb9ba4784472a38a16ce2c0cdc9 (patch) | |
tree | d06b26e9ef598b71937f1c6aab5f10488663556d /src/mongo/scripting/mozjs/nativefunction.cpp | |
parent | a74ecb2a746e4d8a8ab78610c07d509788c4d8ad (diff) | |
download | mongo-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/nativefunction.cpp')
-rw-r--r-- | src/mongo/scripting/mozjs/nativefunction.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/mongo/scripting/mozjs/nativefunction.cpp b/src/mongo/scripting/mozjs/nativefunction.cpp index ef5423f0f21..4d019a5b347 100644 --- a/src/mongo/scripting/mozjs/nativefunction.cpp +++ b/src/mongo/scripting/mozjs/nativefunction.cpp @@ -78,6 +78,8 @@ void NativeFunctionInfo::call(JSContext* cx, JS::CallArgs args) { } BSONObjBuilder bob; + JS::RootedObject robj(cx, JS_NewPlainObject(cx)); + ObjectWrapper wobj(cx, robj); for (unsigned i = 0; i < args.length(); i++) { // 11 is enough here. unsigned's are only 32 bits, and 1 << 32 is only @@ -85,10 +87,10 @@ void NativeFunctionInfo::call(JSContext* cx, JS::CallArgs args) { char buf[11]; std::sprintf(buf, "%i", i); - ValueWriter(cx, args.get(i)).writeThis(&bob, buf); + wobj.setValue(buf, args.get(i)); } - BSONObj out = holder->_func(bob.obj(), holder->_ctx); + BSONObj out = holder->_func(wobj.toBSON(), holder->_ctx); ValueReader(cx, args.rval()).fromBSONElement(out.firstElement(), false); } |