diff --git a/.gitignore b/.gitignore index 997323feede..e086e45e95d 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,11 @@ debian/mongodb.* #osx .DS_Store + +# QtCreator +*.config +*.creator +*.creator.user +*.files +*.includes + diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp index 519038b3b1a..8776b7ab983 100644 --- a/scripting/v8_db.cpp +++ b/scripting/v8_db.cpp @@ -63,6 +63,8 @@ namespace mongo { global->Set(v8::String::New("DBQuery") , dbQuery ); global->Set( v8::String::New("ObjectId") , FunctionTemplate::New( objectIdInit ) ); + + global->Set( v8::String::New("DBRef") , FunctionTemplate::New( dbRefInit ) ); } void installDBTypes( Handle& global ){ @@ -80,6 +82,8 @@ namespace mongo { global->Set(v8::String::New("DBQuery") , dbQuery->GetFunction() ); global->Set( v8::String::New("ObjectId") , FunctionTemplate::New( objectIdInit )->GetFunction() ); + + global->Set( v8::String::New("DBRef") , FunctionTemplate::New( dbRefInit )->GetFunction() ); } void destroyConnection( Persistent object, void* parameter){ @@ -421,5 +425,25 @@ namespace mongo { return it; } + v8::Handle dbRefInit( const v8::Arguments& args ) { + + if (args.Length() != 2) { + return v8::ThrowException( v8::String::New( "DBRef needs 2 arguments" ) ); + } + + v8::Handle it = args.This(); + + if ( it->IsUndefined() || it == v8::Context::GetCurrent()->Global() ){ + v8::Function* f = getNamedCons( "DBRef" ); + it = f->NewInstance(); + } + + it->Set( v8::String::New( "$ref" ) , args[0] ); + it->Set( v8::String::New( "$id" ) , args[1] ); + + return it; + } + + } diff --git a/scripting/v8_db.h b/scripting/v8_db.h index 2f072e907ee..68d68722df8 100644 --- a/scripting/v8_db.h +++ b/scripting/v8_db.h @@ -53,6 +53,8 @@ namespace mongo { v8::Handle dbInit(const v8::Arguments& args); v8::Handle collectionInit( const v8::Arguments& args ); v8::Handle objectIdInit( const v8::Arguments& args ); + + v8::Handle dbRefInit( const v8::Arguments& args ); v8::Handle dbQueryInit( const v8::Arguments& args ); v8::Handle dbQueryIndexAccess( uint32_t index , const v8::AccessorInfo& info ); diff --git a/scripting/v8_utils.cpp b/scripting/v8_utils.cpp index 3229508f0c4..cb68f621502 100644 --- a/scripting/v8_utils.cpp +++ b/scripting/v8_utils.cpp @@ -55,7 +55,7 @@ namespace mongo { stringstream ss; - //while ( try_catch ){ + //while ( try_catch ){ // disabled for v8 bleeding edge v8::String::Utf8Value exception(try_catch->Exception()); Handle message = try_catch->Message(); @@ -124,7 +124,7 @@ namespace mongo { cout << endl; } - //if ( try_catch->next_ ) + //if ( try_catch->next_ ) // disabled for v8 bleeding edge // s << try_catch->next_; return s; diff --git a/scripting/v8_wrapper.cpp b/scripting/v8_wrapper.cpp index 2f319a4ae69..cd111b13662 100644 --- a/scripting/v8_wrapper.cpp +++ b/scripting/v8_wrapper.cpp @@ -30,14 +30,28 @@ namespace mongo { #define DDD(x) Local mongoToV8( const BSONObj& m , bool array ){ + + // handle DBRef. needs to come first. isn't it? (metagoto) + static string ref = "$ref"; + if ( ref == m.firstElement().fieldName() ) { + const BSONElement& id = m["$id"]; + if (!id.eoo()) { // there's no check on $id exitence in sm implementation. risky ? + v8::Function* dbRef = getNamedCons( "DBRef" ); + v8::Handle argv[2]; + argv[0] = mongoToV8Element(m.firstElement()); + argv[1] = mongoToV8Element(m["$id"]); + return dbRef->NewInstance(2, argv); + } + } + Local o; if ( array ) o = v8::Array::New(); else o = v8::Object::New(); - + mongo::BSONObj sub; - + for ( BSONObjIterator i(m); i.more(); ) { const BSONElement& f = i.next();