summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-01-25 10:06:06 -0800
committerAaron <aaron@10gen.com>2010-01-25 10:06:06 -0800
commita85db023f9a01bcab68386fbe0cf32ccc196d785 (patch)
tree1b57c1c15c14c7168be49add9fe7340ed8a08c79 /scripting
parent33bd6d1fe1fff2d9b457662e41e217ceee4d174b (diff)
downloadmongo-a85db023f9a01bcab68386fbe0cf32ccc196d785.tar.gz
SERVER-357 NumberLong converts to number (double) implicitly when doing operations
Diffstat (limited to 'scripting')
-rw-r--r--scripting/sm_db.cpp17
-rw-r--r--scripting/v8_db.cpp25
-rw-r--r--scripting/v8_db.h3
3 files changed, 28 insertions, 17 deletions
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp
index 1f15d0bc07e..9303b3faf39 100644
--- a/scripting/sm_db.cpp
+++ b/scripting/sm_db.cpp
@@ -664,6 +664,15 @@ namespace mongo {
JSCLASS_NO_OPTIONAL_MEMBERS
};
+ JSBool numberlong_valueof(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
+ Convertor c(cx);
+ return *rval = c.toval( double( c.toNumberLongUnsafe( obj ) ) );
+ }
+
+ JSBool numberlong_tonumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
+ return numberlong_valueof( cx, obj, argc, argv, rval );
+ }
+
JSBool numberlong_tostring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
stringstream ss;
@@ -671,15 +680,11 @@ namespace mongo {
string ret = ss.str();
return *rval = c.toval( ret.c_str() );
}
-
- JSBool numberlong_tonumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
- Convertor c(cx);
- return *rval = c.toval( double( c.toNumberLongUnsafe( obj ) ) );
- }
JSFunctionSpec numberlong_functions[] = {
- { "toString" , numberlong_tostring , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
+ { "valueOf" , numberlong_valueof , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ "toNumber" , numberlong_tonumber , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
+ { "toString" , numberlong_tostring , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } ,
{ 0 }
};
diff --git a/scripting/v8_db.cpp b/scripting/v8_db.cpp
index a24d008380c..4ccbf37d4a0 100644
--- a/scripting/v8_db.cpp
+++ b/scripting/v8_db.cpp
@@ -53,8 +53,9 @@ namespace mongo {
v8::Local<v8::FunctionTemplate> numberLong = FunctionTemplate::New( numberLongInit );
v8::Local<v8::Template> proto = numberLong->PrototypeTemplate();
- proto->Set( v8::String::New( "toString" ) , FunctionTemplate::New( numberLongToString ) );
+ proto->Set( v8::String::New( "valueOf" ) , FunctionTemplate::New( numberLongValueOf ) );
proto->Set( v8::String::New( "toNumber" ) , FunctionTemplate::New( numberLongToNumber ) );
+ proto->Set( v8::String::New( "toString" ) , FunctionTemplate::New( numberLongToString ) );
return numberLong;
}
@@ -566,10 +567,10 @@ namespace mongo {
return it;
}
- v8::Handle<v8::Value> numberLongToString( const v8::Arguments& args ) {
+ v8::Handle<v8::Value> numberLongValueOf( const v8::Arguments& args ) {
if (args.Length() != 0) {
- return v8::ThrowException( v8::String::New( "toString needs 0 arguments" ) );
+ return v8::ThrowException( v8::String::New( "toNumber needs 0 arguments" ) );
}
v8::Handle<v8::Object> it = args.This();
@@ -578,16 +579,17 @@ namespace mongo {
( (unsigned long long)( it->Get( v8::String::New( "top" ) )->ToInt32()->Value() ) << 32 ) +
(unsigned)( it->Get( v8::String::New( "bottom" ) )->ToInt32()->Value() );
- stringstream ss;
- ss << (long long)val;
- string ret = ss.str();
- return v8::String::New( ret.c_str() );
+ return v8::Number::New( double( (long long)val ) );
}
v8::Handle<v8::Value> numberLongToNumber( const v8::Arguments& args ) {
+ return numberLongValueOf( args );
+ }
+
+ v8::Handle<v8::Value> numberLongToString( const v8::Arguments& args ) {
if (args.Length() != 0) {
- return v8::ThrowException( v8::String::New( "toNumber needs 0 arguments" ) );
+ return v8::ThrowException( v8::String::New( "toString needs 0 arguments" ) );
}
v8::Handle<v8::Object> it = args.This();
@@ -596,9 +598,12 @@ namespace mongo {
( (unsigned long long)( it->Get( v8::String::New( "top" ) )->ToInt32()->Value() ) << 32 ) +
(unsigned)( it->Get( v8::String::New( "bottom" ) )->ToInt32()->Value() );
- return v8::Number::New( double( (long long)val ) );
+ stringstream ss;
+ ss << (long long)val;
+ string ret = ss.str();
+ return v8::String::New( ret.c_str() );
}
-
+
v8::Handle<v8::Value> bsonsize( const v8::Arguments& args ) {
if (args.Length() != 1 || !args[ 0 ]->IsObject()) {
diff --git a/scripting/v8_db.h b/scripting/v8_db.h
index 860593e33b7..6abac3554fc 100644
--- a/scripting/v8_db.h
+++ b/scripting/v8_db.h
@@ -61,8 +61,9 @@ namespace mongo {
v8::Handle<v8::Value> binDataInit( const v8::Arguments& args );
v8::Handle<v8::Value> numberLongInit( const v8::Arguments& args );
- v8::Handle<v8::Value> numberLongToString(const v8::Arguments& args);
v8::Handle<v8::Value> numberLongToNumber(const v8::Arguments& args);
+ v8::Handle<v8::Value> numberLongValueOf(const v8::Arguments& args);
+ v8::Handle<v8::Value> numberLongToString(const v8::Arguments& args);
v8::Handle<v8::Value> dbQueryInit( const v8::Arguments& args );
v8::Handle<v8::Value> dbQueryIndexAccess( uint32_t index , const v8::AccessorInfo& info );