void initScope(Scope& scope) { // Need to define this method before JSFiles::utils is executed. scope.injectNative("_useWriteCommandsDefault", useWriteCommandsDefault); scope.injectNative("_writeMode", writeMode); scope.injectNative("_readMode", readMode); scope.externalSetup(); mongo::shell_utils::installShellUtils(scope); scope.execSetup(JSFiles::servers); scope.execSetup(JSFiles::shardingtest); scope.execSetup(JSFiles::servers_misc); scope.execSetup(JSFiles::replsettest); scope.execSetup(JSFiles::replsetbridge); scope.injectNative("benchRun", BenchRunner::benchRunSync); scope.injectNative("benchRunSync", BenchRunner::benchRunSync); scope.injectNative("benchStart", BenchRunner::benchStart); scope.injectNative("benchFinish", BenchRunner::benchFinish); if (!_dbConnect.empty()) { uassert(12513, "connect failed", scope.exec(_dbConnect, "(connect)", false, true, false)); } if (!_dbAuth.empty()) { uassert(12514, "login failed", scope.exec(_dbAuth, "(auth)", true, true, false)); } }
void run(){ Scope * s = globalScriptEngine->createScope(); ASSERT( s->exec( "a = 5;" , "a" , false , true , false ) ); ASSERT_EQUALS( 5 , s->getNumber("a" ) ); ASSERT( s->exec( "var b = 6;" , "b" , false , true , false ) ); ASSERT_EQUALS( 6 , s->getNumber("b" ) ); delete s; }
void initScope( Scope &scope ) { scope.externalSetup(); mongo::shell_utils::installShellUtils( scope ); scope.execSetup(JSFiles::servers); if ( !_dbConnect.empty() ) { uassert( 12513, "connect failed", scope.exec( _dbConnect , "(connect)" , false , true , false ) ); if ( !_dbAuth.empty() ) { installGlobalUtils( scope ); uassert( 12514, "login failed", scope.exec( _dbAuth , "(auth)" , true , true , false ) ); } } }
void run() { Scope * s = globalScriptEngine->newScope(); s->localConnect( "blah" ); BSONObjBuilder b; long long val = (long long)( 0xbabadeadbeefbaddULL ); b.append( "a", val ); BSONObj in = b.obj(); s->setObject( "a", in ); BSONObj out = s->getObject( "a" ); ASSERT_EQUALS( mongo::NumberLong, out.firstElement().type() ); ASSERT( s->exec( "printjson( a ); b = {b:a.a}", "foo", false, true, false ) ); out = s->getObject( "b" ); ASSERT_EQUALS( mongo::NumberLong, out.firstElement().type() ); if( val != out.firstElement().numberLong() ) { cout << val << endl; cout << out.firstElement().numberLong() << endl; cout << out.toString() << endl; ASSERT_EQUALS( val, out.firstElement().numberLong() ); } ASSERT( s->exec( "c = {c:a.a.toString()}", "foo", false, true, false ) ); out = s->getObject( "c" ); stringstream ss; ss << "NumberLong(\"" << val << "\")"; ASSERT_EQUALS( ss.str(), out.firstElement().valuestr() ); ASSERT( s->exec( "d = {d:a.a.toNumber()}", "foo", false, true, false ) ); out = s->getObject( "d" ); ASSERT_EQUALS( NumberDouble, out.firstElement().type() ); ASSERT_EQUALS( double( val ), out.firstElement().number() ); ASSERT( s->exec( "e = {e:a.a.floatApprox}", "foo", false, true, false ) ); out = s->getObject( "e" ); ASSERT_EQUALS( NumberDouble, out.firstElement().type() ); ASSERT_EQUALS( double( val ), out.firstElement().number() ); ASSERT( s->exec( "f = {f:a.a.top}", "foo", false, true, false ) ); out = s->getObject( "f" ); ASSERT( NumberDouble == out.firstElement().type() || NumberInt == out.firstElement().type() ); s->setObject( "z", BSON( "z" << (long long)( 4 ) ) ); ASSERT( s->exec( "y = {y:z.z.top}", "foo", false, true, false ) ); out = s->getObject( "y" ); ASSERT_EQUALS( Undefined, out.firstElement().type() ); ASSERT( s->exec( "x = {x:z.z.floatApprox}", "foo", false, true, false ) ); out = s->getObject( "x" ); ASSERT( NumberDouble == out.firstElement().type() || NumberInt == out.firstElement().type() ); ASSERT_EQUALS( double( 4 ), out.firstElement().number() ); ASSERT( s->exec( "w = {w:z.z}", "foo", false, true, false ) ); out = s->getObject( "w" ); ASSERT_EQUALS( mongo::NumberLong, out.firstElement().type() ); ASSERT_EQUALS( 4, out.firstElement().numberLong() ); }