summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_where.cpp
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@10gen.com>2017-09-11 16:05:43 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2017-11-14 13:52:23 -0500
commitacde99b058c6e23302bc849015ed5e90b15b19fc (patch)
treecc1775bd2272048d55c936b3f4c259931f8409d6 /src/mongo/db/matcher/expression_where.cpp
parent4abdc7aff5cd5d0531c53b0ff784826e96700418 (diff)
downloadmongo-acde99b058c6e23302bc849015ed5e90b15b19fc.tar.gz
SERVER-30783 Move init() logic to MatchExpression constructors
Diffstat (limited to 'src/mongo/db/matcher/expression_where.cpp')
-rw-r--r--src/mongo/db/matcher/expression_where.cpp37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/mongo/db/matcher/expression_where.cpp b/src/mongo/db/matcher/expression_where.cpp
index 35f53f1ac14..dea7756f923 100644
--- a/src/mongo/db/matcher/expression_where.cpp
+++ b/src/mongo/db/matcher/expression_where.cpp
@@ -50,38 +50,24 @@ using std::string;
using std::stringstream;
using stdx::make_unique;
-WhereMatchExpression::WhereMatchExpression(OperationContext* opCtx, WhereParams params)
- : WhereMatchExpressionBase(std::move(params)), _opCtx(opCtx) {
+WhereMatchExpression::WhereMatchExpression(OperationContext* opCtx,
+ WhereParams params,
+ StringData dbName)
+ : WhereMatchExpressionBase(std::move(params)), _dbName(dbName.toString()), _opCtx(opCtx) {
invariant(_opCtx != NULL);
- _func = 0;
-}
-
-Status WhereMatchExpression::init(StringData dbName) {
- if (!getGlobalScriptEngine()) {
- return Status(ErrorCodes::BadValue, "no globalScriptEngine in $where parsing");
- }
+ uassert(
+ ErrorCodes::BadValue, "no globalScriptEngine in $where parsing", getGlobalScriptEngine());
- if (dbName.size() == 0) {
- return Status(ErrorCodes::BadValue, "ns for $where cannot be empty");
- }
-
- _dbName = dbName.toString();
+ uassert(ErrorCodes::BadValue, "ns for $where cannot be empty", dbName.size() != 0);
const string userToken =
AuthorizationSession::get(Client::getCurrent())->getAuthenticatedUserNamesToken();
- try {
- _scope = getGlobalScriptEngine()->getPooledScope(_opCtx, _dbName, "where" + userToken);
- _func = _scope->createFunction(getCode().c_str());
- } catch (...) {
- return exceptionToStatus();
- }
-
- if (!_func)
- return Status(ErrorCodes::BadValue, "$where compile error");
+ _scope = getGlobalScriptEngine()->getPooledScope(_opCtx, _dbName, "where" + userToken);
+ _func = _scope->createFunction(getCode().c_str());
- return Status::OK();
+ uassert(ErrorCodes::BadValue, "$where compile error", _func);
}
bool WhereMatchExpression::matches(const MatchableDocument* doc, MatchDetails* details) const {
@@ -113,8 +99,7 @@ unique_ptr<MatchExpression> WhereMatchExpression::shallowClone() const {
params.code = getCode();
params.scope = getScope();
unique_ptr<WhereMatchExpression> e =
- make_unique<WhereMatchExpression>(_opCtx, std::move(params));
- uassertStatusOK(e->init(_dbName));
+ make_unique<WhereMatchExpression>(_opCtx, std::move(params), _dbName);
if (getTag()) {
e->setTag(getTag()->clone());
}