summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/nativefunction.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2015-09-14 14:18:35 -0400
committerJason Carey <jcarey@argv.me>2015-09-17 19:59:38 -0400
commit8291bbb3a6ec192d177076b1fb0cd28995e48440 (patch)
tree5cfb11b9cc1752c9967473c71b957188499b4fce /src/mongo/scripting/mozjs/nativefunction.cpp
parent1b0e65b0ccd5725f97b0a679ac7f7476a242c66e (diff)
downloadmongo-8291bbb3a6ec192d177076b1fb0cd28995e48440.tar.gz
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.
Diffstat (limited to 'src/mongo/scripting/mozjs/nativefunction.cpp')
-rw-r--r--src/mongo/scripting/mozjs/nativefunction.cpp14
1 files changed, 7 insertions, 7 deletions
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));
}