summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/mongohelpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/scripting/mozjs/mongohelpers.js')
-rw-r--r--src/mongo/scripting/mozjs/mongohelpers.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/mongo/scripting/mozjs/mongohelpers.js b/src/mongo/scripting/mozjs/mongohelpers.js
index b0b35bb2fe8..d3f743623a3 100644
--- a/src/mongo/scripting/mozjs/mongohelpers.js
+++ b/src/mongo/scripting/mozjs/mongohelpers.js
@@ -33,6 +33,14 @@
exportToMongoHelpers = {
// This function accepts an expression or function body and returns a function definition
'functionExpressionParser': function functionExpressionParser(fnSrc) {
+
+ // Ensure that a provided expression or function body is not terminated with a ';'.
+ // This ensures we interpret the input as a single expression, rather than a sequence
+ // of expressions, and can wrap it in parentheses.
+ while (fnSrc.endsWith(";") || fnSrc != fnSrc.trimRight()) {
+ fnSrc = fnSrc.slice(0, -1).trimRight();
+ }
+
var parseTree;
try {
parseTree = this.Reflect.parse(fnSrc);