diff options
Diffstat (limited to 'src/mongo/scripting')
-rw-r--r-- | src/mongo/scripting/mozjs/bson.cpp | 10 | ||||
-rw-r--r-- | src/mongo/scripting/mozjs/bson.h | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/scripting/mozjs/bson.cpp b/src/mongo/scripting/mozjs/bson.cpp index 7972cdbaca0..0585022615a 100644 --- a/src/mongo/scripting/mozjs/bson.cpp +++ b/src/mongo/scripting/mozjs/bson.cpp @@ -46,9 +46,10 @@ namespace mozjs { const char* const BSONInfo::className = "BSON"; -const JSFunctionSpec BSONInfo::freeFunctions[3] = { +const JSFunctionSpec BSONInfo::freeFunctions[4] = { MONGO_ATTACH_JS_FUNCTION(bsonWoCompare), MONGO_ATTACH_JS_FUNCTION(bsonBinaryEqual), + MONGO_ATTACH_JS_FUNCTION(bsonObjToArray), JS_FS_END, }; @@ -267,6 +268,13 @@ std::tuple<BSONObj*, bool> BSONInfo::originalBSON(JSContext* cx, JS::HandleObjec return out; } +void BSONInfo::Functions::bsonObjToArray::call(JSContext* cx, JS::CallArgs args) { + uassert(ErrorCodes::BadValue, "bsonObjToArray needs 1 argument", args.length() == 1); + uassert(ErrorCodes::BadValue, "argument must be an object", args.get(0).isObject()); + + auto obj = ValueWriter(cx, args.get(0)).toBSON(); + ValueReader(cx, args.rval()).fromBSONArray(obj, nullptr, false); +} void BSONInfo::Functions::bsonWoCompare::call(JSContext* cx, JS::CallArgs args) { if (args.length() != 2) diff --git a/src/mongo/scripting/mozjs/bson.h b/src/mongo/scripting/mozjs/bson.h index 79768283a58..f515c4fd32a 100644 --- a/src/mongo/scripting/mozjs/bson.h +++ b/src/mongo/scripting/mozjs/bson.h @@ -73,9 +73,10 @@ struct BSONInfo : public BaseInfo { struct Functions { MONGO_DECLARE_JS_FUNCTION(bsonWoCompare); MONGO_DECLARE_JS_FUNCTION(bsonBinaryEqual); + MONGO_DECLARE_JS_FUNCTION(bsonObjToArray); }; - static const JSFunctionSpec freeFunctions[3]; + static const JSFunctionSpec freeFunctions[4]; static std::tuple<BSONObj*, bool> originalBSON(JSContext* cx, JS::HandleObject obj); static void make( |