diff options
author | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
commit | 5d342a758c6095b4d30aba0750b54f13b8916f51 (patch) | |
tree | 762e9aa84781f5e3b96db2c02d356c29cf0217c0 /scripting/utils.cpp | |
parent | cbe2d992e9cd1ea66af9fa91df006106775d3073 (diff) | |
download | mongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz |
Imported Upstream version 2.0.0
Diffstat (limited to 'scripting/utils.cpp')
-rw-r--r-- | scripting/utils.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/scripting/utils.cpp b/scripting/utils.cpp index 97eea10..612b173 100644 --- a/scripting/utils.cpp +++ b/scripting/utils.cpp @@ -25,7 +25,7 @@ namespace mongo { void installBenchmarkSystem( Scope& scope ); - BSONObj jsmd5( const BSONObj &a ) { + BSONObj jsmd5( const BSONObj &a, void* data ) { uassert( 10261 , "js md5 needs a string" , a.firstElement().type() == String ); const char * s = a.firstElement().valuestrsafe(); @@ -38,7 +38,7 @@ namespace mongo { return BSON( "" << digestToString( d ) ); } - BSONObj JSVersion( const BSONObj& args ) { + BSONObj JSVersion( const BSONObj& args, void* data ) { cout << "version: " << versionString << endl; if ( strstr( versionString , "+" ) ) printGitVersion(); @@ -46,6 +46,20 @@ namespace mongo { } + BSONObj JSSleep(const mongo::BSONObj &args, void* data) { + assert( args.nFields() == 1 ); + assert( args.firstElement().isNumber() ); + int ms = int( args.firstElement().number() ); + { + auto_ptr< ScriptEngine::Unlocker > u = globalScriptEngine->newThreadUnlocker(); + sleepmillis( ms ); + } + + BSONObjBuilder b; + b.appendUndefined( "" ); + return b.obj(); + } + // --------------------------------- // ---- installer -------- // --------------------------------- @@ -53,6 +67,7 @@ namespace mongo { void installGlobalUtils( Scope& scope ) { scope.injectNative( "hex_md5" , jsmd5 ); scope.injectNative( "version" , JSVersion ); + scope.injectNative( "sleep" , JSSleep ); installBenchmarkSystem( scope ); } |