diff options
Diffstat (limited to 'src/mongo/scripting/mozjs/valuereader.cpp')
-rw-r--r-- | src/mongo/scripting/mozjs/valuereader.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/mongo/scripting/mozjs/valuereader.cpp b/src/mongo/scripting/mozjs/valuereader.cpp index af26238763d..1eedef58e86 100644 --- a/src/mongo/scripting/mozjs/valuereader.cpp +++ b/src/mongo/scripting/mozjs/valuereader.cpp @@ -97,21 +97,7 @@ void ValueReader::fromBSONElement(const BSONElement& elem, const BSONObj& parent _value.setInt32(elem.Int()); return; case mongo::Array: { - JS::AutoValueVector avv(_context); - - BSONForEach(subElem, elem.embeddedObject()) { - JS::RootedValue member(_context); - - ValueReader(_context, &member).fromBSONElement(subElem, parent, readOnly); - if (!avv.append(member)) { - uasserted(ErrorCodes::JSInterpreterFailure, "Failed to append to JS array"); - } - } - JS::RootedObject array(_context, JS_NewArrayObject(_context, avv)); - if (!array) { - uasserted(ErrorCodes::JSInterpreterFailure, "Failed to JS_NewArrayObject"); - } - _value.setObjectOrNull(array); + fromBSONArray(elem.embeddedObject(), &parent, readOnly); return; } case mongo::Object: @@ -254,6 +240,24 @@ void ValueReader::fromBSON(const BSONObj& obj, const BSONObj* parent, bool readO _value.setObjectOrNull(child); } +void ValueReader::fromBSONArray(const BSONObj& obj, const BSONObj* parent, bool readOnly) { + JS::AutoValueVector avv(_context); + + BSONForEach(elem, obj) { + JS::RootedValue member(_context); + + ValueReader(_context, &member).fromBSONElement(elem, parent ? *parent : obj, readOnly); + if (!avv.append(member)) { + uasserted(ErrorCodes::JSInterpreterFailure, "Failed to append to JS array"); + } + } + JS::RootedObject array(_context, JS_NewArrayObject(_context, avv)); + if (!array) { + uasserted(ErrorCodes::JSInterpreterFailure, "Failed to JS_NewArrayObject"); + } + _value.setObjectOrNull(array); +} + /** * SpiderMonkey doesn't have a direct entry point to create a jsstring from * utf8, so we have to flow through some slightly less public interfaces. |