diff options
author | Jason Carey <jcarey@argv.me> | 2015-09-14 14:18:35 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2015-09-17 19:59:38 -0400 |
commit | 8291bbb3a6ec192d177076b1fb0cd28995e48440 (patch) | |
tree | 5cfb11b9cc1752c9967473c71b957188499b4fce /src/mongo/scripting/mozjs/nativefunction.cpp | |
parent | 1b0e65b0ccd5725f97b0a679ac7f7476a242c66e (diff) | |
download | mongo-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.cpp | 14 |
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)); } |