SERVER-357 NumberLong class for sm

This commit is contained in:
Aaron
2010-01-20 15:02:46 -08:00
parent b6f8abcef1
commit b147ccf752
4 changed files with 83 additions and 3 deletions

View File

@@ -158,6 +158,14 @@ namespace mongo {
return toString( JS_ValueToString( _context , v ) );
}
// NOTE No validation of passed in object
long long toNumberLongUnsafe( JSObject *o ) {
unsigned long long val =
( (unsigned long long)( getNumber( o , "top" ) ) << 32 ) +
( unsigned long long )( getNumber( o , "bottom" ) );
return val;
}
double toNumber( jsval v ){
double d;
uassert( 10214 , "not a number" , JS_ValueToNumber( _context , v , &d ) );
@@ -469,7 +477,6 @@ namespace mongo {
return JSVAL_NULL;
case NumberDouble:
case NumberInt:
case NumberLong:
return toval( e.number() );
case Symbol: // TODO: should we make a special class for this
case String:
@@ -557,7 +564,15 @@ namespace mongo {
setProperty( o , "i" , toval( (double)(e.timestampInc()) ) );
return OBJECT_TO_JSVAL( o );
}
case NumberLong: {
unsigned long long val = (unsigned long long)e.numberLong();
JSObject * o = JS_NewObject( _context , &numberlong_class , 0 , 0 );
// using 2 doubles here instead of a single double because certain double
// bit patterns represent undefined values and sm might trash them
setProperty( o , "top" , toval( (double)( val >> 32 ) ) );
setProperty( o , "bottom" , toval( (double)( val & 0x00000000ffffffff ) ) );
return OBJECT_TO_JSVAL( o );
}
case DBRef: {
JSObject * o = JS_NewObject( _context , &dbpointer_class , 0 , 0 );
setProperty( o , "ns" , toval( e.dbrefNS() ) );