summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2019-02-12 15:23:33 -0500
committerGabriel Russell <gabriel.russell@mongodb.com>2019-03-12 13:29:57 -0400
commitc9dd94ca1a571f9d145eaa9029d8ce905a86f933 (patch)
treec8ecef2fc9b2537213b87bcbd504086d10210383
parent8d817350fbf32a61a9280c84a864222cc99faf27 (diff)
downloadmongo-c9dd94ca1a571f9d145eaa9029d8ce905a86f933.tar.gz
SERVER-39481 don't expose a MongoStatus constructor in JS
-rw-r--r--src/mongo/scripting/mozjs/status.cpp15
-rw-r--r--src/mongo/scripting/mozjs/status.h2
2 files changed, 5 insertions, 12 deletions
diff --git a/src/mongo/scripting/mozjs/status.cpp b/src/mongo/scripting/mozjs/status.cpp
index 2e3e142864f..a5d55f4503b 100644
--- a/src/mongo/scripting/mozjs/status.cpp
+++ b/src/mongo/scripting/mozjs/status.cpp
@@ -53,6 +53,7 @@ Status MongoStatusInfo::toStatus(JSContext* cx, JS::HandleValue value) {
}
void MongoStatusInfo::fromStatus(JSContext* cx, Status status, JS::MutableHandleValue value) {
+ invariant(status != Status::OK());
auto scope = getScope(cx);
JS::RootedValue undef(cx);
@@ -83,16 +84,6 @@ void MongoStatusInfo::fromStatus(JSContext* cx, Status status, JS::MutableHandle
value.setObjectOrNull(thisv);
}
-void MongoStatusInfo::construct(JSContext* cx, JS::CallArgs args) {
- auto code = args.get(0).toInt32();
- auto reason = JSStringWrapper(cx, args.get(1).toString()).toString();
-
- JS::RootedValue out(cx);
- fromStatus(cx, Status(ErrorCodes::Error(code), std::move(reason)), &out);
-
- args.rval().set(out);
-}
-
void MongoStatusInfo::finalize(JSFreeOp* fop, JSObject* obj) {
auto status = static_cast<Status*>(JS_GetPrivate(obj));
@@ -111,7 +102,9 @@ void MongoStatusInfo::Functions::reason::call(JSContext* cx, JS::CallArgs args)
void MongoStatusInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) {
auto scope = getScope(cx);
- JS_SetPrivate(proto, scope->trackedNew<Status>(Status::OK()));
+ JS_SetPrivate(
+ proto,
+ scope->trackedNew<Status>(Status(ErrorCodes::UnknownError, "Mongo Status Prototype")));
}
} // namespace mozjs
diff --git a/src/mongo/scripting/mozjs/status.h b/src/mongo/scripting/mozjs/status.h
index 9eb1987d91c..5ec265b7a1e 100644
--- a/src/mongo/scripting/mozjs/status.h
+++ b/src/mongo/scripting/mozjs/status.h
@@ -47,7 +47,6 @@ namespace mozjs {
* traces, and instanceOf Error.
*/
struct MongoStatusInfo : public BaseInfo {
- static void construct(JSContext* cx, JS::CallArgs args);
static void finalize(JSFreeOp* fop, JSObject* obj);
struct Functions {
@@ -60,6 +59,7 @@ struct MongoStatusInfo : public BaseInfo {
static const char* const className;
static const char* const inheritFrom;
static const unsigned classFlags = JSCLASS_HAS_PRIVATE;
+ static const InstallType installType = InstallType::Private;
static Status toStatus(JSContext* cx, JS::HandleObject object);
static Status toStatus(JSContext* cx, JS::HandleValue value);