Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make sure db doesn't crash with weird db.eval returns SERVER-159

  • Loading branch information...
commit 294f9e48733c03d3ee7f5960dc363b341a0983e3 1 parent 2d8e4fd
@erh erh authored
View
11 jstests/eval9.js
@@ -6,3 +6,14 @@ for ( var i=0; i<a.length; i++ ){
assert.eq( typeof( a[i] ) , typeof( ret ) , "type test" );
assert.eq( a[i] , ret , "val test: " + typeof( a[i] ) );
}
+
+db.eval9.drop();
+db.eval9.save( { a : 17 } );
+
+assert.eq( 1 , db.eval( "return db.eval9.find().toArray()" ).length , "A" );
+assert.eq( 17 , db.eval( "return db.eval9.find().toArray()" )[0].a , "B" );
+
+// just to make sure these things don't crash
+assert( db.eval( "return db.eval9.find()" ) );
+assert( db.eval( "return db.eval9" ) );
+assert( db.eval( "return db" ) );
View
37 scripting/engine_spidermonkey.cpp
@@ -149,27 +149,30 @@ namespace mongo {
BSONObjBuilder b;
- jsval theid = getProperty( o , "_id" );
- if ( ! JSVAL_IS_VOID( theid ) ){
- append( b , "_id" , theid );
- }
-
- JSIdArray * properties = JS_Enumerate( _context , o );
- assert( properties );
+ if ( ! appendSpecialDBObject( this , b , "value" , o ) ){
- for ( jsint i=0; i<properties->length; i++ ){
- jsid id = properties->vector[i];
- jsval nameval;
- assert( JS_IdToValue( _context ,id , &nameval ) );
- string name = toString( nameval );
- if ( name == "_id" )
- continue;
+ jsval theid = getProperty( o , "_id" );
+ if ( ! JSVAL_IS_VOID( theid ) ){
+ append( b , "_id" , theid );
+ }
+
+ JSIdArray * properties = JS_Enumerate( _context , o );
+ assert( properties );
+
+ for ( jsint i=0; i<properties->length; i++ ){
+ jsid id = properties->vector[i];
+ jsval nameval;
+ assert( JS_IdToValue( _context ,id , &nameval ) );
+ string name = toString( nameval );
+ if ( name == "_id" )
+ continue;
+
+ append( b , name , getProperty( o , name.c_str() ) , orig[name].type() );
+ }
- append( b , name , getProperty( o , name.c_str() ) , orig[name].type() );
+ JS_DestroyIdArray( _context , properties );
}
- JS_DestroyIdArray( _context , properties );
-
return b.obj();
}
View
12 scripting/sm_db.cpp
@@ -688,7 +688,7 @@ namespace mongo {
);
return true;
}
-
+
#if defined( SM16 ) || defined( MOZJS )
{
jsdouble d = js_DateGetMsecSinceEpoch( c->_context , o );
@@ -705,6 +705,14 @@ namespace mongo {
}
#endif
+
+ if ( JS_InstanceOf( c->_context , o , &dbquery_class , 0 ) ||
+ JS_InstanceOf( c->_context , o , &mongo_class , 0 ) ||
+ JS_InstanceOf( c->_context , o , &db_collection_class , 0 ) ){
+ b.append( name.c_str() , c->toString( OBJECT_TO_JSVAL(o) ) );
+ return true;
+ }
+
return false;
}
@@ -716,5 +724,5 @@ namespace mongo {
return JS_InstanceOf( cx , o, &js_DateClass, 0 );
#endif
}
-
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.