diff options
-rw-r--r-- | jstests/storefunc.js | 5 | ||||
-rw-r--r-- | scripting/engine.cpp | 25 | ||||
-rw-r--r-- | scripting/engine.h | 1 |
3 files changed, 30 insertions, 1 deletions
diff --git a/jstests/storefunc.js b/jstests/storefunc.js index 9429f03398b..4cf7e309aec 100644 --- a/jstests/storefunc.js +++ b/jstests/storefunc.js @@ -35,3 +35,8 @@ assert.eq( 22 , db.eval( "return bar(5);" ) , "exec - 3 " ); assert( s.getIndexKeys().length > 0 , "no indexes" ); assert( s.getIndexKeys()[0]._id , "no _id index" ); +assert.eq( "undefined" , db.eval( function(){ return typeof(zzz); } ) , "C1" ); +s.save( { _id : "zzz" , value : 5 } ) +assert.eq( "number" , db.eval( function(){ return typeof(zzz); } ) , "C2" ); +s.remove( { _id : "zzz" } ); +assert.eq( "undefined" , db.eval( function(){ return typeof(zzz); } ) , "C3" ); diff --git a/scripting/engine.cpp b/scripting/engine.cpp index c2651b3a883..515f1386e0c 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -164,9 +164,12 @@ namespace mongo { _loadedVersion = _lastVersion; string coll = _localDBName + ".system.js"; - + static DBClientBase * db = createDirectClient(); auto_ptr<DBClientCursor> c = db->query( coll , Query() ); + + set<string> thisTime; + while ( c->more() ){ BSONObj o = c->next(); @@ -177,10 +180,30 @@ namespace mongo { uassert( 10210 , "value has to be set" , v.type() != EOO ); setElement( n.valuestr() , v ); + + thisTime.insert( n.valuestr() ); + _storedNames.insert( n.valuestr() ); + } db->ensureIndex( coll, BSON( "_id" << 1 ) , true ); + + // --- remove things from scope that were removed + + list<string> toremove; + + for ( set<string>::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){ + string n = *i; + if ( thisTime.count( n ) == 0 ) + toremove.push_back( n ); + } + for ( list<string>::iterator i=toremove.begin(); i!=toremove.end(); i++ ){ + string n = *i; + _storedNames.erase( n ); + execSetup( (string)"delete " + n , "clean up scope" ); + } + } ScriptingFunction Scope::createFunction( const char * code ){ diff --git a/scripting/engine.h b/scripting/engine.h index 137bc46f5e2..371c3ffb1da 100644 --- a/scripting/engine.h +++ b/scripting/engine.h @@ -111,6 +111,7 @@ namespace mongo { string _localDBName; long long _loadedVersion; + set<string> _storedNames; static long long _lastVersion; map<string,ScriptingFunction> _cachedFunctions; |