summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/jstests.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2015-07-31 18:18:07 -0400
committerJason Carey <jcarey@argv.me>2015-08-10 14:42:34 -0400
commitdf71fbb001ce204c9f60b9ec66b1178b851cdbb4 (patch)
treea7bac74c1f97333c510948c7d8a6e71e0afa47ae /src/mongo/dbtests/jstests.cpp
parentbed94851c02602dcf4ba9dcec376cfda7f33e657 (diff)
downloadmongo-df71fbb001ce204c9f60b9ec66b1178b851cdbb4.tar.gz
SERVER-19705 unmix MozJS and Mongo Error Codes
SpiderMonkey error codes overlap with Mongo error codes in thrown user assertions. Avoid that by lifting our error codes above theirs.
Diffstat (limited to 'src/mongo/dbtests/jstests.cpp')
-rw-r--r--src/mongo/dbtests/jstests.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp
index 4723fcf9b96..4a4ebb408a4 100644
--- a/src/mongo/dbtests/jstests.cpp
+++ b/src/mongo/dbtests/jstests.cpp
@@ -2175,6 +2175,43 @@ public:
}
};
+class ErrorCodeFromInvoke {
+public:
+ void run() {
+ unique_ptr<Scope> s(globalScriptEngine->newScope());
+
+ {
+ bool threwException = false;
+ try {
+ s->invoke("\"use strict\"; x = 10;", 0, 0);
+ } catch (...) {
+ threwException = true;
+
+ auto status = exceptionToStatus();
+
+ ASSERT_EQUALS(status.code(), ErrorCodes::JSInterpreterFailure);
+ }
+
+ ASSERT(threwException);
+ }
+
+ {
+ bool threwException = false;
+ try {
+ s->invoke("UUID(1,2,3,4,5);", 0, 0);
+ } catch (...) {
+ threwException = true;
+
+ auto status = exceptionToStatus();
+
+ ASSERT_EQUALS(status.code(), ErrorCodes::BadValue);
+ }
+
+ ASSERT(threwException);
+ }
+ }
+};
+
class All : public Suite {
public:
All() : Suite("js") {
@@ -2226,6 +2263,7 @@ public:
add<NoReturnSpecified>();
add<RecursiveInvoke>();
+ add<ErrorCodeFromInvoke>();
add<RoundTripTests::DBRefTest>();
add<RoundTripTests::DBPointerTest>();