0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/scripting/engine_v8.cpp

34 lines
1.1 KiB
C++
Raw Normal View History

2009-05-04 17:49:18 +02:00
#include "engine_v8.h"
#include "../shell/MongoJS.h"
2009-05-04 17:49:18 +02:00
namespace mongo {
void ScriptEngine::setup(){
if ( !globalScriptEngine ){
globalScriptEngine = new V8ScriptEngine();
}
}
Handle< Value > V8Scope::nativeCallback( const Arguments &args ) {
Local< External > f = External::Cast( *args.Callee()->Get( v8::String::New( "_native_function" ) ) );
NativeFunction function = ( NativeFunction )( f->Value() );
BSONObjBuilder b;
for( int i = 0; i < args.Length(); ++i ) {
stringstream ss;
ss << i;
v8ToMongoElement( b, v8::String::New( "foo" ), ss.str(), args[ i ] );
}
BSONObj ret;
try {
ret = function( b.done() );
} catch( const std::exception &e ) {
return v8::ThrowException(v8::String::New(e.what()));
} catch( ... ) {
return v8::ThrowException(v8::String::New("unknown exception"));
}
return mongoToV8Element( ret.firstElement() );
2009-05-04 17:49:18 +02:00
}
2009-05-05 00:45:32 +02:00
} // namespace mongo