From b7104c6f2f597335c6b9890ff6b80243625a6258 Mon Sep 17 00:00:00 2001 From: Jason Carey Date: Wed, 23 Sep 2015 11:11:40 -0400 Subject: SERVER-20564 no default getOwned for BSON in JS --- src/mongo/scripting/mozjs/cursor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/mongo/scripting/mozjs/cursor.cpp') diff --git a/src/mongo/scripting/mozjs/cursor.cpp b/src/mongo/scripting/mozjs/cursor.cpp index 79c1f5cf749..072e2ffb999 100644 --- a/src/mongo/scripting/mozjs/cursor.cpp +++ b/src/mongo/scripting/mozjs/cursor.cpp @@ -83,7 +83,9 @@ void CursorInfo::Functions::next::call(JSContext* cx, JS::CallArgs args) { BSONObj bson = cursor->next(); bool ro = o.hasField("_ro") ? o.getBoolean("_ro") : false; - ValueReader(cx, args.rval()).fromBSON(bson, ro); + // getOwned because cursor->next() gives us unowned bson from an internal + // buffer and we need to make a copy + ValueReader(cx, args.rval()).fromBSON(bson.getOwned(), nullptr, ro); } void CursorInfo::Functions::hasNext::call(JSContext* cx, JS::CallArgs args) { -- cgit v1.2.1