summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/bson.cpp
diff options
context:
space:
mode:
authorcchilds1 <cchilds1@binghamton.edu>2019-08-09 10:57:03 -0400
committercchilds1 <cchilds1@binghamton.edu>2019-08-09 10:57:03 -0400
commitadb75a05a64e7d3a4afd8ae0ded6c183dbf0449f (patch)
treef54be79e2d92f43bbaec19e06fb78793b308b4a0 /src/mongo/scripting/mozjs/bson.cpp
parentf14d9c4c07e69c2109de0af059123060c73cdd77 (diff)
downloadmongo-adb75a05a64e7d3a4afd8ae0ded6c183dbf0449f.tar.gz
SERVER-42664 add bsonObjToArray to shell
Diffstat (limited to 'src/mongo/scripting/mozjs/bson.cpp')
-rw-r--r--src/mongo/scripting/mozjs/bson.cpp10
1 files changed, 9 insertions, 1 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)