summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-03-08 19:51:05 -0800
committerAaron <aaron@10gen.com>2010-03-09 10:05:08 -0800
commit06279cde9a0a4e840a93f1ac0185f93b30d80bee (patch)
tree6d69dec9fffe417769c95ce5ce8892b5cccb7ff5
parent677a095c221b699481da242520547a6b787dbafb (diff)
downloadmongo-06279cde9a0a4e840a93f1ac0185f93b30d80bee.tar.gz
SERVER-705 make v8 timestamp fields consistent with sm
-rw-r--r--scripting/v8_wrapper.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/scripting/v8_wrapper.cpp b/scripting/v8_wrapper.cpp
index cd111b13662..7edc2a7ef24 100644
--- a/scripting/v8_wrapper.cpp
+++ b/scripting/v8_wrapper.cpp
@@ -124,7 +124,7 @@ namespace mongo {
case mongo::Timestamp: {
Local<v8::Object> sub = v8::Object::New();
- sub->Set( v8::String::New( "time" ) , v8::Date::New( f.timestampTime() ) );
+ sub->Set( v8::String::New( "t" ) , v8::Date::New( f.timestampTime() ) );
sub->Set( v8::String::New( "i" ) , v8::Number::New( f.timestampInc() ) );
o->Set( v8::String::New( f.fieldName() ) , sub );
@@ -213,7 +213,7 @@ namespace mongo {
case mongo::Timestamp: {
Local<v8::Object> sub = v8::Object::New();
- sub->Set( v8::String::New( "time" ) , v8::Date::New( f.timestampTime() ) );
+ sub->Set( v8::String::New( "t" ) , v8::Date::New( f.timestampTime() ) );
sub->Set( v8::String::New( "i" ) , v8::Number::New( f.timestampInc() ) );
return sub;
@@ -273,6 +273,27 @@ namespace mongo {
}
if ( value->IsObject() ){
+ // The user could potentially modify the fields of these special objects,
+ // wreaking havoc when we attempt to reinterpret them. Not doing any validation
+ // for now...
+ Local< v8::Object > obj = value->ToObject();
+ if ( obj->InternalFieldCount() && obj->GetInternalField( 0 )->IsNumber() ) {
+ switch( obj->GetInternalField( 0 )->ToInt32()->Value() ) { // NOTE Uint32's Value() gave me a linking error, so going with this instead
+ case Timestamp:
+ b.appendTimestamp( sname.c_str(),
+ Date_t( v8::Date::Cast( *obj->Get( v8::String::New( "t" ) ) )->NumberValue() ),
+ obj->Get( v8::String::New( "i" ) )->ToInt32()->Value() );
+ return;
+ case MinKey:
+ b.appendMinKey( sname.c_str() );
+ return;
+ case MaxKey:
+ b.appendMaxKey( sname.c_str() );
+ return;
+ default:
+ assert( "invalid internal field" == 0 );
+ }
+ }
string s = toSTLString( value );
if ( s.size() && s[0] == '/' ){
s = s.substr( 1 );