diff options
author | Jason Carey <jcarey@argv.me> | 2015-09-14 16:19:11 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2015-09-17 20:13:11 -0400 |
commit | 041e4fe737342bf40a6aedb7a04d8d99ba20e213 (patch) | |
tree | 148c21a538fd93bddf8a1982d463400d73984060 /src/mongo/scripting/mozjs/nativefunction.cpp | |
parent | 8291bbb3a6ec192d177076b1fb0cd28995e48440 (diff) | |
download | mongo-041e4fe737342bf40a6aedb7a04d8d99ba20e213.tar.gz |
SERVER-20375 Constrain JS method thisv
This constrains universal access to wraptype methods by providing a
JS_ATTACH_JS_CONSTRAINED_METHOD() macro which allows for a list of types
that are allowed to call said method.
In this way we can lock down all methods without having to add uasserts
to each individual method body.
Diffstat (limited to 'src/mongo/scripting/mozjs/nativefunction.cpp')
-rw-r--r-- | src/mongo/scripting/mozjs/nativefunction.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mongo/scripting/mozjs/nativefunction.cpp b/src/mongo/scripting/mozjs/nativefunction.cpp index 5ffdc5f902d..ef5423f0f21 100644 --- a/src/mongo/scripting/mozjs/nativefunction.cpp +++ b/src/mongo/scripting/mozjs/nativefunction.cpp @@ -36,6 +36,7 @@ #include "mongo/scripting/mozjs/objectwrapper.h" #include "mongo/scripting/mozjs/valuereader.h" #include "mongo/scripting/mozjs/valuewriter.h" +#include "mongo/scripting/mozjs/wrapconstrainedmethod.h" #include "mongo/util/mongoutils/str.h" namespace mongo { @@ -45,7 +46,7 @@ const char* const NativeFunctionInfo::inheritFrom = "Function"; const char* const NativeFunctionInfo::className = "NativeFunction"; const JSFunctionSpec NativeFunctionInfo::methods[2] = { - MONGO_ATTACH_JS_FUNCTION(toString), JS_FS_END, + MONGO_ATTACH_JS_CONSTRAINED_METHOD(toString, NativeFunctionInfo), JS_FS_END, }; namespace { @@ -70,7 +71,7 @@ NativeHolder* getHolder(JS::CallArgs args) { void NativeFunctionInfo::call(JSContext* cx, JS::CallArgs args) { auto holder = getHolder(args); - if (! holder) { + if (!holder) { // Calling the prototype args.rval().setUndefined(); return; @@ -99,7 +100,7 @@ void NativeFunctionInfo::finalize(JSFreeOp* fop, JSObject* obj) { delete holder; } -void NativeFunctionInfo::Functions::toString(JSContext* cx, JS::CallArgs args) { +void NativeFunctionInfo::Functions::toString::call(JSContext* cx, JS::CallArgs args) { ObjectWrapper o(cx, args.thisv()); str::stream ss; @@ -115,7 +116,7 @@ void NativeFunctionInfo::make(JSContext* cx, void* data) { auto scope = getScope(cx); - scope->getNativeFunctionProto().newObject(obj); + scope->getProto<NativeFunctionInfo>().newObject(obj); JS_SetPrivate(obj, new NativeHolder(function, data)); } |