summaryrefslogtreecommitdiff
path: root/jstests/core/type5.js
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2015-09-14 16:19:11 -0400
committerJason Carey <jcarey@argv.me>2015-09-17 20:13:11 -0400
commit041e4fe737342bf40a6aedb7a04d8d99ba20e213 (patch)
tree148c21a538fd93bddf8a1982d463400d73984060 /jstests/core/type5.js
parent8291bbb3a6ec192d177076b1fb0cd28995e48440 (diff)
downloadmongo-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 'jstests/core/type5.js')
-rw-r--r--jstests/core/type5.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/jstests/core/type5.js b/jstests/core/type5.js
new file mode 100644
index 00000000000..414af2be7eb
--- /dev/null
+++ b/jstests/core/type5.js
@@ -0,0 +1,22 @@
+(function(){
+ "use strict";
+
+ // This checks SERVER-20375 - Constrain JS method thisv
+ //
+ // Check to make sure we can't invoke methods on incorrect types, or on
+ // prototypes of objects that aren't intended to have methods invoked on
+ // them.
+
+ assert.throws(function(){
+ HexData(0, "aaaa").hex.apply({});
+ }, [], "invoke method on object of incorrect type");
+ assert.throws(function(){
+ var x = HexData(0, "aaaa");
+ x.hex.apply(10);
+ }, [], "invoke method on incorrect type");
+ assert.throws(function(){
+ var x = HexData(0, "aaaa");
+ x.hex.apply(x.__proto__);
+ }, [], "invoke method on prototype of correct type");
+
+})();