summaryrefslogtreecommitdiff
path: root/src/mongo/scripting
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2019-01-09 17:43:14 -0500
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2019-01-09 17:43:14 -0500
commit39f585b27ba3c872c869f36f3a3fc71e9966724e (patch)
treedce35499bdada5b790c24ac7489a0b11d6913d95 /src/mongo/scripting
parente3b9fc174a8ff64a850fd742295dd54839fc1744 (diff)
downloadmongo-39f585b27ba3c872c869f36f3a3fc71e9966724e.tar.gz
SERVER-38838 Ensure JavaScript stack string isn't empty.
Diffstat (limited to 'src/mongo/scripting')
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 85eba66d5f9..0f3859306fd 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -149,6 +149,9 @@ void MozJSImplScope::_reportError(JSContext* cx, const char* message, JSErrorRep
auto stackStr = ValueWriter(cx, stack).toString();
if (stackStr.empty()) {
+ // The JavaScript Error objects resulting from C++ exceptions may not always
+ // have a non-empty "stack" property. We instead use the line and column
+ // numbers of where in the JavaScript code the C++ function was called from.
str::stream ss;
ss << "@" << report->filename << ":" << report->lineno << ":" << report->column
<< "\n";
@@ -932,6 +935,15 @@ bool MozJSImplScope::_checkErrorState(bool success, bool reportError, bool asser
auto lineNum = ObjectWrapper(_context, excn).getNumberInt(InternedString::lineNumber);
auto colNum = ObjectWrapper(_context, excn).getNumberInt(InternedString::columnNumber);
+ if (stackStr.empty()) {
+ // The JavaScript Error objects resulting from C++ exceptions may not always have a
+ // non-empty "stack" property. We instead use the line and column numbers of where
+ // in the JavaScript code the C++ function was called from.
+ str::stream ss;
+ ss << "@" << fnameStr << ":" << lineNum << ":" << colNum << "\n";
+ stackStr = ss;
+ }
+
if (fnameStr != "") {
ss << "[" << fnameStr << ":" << lineNum << ":" << colNum << "] ";
}