From c9dd94ca1a571f9d145eaa9029d8ce905a86f933 Mon Sep 17 00:00:00 2001 From: Gabriel Russell Date: Tue, 12 Feb 2019 15:23:33 -0500 Subject: SERVER-39481 don't expose a MongoStatus constructor in JS --- src/mongo/scripting/mozjs/status.cpp | 15 ++++----------- src/mongo/scripting/mozjs/status.h | 2 +- 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(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::OK())); + JS_SetPrivate( + proto, + scope->trackedNew(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); -- cgit v1.2.1