summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-12-21 20:40:04 -0800
committerAaron <aaron@10gen.com>2009-12-21 20:40:04 -0800
commit643ec0261b21c8053dfabe9a9446d7bdc3ef788d (patch)
tree52a0ab1ae5e8173e177b00f22b3d4781cf95f481 /scripting
parent793dfc134b24030ed19e29f4654077dfe56a75ce (diff)
downloadmongo-643ec0261b21c8053dfabe9a9446d7bdc3ef788d.tar.gz
SERVER-446 implement bsonsize() in v8
Diffstat (limited to 'scripting')
-rw-r--r--scripting/v8_db.cpp12
-rw-r--r--scripting/v8_db.h4
2 files changed, 14 insertions, 2 deletions
diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp
index 17775651d68..e766c0637a1 100644
--- a/scripting/v8_db.cpp
+++ b/scripting/v8_db.cpp
@@ -70,7 +70,7 @@ namespace mongo {
global->Set( v8::String::New("DBPointer") , FunctionTemplate::New( dbPointerInit ) );
global->Set( v8::String::New("BinData") , FunctionTemplate::New( binDataInit ) );
-
+
}
void installDBTypes( Handle<v8::Object>& global ){
@@ -102,6 +102,8 @@ namespace mongo {
BSONObjIterator i( o );
global->Set( v8::String::New("MaxKey"), mongoToV8Element( i.next() ) );
global->Set( v8::String::New("MinKey"), mongoToV8Element( i.next() ) );
+
+ global->Get( v8::String::New( "Object" ) )->ToObject()->Set( v8::String::New("bsonsize") , FunctionTemplate::New( bsonsize )->GetFunction() );
}
void destroyConnection( Persistent<Value> object, void* parameter){
@@ -511,4 +513,12 @@ namespace mongo {
return it;
}
+ v8::Handle<v8::Value> bsonsize( const v8::Arguments& args ) {
+
+ if (args.Length() != 1 || !args[ 0 ]->IsObject()) {
+ return v8::ThrowException( v8::String::New( "bonsisze needs 1 object" ) );
+ }
+
+ return v8::Number::New( v8ToMongo( args[ 0 ]->ToObject() ).objsize() );
+ }
}
diff --git a/scripting/v8_db.h b/scripting/v8_db.h
index 969256aae4b..95afcf2d4f8 100644
--- a/scripting/v8_db.h
+++ b/scripting/v8_db.h
@@ -63,5 +63,7 @@ namespace mongo {
v8::Handle<v8::Value> dbQueryIndexAccess( uint32_t index , const v8::AccessorInfo& info );
v8::Handle<v8::Value> collectionFallback( v8::Local<v8::String> name, const v8::AccessorInfo &info);
-
+
+ v8::Handle<v8::Value> bsonsize( const v8::Arguments& args );
+
}