Permalink
Browse files

NumberLong shell output changed to NumberLong(111111111111) or Number…

…Long(11111) (when absolute value < 2^30) SERVER-1659

Signed-off-by: Eliot Horowitz <eliot@10gen.com>
  • Loading branch information...
1 parent 8864cfa commit b42dd5c67e9d9e86b0a62736fb8fda324a1d1806 @wpiekutowski wpiekutowski committed with erh Aug 29, 2010
Showing with 31 additions and 26 deletions.
  1. +1 −1 dbtests/jstests.cpp
  2. +14 −14 jstests/numberlong.js
  3. +8 −6 scripting/sm_db.cpp
  4. +8 −5 scripting/v8_db.cpp
View
@@ -541,7 +541,7 @@ namespace JSTests {
ASSERT( s->exec( "c = {c:a.a.toString()}", "foo", false, true, false ) );
out = s->getObject( "c" );
stringstream ss;
- ss << "NumberLong( \"" << val << "\" )";
+ ss << "NumberLong(\"" << val << "\")";
ASSERT_EQUALS( ss.str(), out.firstElement().valuestr() );
ASSERT( s->exec( "d = {d:a.a.toNumber()}", "foo", false, true, false ) );
View
@@ -4,50 +4,50 @@ n = new NumberLong( 4 );
assert.eq.automsg( "4", "n" );
assert.eq.automsg( "4", "n.toNumber()" );
assert.eq.automsg( "8", "n + 4" );
-assert.eq.automsg( "'NumberLong( 4 )'", "n.toString()" );
-assert.eq.automsg( "'NumberLong( 4 )'", "tojson( n )" );
+assert.eq.automsg( "'NumberLong(4)'", "n.toString()" );
+assert.eq.automsg( "'NumberLong(4)'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
-assert.eq.automsg( "'{ \"a\" : NumberLong( 4 ) }'", "p" );
+assert.eq.automsg( "'{ \"a\" : NumberLong(4) }'", "p" );
-assert.eq.automsg( "NumberLong( 4 )", "eval( tojson( NumberLong( 4 ) ) )" );
+assert.eq.automsg( "NumberLong(4 )", "eval( tojson( NumberLong( 4 ) ) )" );
assert.eq.automsg( "a", "eval( tojson( a ) )" );
n = new NumberLong( -4 );
assert.eq.automsg( "-4", "n" );
assert.eq.automsg( "-4", "n.toNumber()" );
assert.eq.automsg( "0", "n + 4" );
-assert.eq.automsg( "'NumberLong( -4 )'", "n.toString()" );
-assert.eq.automsg( "'NumberLong( -4 )'", "tojson( n )" );
+assert.eq.automsg( "'NumberLong(-4)'", "n.toString()" );
+assert.eq.automsg( "'NumberLong(-4)'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
-assert.eq.automsg( "'{ \"a\" : NumberLong( -4 ) }'", "p" );
+assert.eq.automsg( "'{ \"a\" : NumberLong(-4) }'", "p" );
// too big to fit in double
n = new NumberLong( "11111111111111111" );
assert.eq.automsg( "11111111111111112", "n.toNumber()" );
assert.eq.automsg( "11111111111111116", "n + 4" );
-assert.eq.automsg( "'NumberLong( \"11111111111111111\" )'", "n.toString()" );
-assert.eq.automsg( "'NumberLong( \"11111111111111111\" )'", "tojson( n )" );
+assert.eq.automsg( "'NumberLong(\"11111111111111111\")'", "n.toString()" );
+assert.eq.automsg( "'NumberLong(\"11111111111111111\")'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
-assert.eq.automsg( "'{ \"a\" : NumberLong( \"11111111111111111\" ) }'", "p" );
+assert.eq.automsg( "'{ \"a\" : NumberLong(\"11111111111111111\") }'", "p" );
-assert.eq.automsg( "NumberLong( '11111111111111111' )", "eval( tojson( NumberLong( '11111111111111111' ) ) )" );
+assert.eq.automsg( "NumberLong('11111111111111111' )", "eval( tojson( NumberLong( '11111111111111111' ) ) )" );
assert.eq.automsg( "a", "eval( tojson( a ) )" );
n = new NumberLong( "-11111111111111111" );
assert.eq.automsg( "-11111111111111112", "n.toNumber()" );
assert.eq.automsg( "-11111111111111108", "n + 4" );
-assert.eq.automsg( "'NumberLong( \"-11111111111111111\" )'", "n.toString()" );
-assert.eq.automsg( "'NumberLong( \"-11111111111111111\" )'", "tojson( n )" );
+assert.eq.automsg( "'NumberLong(\"-11111111111111111\")'", "n.toString()" );
+assert.eq.automsg( "'NumberLong(\"-11111111111111111\")'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
-assert.eq.automsg( "'{ \"a\" : NumberLong( \"-11111111111111111\" ) }'", "p" );
+assert.eq.automsg( "'{ \"a\" : NumberLong(\"-11111111111111111\") }'", "p" );
// parsing
assert.throws.automsg( function() { new NumberLong( "" ); } );
View
@@ -880,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() );
}
View
@@ -719,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() );
}

0 comments on commit b42dd5c

Please sign in to comment.