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
{
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;

View File

@ -71,10 +71,9 @@ namespace mongo {
Local<v8::Object> 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 );
}