summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/bson.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2017-08-29 14:26:07 -0400
committerJason Carey <jcarey@argv.me>2017-08-30 15:05:04 -0400
commit8ef456f89f63ab12941fe6b5352b20cff2522da3 (patch)
tree6c1e5d5bb2f71175297b69013dd00b199b9f053d /src/mongo/scripting/mozjs/bson.cpp
parentb39e21c774d0ff3afeac1730f08d8defed38044d (diff)
downloadmongo-fe37cb554c7de40dfb10567d932073e7d41e2815.tar.gz
SERVER-30875 add requireOwnedObjects() to scoper3.4.8-rc1r3.4.8
Add a flag to JS scopes that requires that bson objects bound to the scope be owned. This should allow for more easy auditing of scopes that don't explicitly manage lifetime with advanceGeneration. (cherry picked from commit 79b47945a6aae707d44e05669d991d86b157a14b)
Diffstat (limited to 'src/mongo/scripting/mozjs/bson.cpp')
-rw-r--r--src/mongo/scripting/mozjs/bson.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/mongo/scripting/mozjs/bson.cpp b/src/mongo/scripting/mozjs/bson.cpp
index 5a2ebd0dfed..a2881c44664 100644
--- a/src/mongo/scripting/mozjs/bson.cpp
+++ b/src/mongo/scripting/mozjs/bson.cpp
@@ -59,13 +59,17 @@ namespace {
* the appearance of mutable state on the read/write versions.
*/
struct BSONHolder {
- BSONHolder(const BSONObj& obj, const BSONObj* parent, std::size_t generation, bool ro)
+ BSONHolder(const BSONObj& obj, const BSONObj* parent, const MozJSImplScope* scope, bool ro)
: _obj(obj),
- _generation(generation),
+ _generation(scope->getGeneration()),
_isOwned(obj.isOwned() || (parent && parent->isOwned())),
_resolved(false),
_readOnly(ro),
_altered(false) {
+ uassert(
+ ErrorCodes::BadValue,
+ "Attempt to bind an unowned BSON Object to a JS scope marked as requiring ownership",
+ _isOwned || (!scope->requiresOwnedObjects()));
if (parent) {
_parent.emplace(*parent);
}
@@ -107,7 +111,7 @@ void BSONInfo::make(
auto scope = getScope(cx);
scope->getProto<BSONInfo>().newObject(obj);
- JS_SetPrivate(obj, scope->trackedNew<BSONHolder>(bson, parent, scope->getGeneration(), ro));
+ JS_SetPrivate(obj, scope->trackedNew<BSONHolder>(bson, parent, scope, ro));
}
void BSONInfo::finalize(JSFreeOp* fop, JSObject* obj) {