From 8291bbb3a6ec192d177076b1fb0cd28995e48440 Mon Sep 17 00:00:00 2001 From: Jason Carey Date: Mon, 14 Sep 2015 14:18:35 -0400 Subject: SERVER-20080 Constrain ctor calls for JS types Several types shouldn't be called as a ctor: * NativeFunction * Cursor * CursorHandle * NativeFunction This prevents them from being called as such. --- src/mongo/scripting/mozjs/nativefunction.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/mongo/scripting/mozjs/nativefunction.cpp') diff --git a/src/mongo/scripting/mozjs/nativefunction.cpp b/src/mongo/scripting/mozjs/nativefunction.cpp index 010b6a13587..5ffdc5f902d 100644 --- a/src/mongo/scripting/mozjs/nativefunction.cpp +++ b/src/mongo/scripting/mozjs/nativefunction.cpp @@ -67,15 +67,15 @@ NativeHolder* getHolder(JS::CallArgs args) { } // namespace -void NativeFunctionInfo::construct(JSContext* cx, JS::CallArgs args) { - auto scope = getScope(cx); - - scope->getNativeFunctionProto().newObject(args.rval()); -} - void NativeFunctionInfo::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); + if (! holder) { + // Calling the prototype + args.rval().setUndefined(); + return; + } + BSONObjBuilder bob; for (unsigned i = 0; i < args.length(); i++) { @@ -115,7 +115,7 @@ void NativeFunctionInfo::make(JSContext* cx, void* data) { auto scope = getScope(cx); - scope->getNativeFunctionProto().newInstance(obj); + scope->getNativeFunctionProto().newObject(obj); JS_SetPrivate(obj, new NativeHolder(function, data)); } -- cgit v1.2.1