diff options
author | Eric Cox <eric.cox@mongodb.com> | 2020-02-24 21:11:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-28 05:03:38 +0000 |
commit | 0a3733da8319ff6064ec813cd3195f0511cedbee (patch) | |
tree | b9b980dbde02b5494029b29166762f44dc32e3f4 /src | |
parent | ae7506fb3ec763097208a1fec9228e09e430505a (diff) | |
download | mongo-0a3733da8319ff6064ec813cd3195f0511cedbee.tar.gz |
SERVER-46377 Don't get a returnValue from js scope for callFunctionWithoutReturn
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/pipeline/javascript_execution.cpp | 27 | ||||
-rw-r--r-- | src/mongo/db/pipeline/javascript_execution.h | 9 |
2 files changed, 22 insertions, 14 deletions
diff --git a/src/mongo/db/pipeline/javascript_execution.cpp b/src/mongo/db/pipeline/javascript_execution.cpp index a9eeb0957fc..6ae5ccd9ea5 100644 --- a/src/mongo/db/pipeline/javascript_execution.cpp +++ b/src/mongo/db/pipeline/javascript_execution.cpp @@ -28,10 +28,13 @@ */ #include "mongo/platform/basic.h" + +#include "mongo/db/pipeline/javascript_execution.h" + #include <iostream> #include "mongo/base/status_with.h" -#include "mongo/db/pipeline/javascript_execution.h" +#include "mongo/util/str.h" namespace mongo { @@ -60,15 +63,13 @@ JsExecution* JsExecution::get(OperationContext* opCtx, return exec.get(); } -Value JsExecution::doCallFunction(ScriptingFunction func, - const BSONObj& params, - const BSONObj& thisObj, - bool noReturnVal) { +Value JsExecution::callFunction(ScriptingFunction func, + const BSONObj& params, + const BSONObj& thisObj) { _scope->registerOperation(Client::getCurrent()->getOperationContext()); const auto guard = makeGuard([&] { _scope->unregisterOperation(); }); - int err = _scope->invoke(func, ¶ms, &thisObj, _fnCallTimeoutMillis, noReturnVal); - + int err = _scope->invoke(func, ¶ms, &thisObj, _fnCallTimeoutMillis, false); uassert( 31439, str::stream() << "js function failed to execute: " << _scope->getError(), err == 0); @@ -77,4 +78,16 @@ Value JsExecution::doCallFunction(ScriptingFunction func, return Value(returnValue.done().firstElement()); } +void JsExecution::callFunctionWithoutReturn(ScriptingFunction func, + const BSONObj& params, + const BSONObj& thisObj) { + _scope->registerOperation(Client::getCurrent()->getOperationContext()); + const auto guard = makeGuard([&] { _scope->unregisterOperation(); }); + + int err = _scope->invoke(func, ¶ms, &thisObj, _fnCallTimeoutMillis, true); + uassert( + 31470, str::stream() << "js function failed to execute: " << _scope->getError(), err == 0); + + return; +} } // namespace mongo diff --git a/src/mongo/db/pipeline/javascript_execution.h b/src/mongo/db/pipeline/javascript_execution.h index 1af22c9c1d8..163d1fcc974 100644 --- a/src/mongo/db/pipeline/javascript_execution.h +++ b/src/mongo/db/pipeline/javascript_execution.h @@ -35,7 +35,6 @@ #include "mongo/db/operation_context.h" #include "mongo/db/query/query_knobs_gen.h" #include "mongo/scripting/engine.h" -#include "mongo/util/str.h" namespace mongo { @@ -77,9 +76,7 @@ public: */ void callFunctionWithoutReturn(ScriptingFunction func, const BSONObj& params, - const BSONObj& thisObj) { - doCallFunction(func, params, thisObj, true); - } + const BSONObj& thisObj); /** * Registers and invokes the javascript function given by 'func' with the arguments 'params' and @@ -87,9 +84,7 @@ public: * * Returns the value returned by the function. */ - Value callFunction(ScriptingFunction func, const BSONObj& params, const BSONObj& thisObj) { - return doCallFunction(func, params, thisObj, false); - } + Value callFunction(ScriptingFunction func, const BSONObj& params, const BSONObj& thisObj); /** * Injects the given function 'emitFn' as a native JS function named 'emit', callable from |