diff --git a/dbtests/jstests.cpp b/dbtests/jstests.cpp index b4991cd7587..0ba1ff6ffa8 100644 --- a/dbtests/jstests.cpp +++ b/dbtests/jstests.cpp @@ -349,9 +349,13 @@ namespace JSTests { // array { BSONObj o = fromjson( "{r:[1,2,3]}" ); - s->setObject( "x", o ); + s->setObject( "x", o, false ); BSONObj out = s->getObject( "x" ); ASSERT_EQUALS( Array, out.firstElement().type() ); + + s->setObject( "x", o, true ); + out = s->getObject( "x" ); + ASSERT_EQUALS( Array, out.firstElement().type() ); } delete s; diff --git a/scripting/v8_wrapper.cpp b/scripting/v8_wrapper.cpp index ed27947672b..e7508d766c9 100644 --- a/scripting/v8_wrapper.cpp +++ b/scripting/v8_wrapper.cpp @@ -71,10 +71,9 @@ namespace mongo { Local o; if ( !readOnly ) { - // probably unnecessary -// if ( array ) -// o = v8::Array::New(); -// else + if ( array ) + o = internalFieldObjects->NewInstance(); + else o = v8::Object::New(); } else { // NOTE Our readOnly implemention relies on undocumented ObjectTemplate @@ -90,11 +89,18 @@ namespace mongo { // However, it turns out that ForceSet() only bypasses handlers for named // properties and not for indexed properties. readOnlyObjects = v8::ObjectTemplate::New(); + // NOTE This internal field will store type info for special db types. For + // regular objects the field is unnecessary - for simplicity I'm creating just + // one readOnlyObjects template for objects where the field is & isn't necessary, + // assuming that the overhead of an internal field is slight. readOnlyObjects->SetInternalFieldCount( 1 ); readOnlyObjects->SetNamedPropertyHandler( 0 ); readOnlyObjects->SetIndexedPropertyHandler( 0 ); o = readOnlyObjects->NewInstance(); } + + if ( array ) + o->SetInternalField( 0, v8::Uint32::New( mongo::Array ) ); mongo::BSONObj sub; @@ -358,6 +364,9 @@ namespace mongo { case MaxKey: b.appendMaxKey( sname.c_str() ); return; + case Array: + b.appendArray( sname.c_str() , v8ToMongo( value->ToObject() ) ); + return; default: assert( "invalid internal field" == 0 ); }