diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2020-12-16 06:20:56 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-16 11:59:13 +0000 |
commit | b83bf99b6e48e2f41ea3b1e7ed6aeb4cf1eb0d31 (patch) | |
tree | 01332eac7b0c156b8bf220c366683e5f122b7de6 /src/mongo/scripting/mozjs | |
parent | c99a57f74a55dbb5509f19f5724f2a5697163f44 (diff) | |
download | mongo-b83bf99b6e48e2f41ea3b1e7ed6aeb4cf1eb0d31.tar.gz |
SERVER-52545 Define listIndexes with IDL
Diffstat (limited to 'src/mongo/scripting/mozjs')
-rw-r--r-- | src/mongo/scripting/mozjs/bson.cpp | 29 | ||||
-rw-r--r-- | src/mongo/scripting/mozjs/bson.h | 3 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/mongo/scripting/mozjs/bson.cpp b/src/mongo/scripting/mozjs/bson.cpp index 0585022615a..efe78d2feab 100644 --- a/src/mongo/scripting/mozjs/bson.cpp +++ b/src/mongo/scripting/mozjs/bson.cpp @@ -31,6 +31,7 @@ #include "mongo/scripting/mozjs/bson.h" #include <boost/optional.hpp> +#include <fmt/format.h> #include <set> #include "mongo/scripting/mozjs/idwrapper.h" @@ -44,10 +45,13 @@ namespace mongo { namespace mozjs { +using namespace fmt::literals; + const char* const BSONInfo::className = "BSON"; -const JSFunctionSpec BSONInfo::freeFunctions[4] = { +const JSFunctionSpec BSONInfo::freeFunctions[5] = { MONGO_ATTACH_JS_FUNCTION(bsonWoCompare), + MONGO_ATTACH_JS_FUNCTION(bsonUnorderedFieldsCompare), MONGO_ATTACH_JS_FUNCTION(bsonBinaryEqual), MONGO_ATTACH_JS_FUNCTION(bsonObjToArray), JS_FS_END, @@ -276,9 +280,13 @@ void BSONInfo::Functions::bsonObjToArray::call(JSContext* cx, JS::CallArgs args) ValueReader(cx, args.rval()).fromBSONArray(obj, nullptr, false); } -void BSONInfo::Functions::bsonWoCompare::call(JSContext* cx, JS::CallArgs args) { +namespace { +void bsonCompareCommon(JSContext* cx, + JS::CallArgs args, + StringData funcName, + BSONObj::ComparisonRulesSet rules) { if (args.length() != 2) - uasserted(ErrorCodes::BadValue, "bsonWoCompare needs 2 arguments"); + uasserted(ErrorCodes::BadValue, "{} needs 2 arguments"_format(funcName)); // If either argument is not proper BSON, then we wrap both objects. auto scope = getScope(cx); @@ -288,7 +296,20 @@ void BSONInfo::Functions::bsonWoCompare::call(JSContext* cx, JS::CallArgs args) BSONObj bsonObject1 = getBSONFromArg(cx, args.get(0), isBSON); BSONObj bsonObject2 = getBSONFromArg(cx, args.get(1), isBSON); - args.rval().setInt32(bsonObject1.woCompare(bsonObject2)); + args.rval().setInt32(bsonObject1.woCompare(bsonObject2, {}, rules)); +} +} // namespace + +void BSONInfo::Functions::bsonWoCompare::call(JSContext* cx, JS::CallArgs args) { + bsonCompareCommon(cx, args, "bsonWoCompare", BSONObj::ComparatorInterface::kConsiderFieldName); +} + +void BSONInfo::Functions::bsonUnorderedFieldsCompare::call(JSContext* cx, JS::CallArgs args) { + bsonCompareCommon(cx, + args, + "bsonWoCompare", + BSONObj::ComparatorInterface::kConsiderFieldName | + BSONObj::ComparatorInterface::kIgnoreFieldOrder); } void BSONInfo::Functions::bsonBinaryEqual::call(JSContext* cx, JS::CallArgs args) { diff --git a/src/mongo/scripting/mozjs/bson.h b/src/mongo/scripting/mozjs/bson.h index f515c4fd32a..a2cc5f1d2d3 100644 --- a/src/mongo/scripting/mozjs/bson.h +++ b/src/mongo/scripting/mozjs/bson.h @@ -72,11 +72,12 @@ struct BSONInfo : public BaseInfo { struct Functions { MONGO_DECLARE_JS_FUNCTION(bsonWoCompare); + MONGO_DECLARE_JS_FUNCTION(bsonUnorderedFieldsCompare); MONGO_DECLARE_JS_FUNCTION(bsonBinaryEqual); MONGO_DECLARE_JS_FUNCTION(bsonObjToArray); }; - static const JSFunctionSpec freeFunctions[4]; + static const JSFunctionSpec freeFunctions[5]; static std::tuple<BSONObj*, bool> originalBSON(JSContext* cx, JS::HandleObject obj); static void make( |