diff options
author | Jason Carey <jcarey@argv.me> | 2015-09-23 11:11:40 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2015-10-06 19:28:19 -0400 |
commit | b7104c6f2f597335c6b9890ff6b80243625a6258 (patch) | |
tree | 8107d9b98344574c7bd541619c1fcb5b727b0eb2 /src/mongo/scripting/mozjs/valuereader.cpp | |
parent | e5f65d77a33e5116adb965549deb51ab3ed0a462 (diff) | |
download | mongo-b7104c6f2f597335c6b9890ff6b80243625a6258.tar.gz |
SERVER-20564 no default getOwned for BSON in JS
Diffstat (limited to 'src/mongo/scripting/mozjs/valuereader.cpp')
-rw-r--r-- | src/mongo/scripting/mozjs/valuereader.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/mongo/scripting/mozjs/valuereader.cpp b/src/mongo/scripting/mozjs/valuereader.cpp index 6a0b9dc6fe1..71be53c6ff2 100644 --- a/src/mongo/scripting/mozjs/valuereader.cpp +++ b/src/mongo/scripting/mozjs/valuereader.cpp @@ -48,7 +48,7 @@ namespace mozjs { ValueReader::ValueReader(JSContext* cx, JS::MutableHandleValue value) : _context(cx), _value(value) {} -void ValueReader::fromBSONElement(const BSONElement& elem, bool readOnly) { +void ValueReader::fromBSONElement(const BSONElement& elem, const BSONObj& parent, bool readOnly) { auto scope = getScope(_context); switch (elem.type()) { @@ -92,14 +92,14 @@ void ValueReader::fromBSONElement(const BSONElement& elem, bool readOnly) { sprintf(str, "%i", i++); JS::RootedValue member(_context); - ValueReader(_context, &member).fromBSONElement(subElem, readOnly); + ValueReader(_context, &member).fromBSONElement(subElem, parent, readOnly); ObjectWrapper(_context, array).setValue(str, member); } _value.setObjectOrNull(array); return; } case mongo::Object: - fromBSON(elem.embeddedObject(), readOnly); + fromBSON(elem.embeddedObject(), &parent, readOnly); return; case mongo::Date: _value.setObjectOrNull( @@ -213,7 +213,7 @@ void ValueReader::fromBSONElement(const BSONElement& elem, bool readOnly) { _value.setUndefined(); } -void ValueReader::fromBSON(const BSONObj& obj, bool readOnly) { +void ValueReader::fromBSON(const BSONObj& obj, const BSONObj* parent, bool readOnly) { if (obj.firstElementType() == String && str::equals(obj.firstElementFieldName(), "$ref")) { BSONObjIterator it(obj); const BSONElement ref = it.next(); @@ -222,30 +222,30 @@ void ValueReader::fromBSON(const BSONObj& obj, bool readOnly) { if (id.ok() && str::equals(id.fieldName(), "$id")) { JS::AutoValueArray<2> args(_context); - ValueReader(_context, args[0]).fromBSONElement(ref, readOnly); + ValueReader(_context, args[0]).fromBSONElement(ref, parent ? *parent : obj, readOnly); // id can be a subobject - ValueReader(_context, args[1]).fromBSONElement(id, readOnly); + ValueReader(_context, args[1]).fromBSONElement(id, parent ? *parent : obj, readOnly); - JS::RootedObject obj(_context); + JS::RootedObject robj(_context); auto scope = getScope(_context); - scope->getProto<DBRefInfo>().newInstance(args, &obj); - ObjectWrapper o(_context, obj); + scope->getProto<DBRefInfo>().newInstance(args, &robj); + ObjectWrapper o(_context, robj); while (it.more()) { BSONElement elem = it.next(); - o.setBSONElement(elem.fieldName(), elem, readOnly); + o.setBSONElement(elem.fieldName(), elem, parent ? *parent : obj, readOnly); } - _value.setObjectOrNull(obj); + _value.setObjectOrNull(robj); return; } } JS::RootedObject child(_context); - BSONInfo::make(_context, &child, obj, readOnly); + BSONInfo::make(_context, &child, obj, parent, readOnly); _value.setObjectOrNull(child); } |