Permalink
Browse files

Merge branch 'smshell'

Conflicts:
	jstests/count.js
	scripting/engine_spidermonkey.cpp
  • Loading branch information...
2 parents 6b8c0c1 + 0516fad commit 2db1e0ca72753543cbb468e95442396149169f08 @erh erh committed May 15, 2009
View
@@ -207,12 +207,13 @@ coreServerFiles = [ "util/message_server_port.cpp" , "util/message_server_asio.c
serverOnlyFiles = Split( "db/query.cpp db/introspect.cpp db/btree.cpp db/clientcursor.cpp db/tests.cpp db/repl.cpp db/btreecursor.cpp db/cloner.cpp db/namespace.cpp db/matcher.cpp db/dbcommands.cpp db/dbeval.cpp db/dbwebserver.cpp db/dbinfo.cpp db/dbhelpers.cpp db/instance.cpp db/pdfile.cpp db/cursor.cpp db/security_commands.cpp db/security.cpp util/miniwebserver.cpp db/storage.cpp db/reccache.cpp db/queryoptimizer.cpp" )
if usesm:
- serverOnlyFiles += [ "scripting/engine_spidermonkey.cpp" ]
+ commonFiles += [ "scripting/engine_spidermonkey.cpp" ]
nojni = True
elif not nojni:
- serverOnlyFiles += [ "scripting/engine_java.cpp" ]
+ commonFiles += [ "scripting/engine_java.cpp" ]
else:
- serverOnlyFiles += [ "scripting/engine_none.cpp" ]
+ commonFiles += [ "scripting/engine_none.cpp" ]
+ nojni = True
coreShardFiles = []
shardServerFiles = coreShardFiles + Glob( "s/strategy*.cpp" ) + [ "s/commands_admin.cpp" , "s/commands_public.cpp" , "s/request.cpp" , "s/cursors.cpp" , "s/server.cpp" ] + [ "s/shard.cpp" , "s/shardkey.cpp" , "s/config.cpp" ]
@@ -499,12 +500,6 @@ def doConfigure( myenv , needJava=True , needPcre=True , shell=False ):
return False
- if shell:
- if windows:
- myenv.Append( LIBS=["v8"] )
- else:
- myCheckLib( "v8" , True )
-
if needPcre and not conf.CheckCXXHeader( 'pcrecpp.h' ):
print( "can't find pcre" )
Exit(1)
@@ -582,15 +577,6 @@ def doConfigure( myenv , needJava=True , needPcre=True , shell=False ):
return conf.Finish()
env = doConfigure( env )
-# --- v8 ---
-
-v8Home = GetOption( "v8home" )
-
-if not os.path.exists( v8Home ):
- for poss in [ "../v8" , "../../v8/" , "../open-source/v8" ]:
- if os.path.exists( poss ):
- v8Home = poss
- break
# --- js concat ---
@@ -715,16 +701,12 @@ if darwin or clientEnv["_HAVEPCAP"]:
sniffEnv.Program( "mongosniff" , "tools/sniffer.cpp" )
# --- shell ---
-# shell is complicated by the fact that v8 doesn't work 64-bit yet
env.JSConcat( "shell/mongo.jsall" , Glob( "shell/*.js" ) )
env.JSHeader( "shell/mongo.jsall" )
shellEnv = env.Clone();
-shellEnv.Append( CPPPATH=[ "../" , v8Home + "/include/" ] )
-shellEnv.Append( LIBPATH=[ v8Home] )
-
if release and ( ( darwin and force64 ) or linux64 ):
shellEnv["LINKFLAGS"] = env["LINKFLAGS_CLEAN"]
shellEnv["LIBS"] = env["LIBS_CLEAN"]
@@ -733,14 +715,7 @@ if release and ( ( darwin and force64 ) or linux64 ):
if noshell:
print( "not building shell" )
elif not onlyServer:
- weird = linux64 or force64
-
- if linux64:
- shellEnv.Append( CFLAGS="-m32" )
- shellEnv.Append( CXXFLAGS="-m32" )
- shellEnv.Append( LINKFLAGS="-m32" )
- shellEnv.Append( LIBPATH=[ "/usr/lib32" , "/usr/lib" ] )
- shellEnv["LIBPATH"].remove( "/usr/lib64" )
+ weird = force64
if force64:
shellEnv["CFLAGS"].remove("-m64")
@@ -762,7 +737,7 @@ elif not onlyServer:
if windows:
shellEnv.Append( LIBS=["winmm.lib"] )
- coreShellFiles = [ "shell/MongoJS.cpp" , "shell/ShellUtils.cpp" , "shell/dbshell.cpp" , "scripting/engine_v8.cpp" ]
+ coreShellFiles = [ "shell/dbshell.cpp" , "shell/utils.cpp" ]
if weird:
shell32BitFiles = coreShellFiles
View
@@ -28,6 +28,7 @@
#include "../stdafx.h"
#include "../util/builder.h"
+#include "../util/optime.h"
#include "boost/utility.hpp"
#include <set>
@@ -1007,6 +1008,11 @@ namespace mongo {
b.append( fieldName );
b.append( val );
}
+
+ void appendTimestamp( const char *fieldName , unsigned long long time , unsigned int inc ){
+ OpTime t( time / 1000 , inc );
+ appendTimestamp( fieldName , t.asDate() );
+ }
/* Deprecated (but supported) */
void appendDBRef( const char *fieldName, const char *ns, const OID &oid ) {
View
@@ -143,7 +143,7 @@ namespace mongo {
if ( e.eoo() )
break;
- if ( ( e.type() == CodeWScope || e.type() == Code ) && strcmp(e.fieldName(), "$where")==0 ) {
+ if ( ( e.type() == CodeWScope || e.type() == Code || e.type() == String ) && strcmp(e.fieldName(), "$where")==0 ) {
// $where: function()...
uassert( "$where occurs twice?", where == 0 );
where = new Where();
View
@@ -118,6 +118,12 @@ namespace JSTests {
s->setThis( & o );
s->invoke( "return this.z;" , BSONObj() );
ASSERT_EQUALS( "sara" , s->getString( "return" ) );
+
+ s->invoke( "this.z == 'sara';" , BSONObj() );
+ ASSERT_EQUALS( true , s->getBoolean( "return" ) );
+
+ s->invoke( "this.z == 'asara';" , BSONObj() );
+ ASSERT_EQUALS( false , s->getBoolean( "return" ) );
s->invoke( "return this.x == 17;" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "return" ) );
@@ -214,7 +220,100 @@ namespace JSTests {
delete s;
}
};
-
+
+ class OtherJSTypes {
+ public:
+ void run(){
+ Scope * s = globalScriptEngine->createScope();
+
+ { // date
+ BSONObj o;
+ {
+ BSONObjBuilder b;
+ b.appendDate( "d" , 123456789 );
+ o = b.obj();
+ }
+ s->setObject( "x" , o );
+
+ s->invoke( "return x.d.getTime() != 12;" , BSONObj() );
+ ASSERT_EQUALS( true, s->getBoolean( "return" ) );
+
+ s->invoke( "z = x.d.getTime();" , BSONObj() );
+ ASSERT_EQUALS( 123456789 , s->getNumber( "z" ) );
+
+ s->invoke( "z = { z : x.d }" , BSONObj() );
+ BSONObj out = s->getObject( "z" );
+ ASSERT( out["z"].type() == Date );
+ }
+
+ { // regex
+ BSONObj o;
+ {
+ BSONObjBuilder b;
+ b.appendRegex( "r" , "^a" , "i" );
+ o = b.obj();
+ }
+ s->setObject( "x" , o );
+
+ s->invoke( "z = x.r.test( 'b' );" , BSONObj() );
+ ASSERT_EQUALS( false , s->getBoolean( "z" ) );
+
+ s->invoke( "z = x.r.test( 'a' );" , BSONObj() );
+ ASSERT_EQUALS( true , s->getBoolean( "z" ) );
+
+ s->invoke( "z = x.r.test( 'ba' );" , BSONObj() );
+ ASSERT_EQUALS( false , s->getBoolean( "z" ) );
+
+ s->invoke( "z = { a : x.r };" , BSONObj() );
+
+ BSONObj out = s->getObject("z");
+ ASSERT_EQUALS( (string)"^a" , out["a"].regex() );
+ ASSERT_EQUALS( (string)"i" , out["a"].regexFlags() );
+
+ }
+
+ delete s;
+ }
+ };
+
+ class SpecialDBTypes {
+ public:
+ void run(){
+ Scope * s = globalScriptEngine->createScope();
+
+ BSONObjBuilder b;
+ b.appendTimestamp( "a" , 123456789 );
+ b.appendMinKey( "b" );
+ b.appendMaxKey( "c" );
+ b.appendTimestamp( "d" , 1234000 , 9876 );
+
+
+ {
+ BSONObj t = b.done();
+ ASSERT_EQUALS( 1234000 , t["d"].timestampTime() );
+ ASSERT_EQUALS( 9876 , t["d"].timestampInc() );
+ }
+
+ s->setObject( "z" , b.obj() );
+
+ assert( s->invoke( "y = { a : z.a , b : z.b , c : z.c , d: z.d }" , BSONObj() ) == 0 );
+
+ BSONObj out = s->getObject( "y" );
+ ASSERT_EQUALS( Timestamp , out["a"].type() );
+ ASSERT_EQUALS( MinKey , out["b"].type() );
+ ASSERT_EQUALS( MaxKey , out["c"].type() );
+ ASSERT_EQUALS( Timestamp , out["d"].type() );
+
+ ASSERT_EQUALS( 9876 , out["d"].timestampInc() );
+ ASSERT_EQUALS( 1234000 , out["d"].timestampTime() );
+ ASSERT_EQUALS( 123456789 , out["a"].date() );
+
+
+ delete s;
+ }
+ };
+
+
class All : public Suite {
public:
All() {
@@ -226,6 +325,8 @@ namespace JSTests {
add< ObjectDecoding >();
add< JSOIDTests >();
add< ObjectModTests >();
+ add< OtherJSTypes >();
+ add< SpecialDBTypes >();
}
};
@@ -64,51 +64,52 @@ assert(v.result.toString().match(/nrecords\?:(\d+)/)[1] == 100,11);
db.getCollection( "test_db" ).drop();
assert(db.getCollection( "test_db" ).count() == 0,12);
db.getCollection( "test_db" ).dropIndexes();
-assert(db.getCollection( "test_db" ).getIndexes().length() == 0,13);
+assert(db.getCollection( "test_db" ).getIndexes().length == 0,13);
db.getCollection( "test_db" ).save({a:10});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 1,14);
+assert(db.getCollection( "test_db" ).getIndexes().length == 1,14);
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).save({a:10});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 2,15);
+print( tojson( db.getCollection( "test_db" ).getIndexes() ) );
+assert.eq(db.getCollection( "test_db" ).getIndexes().length , 2,15);
db.getCollection( "test_db" ).dropIndex({a:1});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 1,16);
+assert(db.getCollection( "test_db" ).getIndexes().length == 1,16);
db.getCollection( "test_db" ).save({a:10});
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).save({a:10});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 2,17);
+assert(db.getCollection( "test_db" ).getIndexes().length == 2,17);
db.getCollection( "test_db" ).dropIndex("a_1");
-assert.eq( db.getCollection( "test_db" ).getIndexes().length() , 1,18);
+assert.eq( db.getCollection( "test_db" ).getIndexes().length , 1,18);
db.getCollection( "test_db" ).save({a:10, b:11});
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).ensureIndex({b:1});
db.getCollection( "test_db" ).save({a:10, b:12});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 3,19);
+assert(db.getCollection( "test_db" ).getIndexes().length == 3,19);
db.getCollection( "test_db" ).dropIndex({b:1});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 2,20);
+assert(db.getCollection( "test_db" ).getIndexes().length == 2,20);
db.getCollection( "test_db" ).dropIndex({a:1});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 1,21);
+assert(db.getCollection( "test_db" ).getIndexes().length == 1,21);
db.getCollection( "test_db" ).save({a:10, b:11});
db.getCollection( "test_db" ).ensureIndex({a:1});
db.getCollection( "test_db" ).ensureIndex({b:1});
db.getCollection( "test_db" ).save({a:10, b:12});
-assert(db.getCollection( "test_db" ).getIndexes().length() == 3,22);
+assert(db.getCollection( "test_db" ).getIndexes().length == 3,22);
db.getCollection( "test_db" ).dropIndexes();
-assert(db.getCollection( "test_db" ).getIndexes().length() == 1,23);
+assert(db.getCollection( "test_db" ).getIndexes().length == 1,23);
db.getCollection( "test_db" ).find();
db.getCollection( "test_db" ).drop();
-assert(db.getCollection( "test_db" ).getIndexes().length() == 0,24);
+assert(db.getCollection( "test_db" ).getIndexes().length == 0,24);
View
@@ -3,22 +3,23 @@ t = db.jstests_count;
t.drop();
t.save( { i: 1 } );
t.save( { i: 2 } );
-assert.eq( 1, t.find( { i: 1 } ).count() );
-assert.eq( 1, t.count( { i: 1 } ) );
-assert.eq( 2, t.find().count() );
-assert.eq( 2, t.find( undefined ).count() );
-assert.eq( 2, t.find( null ).count() );
-assert.eq( 2, t.count() );
+assert.eq( 1, t.find( { i: 1 } ).count(), "A" );
+assert.eq( 1, t.count( { i: 1 } ) , "B" );
+assert.eq( 2, t.find().count() , "C" );
+assert.eq( 2, t.find( undefined ).count() , "D" );
+assert.eq( 2, t.find( null ).count() , "E" );
+assert.eq( 2, t.count() , "F" );
t.drop();
t.save( {a:true,b:false} );
t.ensureIndex( {b:1,a:1} );
-assert.eq( 1, t.find( {a:true,b:false} ).count() );
-assert.eq( 1, t.find( {b:false,a:true} ).count() );
+assert.eq( 1, t.find( {a:true,b:false} ).count() , "G" );
+assert.eq( 1, t.find( {b:false,a:true} ).count() , "H" );
t.drop();
t.save( {a:true,b:false} );
t.ensureIndex( {b:1,a:1,c:1} );
-assert.eq( 1, t.find( {a:true,b:false} ).count() );
-assert.eq( 1, t.find( {b:false,a:true} ).count() );
+
+assert.eq( 1, t.find( {a:true,b:false} ).count() , "I" );
+assert.eq( 1, t.find( {b:false,a:true} ).count() , "J" );
View
@@ -0,0 +1,8 @@
+
+t = db.date1;
+t.drop();
+
+d = new Date()
+t.save( { a : 1 , d : d } );
+
+assert.eq( d , t.findOne().d , "A" )
View
@@ -2,20 +2,20 @@ f = db.jstests_drop;
f.drop();
-assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() );
+assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "A" );
f.save( {} );
-assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() );
+assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "B" );
f.ensureIndex( {a:1} );
-assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() );
+assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "C" );
assert.commandWorked( db.runCommand( {drop:"jstests_drop"} ) );
-assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() );
+assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "D" );
-f = db.jstests_drop;
+f.resetIndexCache();
f.ensureIndex( {a:1} );
-assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() );
+assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "E" );
assert.commandWorked( db.runCommand( {deleteIndexes:"jstests_drop",index:"*"} ) );
-assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() );
+assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "G" );
// make sure we can still use it
f.save( {} );
-assert.eq( 1, f.find().hint( {_id:ObjectId( "000000000000000000000000" )} ).toArray().length );
+assert.eq( 1, f.find().hint( {_id:new ObjectId( "000000000000000000000000" )} ).toArray().length , "H" );
View
@@ -5,4 +5,4 @@ p.ensureIndex( { ts: 1 } );
e = p.find( { live: true, ts: { $lt: new Date( 1234119308272 ) }, cls: "entry", verticals: " alleyinsider" } ).sort( { ts: -1 } ).hint( { ts: 1 } ).explain();
assert.eq( e.startKey.ts.getTime(), new Date( 1234119308272 ).getTime() );
-assert.eq( 1, e.endKey.ts.$minElement );
+assert.eq( 1, e.endKey.ts.$minElement );
Oops, something went wrong.

0 comments on commit 2db1e0c

Please sign in to comment.