summaryrefslogtreecommitdiff
path: root/jstests/core/recursion.js
blob: 926250be20dc9c45fd24930dc3819f0fd92d8f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Basic tests for a form of stack recursion that's been shown to cause C++
// side stack overflows in the past. See SERVER-19614.

(function() {
    "use strict";

    db.recursion.drop();

    // Make sure the shell doesn't blow up
    function shellRecursion() {
        shellRecursion.apply();
    }
    assert.throws(shellRecursion);

    // Make sure db.eval doesn't blow up
    function dbEvalRecursion() {
        db.eval(function() {
            function recursion() {
                recursion.apply();
            }
            recursion();
        });
    }
    assert.commandFailedWithCode(assert.throws(dbEvalRecursion), ErrorCodes.JSInterpreterFailure);

    // Make sure mapReduce doesn't blow up
    function mapReduceRecursion() {
        db.recursion.mapReduce(
            function() {
                (function recursion() {
                    recursion.apply();
                })();
            },
            function() {},
            {out: 'inline'});
    }

    db.recursion.insert({});
    assert.commandFailedWithCode(assert.throws(mapReduceRecursion),
                                 ErrorCodes.JSInterpreterFailure);
}());