0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/noPassthrough/nested_tojson.js
2016-11-29 20:15:31 -05:00

32 lines
762 B
JavaScript

(function() {
"use strict";
const tooMuchRecursion = (1 << 16);
const nestobj = (depth) => {
let doc = {};
let cur = doc;
for (let i = 0; i < depth; i++) {
cur[i] = {};
cur = cur[i];
}
cur['a'] = 'foo';
return doc;
};
const nestarr = (depth) => {
let doc = [0];
let cur = doc;
for (let i = 0; i < depth; i++) {
cur[0] = [0];
cur = cur[0];
}
cur[0] = 'foo';
return doc;
};
assert.doesNotThrow(
tojson, [nestobj(tooMuchRecursion)], 'failed to print deeply nested object');
assert.doesNotThrow(tojson, [nestarr(tooMuchRecursion)], 'failed to print deeply nested array');
})();