Skip to content

Commit

Permalink
clean up cursor exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Sep 15, 2010
1 parent 833d720 commit c84d2e1
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions scripting/sm_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit c84d2e1

Please sign in to comment.