summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/wraptype.h
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/wraptype.h
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/wraptype.h')
-rw-r--r--src/mongo/scripting/mozjs/wraptype.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/mongo/scripting/mozjs/wraptype.h b/src/mongo/scripting/mozjs/wraptype.h
index d569bcb9d86..3729e964c0e 100644
--- a/src/mongo/scripting/mozjs/wraptype.h
+++ b/src/mongo/scripting/mozjs/wraptype.h
@@ -240,8 +240,12 @@ public:
// before the other types are installed. Might as well just do it
// in the constructor.
if (T::classFlags & JSCLASS_GLOBAL_FLAGS) {
+ _jsclass.trace = JS_GlobalObjectTraceHook;
+
JS::RootedObject proto(_context);
+ JSAutoRequest ar(_context);
+
_proto.init(_context,
_assertPtr(JS_NewGlobalObject(
_context, &_jsclass, nullptr, JS::DontFireOnNewGlobalHook)));