Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit b42dd5c67e9d9e86b0a62736fb8fda324a1d1806 1 parent 8864cfa
@wpiekutowski wpiekutowski authored erh committed
View
2  dbtests/jstests.cpp
@@ -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
28 jstests/numberlong.js
@@ -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
14 scripting/sm_db.cpp
@@ -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
13 scripting/v8_db.cpp
@@ -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() );
}
Please sign in to comment.
Something went wrong with that request. Please try again.