diff --git a/db/matcher.cpp b/db/matcher.cpp index 8bc76e5b404..55ddd302a7c 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -80,6 +80,7 @@ namespace mongo { public: Where() { jsScope = 0; + func = 0; } ~Where() { @@ -553,6 +554,7 @@ namespace mongo { where->scope->setBoolean( "fullObject" , true ); // this is a hack b/c fullObject used to be relevant int err = where->scope->invoke( where->func , BSONObj() , 1000 * 60 ); + where->scope->setThis( 0 ); if ( err == -3 ) { // INVOKE_ERROR stringstream ss; ss << "error on invocation of $where function:\n" diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 666b690a570..d78a4c90aa3 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -772,6 +772,7 @@ namespace mongo { Convertor c( cx ); BSONHolder * holder = GETHOLDER( cx , obj ); + assert( holder ); holder->check(); string s = c.toString( id ); @@ -1090,11 +1091,15 @@ namespace mongo { void setThis( const BSONObj * obj ){ smlock; - if ( _this ) + if ( _this ){ JS_RemoveRoot( _context , &_this ); + _this = 0; + } - _this = _convertor->toJSObject( obj ); - JS_AddNamedRoot( _context , &_this , "scope this" ); + if ( obj ){ + _this = _convertor->toJSObject( obj ); + JS_AddNamedRoot( _context , &_this , "scope this" ); + } } // ---- functions -----