diff options
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/engine.cpp | 4 | ||||
-rw-r--r-- | scripting/engine_spidermonkey.cpp | 3 | ||||
-rw-r--r-- | scripting/sm_db.cpp | 49 | ||||
-rw-r--r-- | scripting/v8_db.cpp | 22 |
4 files changed, 55 insertions, 23 deletions
diff --git a/scripting/engine.cpp b/scripting/engine.cpp index 9e20a3a..da108c6 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -305,7 +305,9 @@ namespace mongo { _real = 0; } else { - log() << "warning: scopeCache is empty!" << endl; + // this means that the Scope was killed from a different thread + // for example a cursor got timed out that has a $where clause + log(3) << "warning: scopeCache is empty!" << endl; delete _real; _real = 0; } diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 22102ba..c8f2eca 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -670,7 +670,8 @@ namespace mongo { CHECKNEWOBJECT(o,_context,"Bindata_BinData1"); int len; const char * data = e.binData( len ); - assert( JS_SetPrivate( _context , o , new BinDataHolder( data ) ) ); + assert( data ); + assert( JS_SetPrivate( _context , o , new BinDataHolder( data , len ) ) ); setProperty( o , "len" , toval( (double)len ) ); setProperty( o , "type" , toval( (double)e.binDataType() ) ); diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index 940d785..8ba612b 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -95,7 +95,13 @@ namespace mongo { JSBool internal_cursor_hasNext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ DBClientCursor *cursor = getCursor( cx, obj ); - *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE; + try { + *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE; + } + catch ( std::exception& e ){ + JS_ReportError( cx , e.what() ); + return JS_FALSE; + } return JS_TRUE; } @@ -108,13 +114,23 @@ namespace mongo { JSBool internal_cursor_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ DBClientCursor *cursor = getCursor( cx, obj ); - if ( ! cursor->more() ){ - JS_ReportError( cx , "cursor at the end" ); + + BSONObj n; + + try { + if ( ! cursor->more() ){ + JS_ReportError( cx , "cursor at the end" ); + return JS_FALSE; + } + + n = cursor->next(); + } + catch ( std::exception& e ){ + JS_ReportError( cx , e.what() ); return JS_FALSE; } - Convertor c(cx); - BSONObj n = cursor->next(); + Convertor c(cx); *rval = c.toval( &n ); return JS_TRUE; } @@ -310,7 +326,7 @@ namespace mongo { } JSBool mongo_remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ - smuassert( cx , "mongo_remove needs 2 arguments" , argc == 2 ); + smuassert( cx , "mongo_remove needs 2 or 3 arguments" , argc == 2 || argc == 3 ); smuassert( cx , "2nd param to insert has to be an object" , JSVAL_IS_OBJECT( argv[1] ) ); Convertor c( cx ); @@ -324,9 +340,12 @@ namespace mongo { string ns = c.toString( argv[0] ); BSONObj o = c.toObject( argv[1] ); - + bool justOne = false; + if ( argc > 2 ) + justOne = c.toBoolean( argv[2] ); + try { - conn->remove( ns , o ); + conn->remove( ns , o , justOne ); return JS_TRUE; } catch ( ... ){ @@ -861,12 +880,14 @@ namespace mongo { JSBool numberlong_tostring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ Convertor c(cx); stringstream ss; - if ( c.hasProperty( obj, "top" ) ) { - long long val = c.toNumberLongUnsafe( obj ); - ss << "NumberLong( \"" << val << "\" )"; - } else { - ss << "NumberLong( " << c.getNumber( obj, "floatApprox" ) << " )"; - } + long long val = c.toNumberLongUnsafe( obj ); + const long long limit = 2LL << 30; + + if ( val <= -limit || limit <= val ) + ss << "NumberLong(\"" << val << "\")"; + else + ss << "NumberLong(" << val << ")"; + string ret = ss.str(); return *rval = c.toval( ret.c_str() ); } diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp index 5752fde..e178875 100644 --- a/scripting/v8_db.cpp +++ b/scripting/v8_db.cpp @@ -297,7 +297,7 @@ namespace mongo { } v8::Handle<v8::Value> mongoRemove(const v8::Arguments& args){ - jsassert( args.Length() == 2 , "remove needs 2 args" ); + jsassert( args.Length() == 2 || args.Length() == 3 , "remove needs 2 args" ); jsassert( args[1]->IsObject() , "have to remove an object template" ); DBClientBase * conn = getConnection( args ); @@ -306,10 +306,15 @@ namespace mongo { v8::Handle<v8::Object> in = args[1]->ToObject(); BSONObj o = v8ToMongo( in ); + bool justOne = false; + if ( args.Length() > 2 ){ + justOne = args[2]->BooleanValue(); + } + DDD( "want to remove : " << o.jsonString() ); try { v8::Unlocker u; - conn->remove( ns , o ); + conn->remove( ns , o , justOne ); } catch ( ... ){ return v8::ThrowException( v8::String::New( "socket error on remove" ) ); @@ -714,11 +719,14 @@ namespace mongo { v8::Handle<v8::Object> it = args.This(); stringstream ss; - if ( !it->Has( v8::String::New( "top" ) ) ) { - ss << "NumberLong( " << it->Get( v8::String::New( "floatApprox" ) )->NumberValue() << " )"; - } else { - ss << "NumberLong( \"" << numberLongVal( it ) << "\" )"; - } + long long val = numberLongVal( it ); + const long long limit = 2LL << 30; + + if ( val <= -limit || limit <= val ) + ss << "NumberLong(\"" << val << "\")"; + else + ss << "NumberLong(" << val << ")"; + string ret = ss.str(); return v8::String::New( ret.c_str() ); } |