Permalink
Browse files

temp fix for sub object mods

  • Loading branch information...
1 parent 529784d commit a4a3d19ce1249f7dd669aac4439157a6ac40b429 @erh erh committed Jul 23, 2009
Showing with 28 additions and 2 deletions.
  1. +19 −1 jstests/basica.js
  2. +9 −1 scripting/engine_spidermonkey.cpp
View
@@ -1,15 +1,33 @@
t = db.basica;
+
+
t.drop();
t.save( { a : 1 , b : [ { x : 2 , y : 2 } , { x : 3 , y : 3 } ] } );
x = t.findOne();
x.b["0"].x = 4;
x.b["0"].z = 4;
+x.b[0].m = 9;
+x.b[0]["asd"] = 11;
x.a = 2;
x.z = 11;
tojson( x );
t.save( x );
-assert.eq( tojson( x ) , tojson( t.findOne() ) );
+assert.eq( tojson( x ) , tojson( t.findOne() ) , "FIRST" );
+
+// -----
+
+t.drop();
+
+t.save( { a : 1 , b : [ { x : 2 , y : 2 } , { x : 3 , y : 3 } ] } );
+
+x = t.findOne();
+x.b["0"].z = 4;
+
+//printjson( x );
+t.save( x );
+assert.eq( tojson( x ) , tojson( t.findOne() ) , "SECOND" );
+
@@ -148,8 +148,9 @@ namespace mongo {
BSONObj orig;
if ( JS_InstanceOf( _context , o , &bson_class , 0 ) ){
BSONHolder * holder = GETHOLDER(_context,o);
- if ( ! holder->_modified )
+ if ( ! holder->_modified ){
return holder->_obj;
+ }
orig = holder->_obj;
}
@@ -708,6 +709,13 @@ namespace mongo {
holder->_inResolve = true;
assert( JS_SetProperty( cx , obj , s.c_str() , &val ) );
holder->_inResolve = false;
+
+ if ( JSVAL_IS_OBJECT( val ) &&
+ ( JS_InstanceOf( cx , JSVAL_TO_OBJECT( val ) , &bson_class , 0 ) ||
+ JS_IsArrayObject( cx , JSVAL_TO_OBJECT( val ) ) ) ){
+ // TODO: this is a hack to get around sub objects being modified
+ holder->_modified = true;
+ }
*objp = obj;
JS_LeaveLocalRootScope( cx );

0 comments on commit a4a3d19

Please sign in to comment.