summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-09-07 23:02:02 -0400
committerEliot Horowitz <eliot@10gen.com>2010-09-07 23:02:23 -0400
commit296ddbb6b8855dfbb3f42dc73cf437a179e6185a (patch)
tree725e187e4961e55bc97f39d33371f20a03623418 /scripting
parentf4fd753e08058b0d44fc101bb899008cf09f94e3 (diff)
downloadmongo-296ddbb6b8855dfbb3f42dc73cf437a179e6185a.tar.gz
fix Object.bsonsize with null param SERVER-1753
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine_spidermonkey.cpp8
-rw-r--r--scripting/v8_db.cpp11
2 files changed, 15 insertions, 4 deletions
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index 8952b339702..ed7aae47b5d 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -959,10 +959,16 @@ namespace mongo {
JS_ReportError( cx , "bsonsize requires one valid object" );
return JS_FALSE;
}
+
+ Convertor c(cx);
+ if ( argv[0] == JSVAL_VOID || argv[0] == JSVAL_NULL ){
+ *rval = c.toval( 0.0 );
+ return JS_TRUE;
+ }
+
JSObject * o = JSVAL_TO_OBJECT( argv[0] );
- Convertor c(cx);
double size = 0;
if ( JS_InstanceOf( cx , o , &bson_ro_class , 0 ) ||
diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp
index 2ccca1c7c0c..f4acac001d9 100644
--- a/scripting/v8_db.cpp
+++ b/scripting/v8_db.cpp
@@ -737,9 +737,14 @@ namespace mongo {
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" ) );
- }
+ if ( args.Length() != 1 )
+ return v8::ThrowException( v8::String::New( "bonsisze needs 1 argument" ) );
+
+ if ( args[0]->IsNull() )
+ return v8::Number::New(0);
+
+ if ( ! args[ 0 ]->IsObject() )
+ return v8::ThrowException( v8::String::New( "argument to bonsisze has to be an object" ) );
return v8::Number::New( v8ToMongo( args[ 0 ]->ToObject() ).objsize() );
}