0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-446 v8 round trip array support

This commit is contained in:
Aaron 2009-12-16 09:31:56 -08:00
parent df1867b3a7
commit b9ddc3e9ef
2 changed files with 18 additions and 5 deletions

View File

@ -349,9 +349,13 @@ namespace JSTests {
// array // array
{ {
BSONObj o = fromjson( "{r:[1,2,3]}" ); BSONObj o = fromjson( "{r:[1,2,3]}" );
s->setObject( "x", o ); s->setObject( "x", o, false );
BSONObj out = s->getObject( "x" ); BSONObj out = s->getObject( "x" );
ASSERT_EQUALS( Array, out.firstElement().type() ); ASSERT_EQUALS( Array, out.firstElement().type() );
s->setObject( "x", o, true );
out = s->getObject( "x" );
ASSERT_EQUALS( Array, out.firstElement().type() );
} }
delete s; delete s;

View File

@ -71,10 +71,9 @@ namespace mongo {
Local<v8::Object> o; Local<v8::Object> o;
if ( !readOnly ) { if ( !readOnly ) {
// probably unnecessary if ( array )
// if ( array ) o = internalFieldObjects->NewInstance();
// o = v8::Array::New(); else
// else
o = v8::Object::New(); o = v8::Object::New();
} else { } else {
// NOTE Our readOnly implemention relies on undocumented ObjectTemplate // 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 // However, it turns out that ForceSet() only bypasses handlers for named
// properties and not for indexed properties. // properties and not for indexed properties.
readOnlyObjects = v8::ObjectTemplate::New(); 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->SetInternalFieldCount( 1 );
readOnlyObjects->SetNamedPropertyHandler( 0 ); readOnlyObjects->SetNamedPropertyHandler( 0 );
readOnlyObjects->SetIndexedPropertyHandler( 0 ); readOnlyObjects->SetIndexedPropertyHandler( 0 );
o = readOnlyObjects->NewInstance(); o = readOnlyObjects->NewInstance();
} }
if ( array )
o->SetInternalField( 0, v8::Uint32::New( mongo::Array ) );
mongo::BSONObj sub; mongo::BSONObj sub;
@ -358,6 +364,9 @@ namespace mongo {
case MaxKey: case MaxKey:
b.appendMaxKey( sname.c_str() ); b.appendMaxKey( sname.c_str() );
return; return;
case Array:
b.appendArray( sname.c_str() , v8ToMongo( value->ToObject() ) );
return;
default: default:
assert( "invalid internal field" == 0 ); assert( "invalid internal field" == 0 );
} }