From 5d342a758c6095b4d30aba0750b54f13b8916f51 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Wed, 14 Sep 2011 17:08:06 +0200 Subject: Imported Upstream version 2.0.0 --- scripting/engine.h | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'scripting/engine.h') diff --git a/scripting/engine.h b/scripting/engine.h index 62afd77..1f9f1f5 100644 --- a/scripting/engine.h +++ b/scripting/engine.h @@ -27,18 +27,8 @@ namespace mongo { const StringData& source; }; - namespace JSFiles { - extern const JSFile collection; - extern const JSFile db; - extern const JSFile mongo; - extern const JSFile mr; - extern const JSFile query; - extern const JSFile servers; - extern const JSFile utils; - } - typedef unsigned long long ScriptingFunction; - typedef BSONObj (*NativeFunction) ( const BSONObj &args ); + typedef BSONObj (*NativeFunction) ( const BSONObj &args, void* data ); class Scope : boost::noncopyable { public: @@ -48,7 +38,7 @@ namespace mongo { virtual void reset() = 0; virtual void init( const BSONObj * data ) = 0; void init( const char * data ) { - BSONObj o( data , 0 ); + BSONObj o( data ); init( &o ); } @@ -79,14 +69,15 @@ namespace mongo { virtual int type( const char *field ) = 0; - void append( BSONObjBuilder & builder , const char * fieldName , const char * scopeName ); + virtual void append( BSONObjBuilder & builder , const char * fieldName , const char * scopeName ); virtual void setElement( const char *field , const BSONElement& e ) = 0; virtual void setNumber( const char *field , double val ) = 0; virtual void setString( const char *field , const char * val ) = 0; virtual void setObject( const char *field , const BSONObj& obj , bool readOnly=true ) = 0; virtual void setBoolean( const char *field , bool val ) = 0; - virtual void setThis( const BSONObj * obj ) = 0; + virtual void setFunction( const char *field , const char * code ) = 0; +// virtual void setThis( const BSONObj * obj ) = 0; virtual ScriptingFunction createFunction( const char * code ); @@ -94,18 +85,18 @@ namespace mongo { /** * @return 0 on success */ - virtual int invoke( ScriptingFunction func , const BSONObj& args, int timeoutMs = 0 , bool ignoreReturn = false ) = 0; - void invokeSafe( ScriptingFunction func , const BSONObj& args, int timeoutMs = 0 ) { - int res = invoke( func , args , timeoutMs ); + virtual int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 , bool ignoreReturn = false, bool readOnlyArgs = false, bool readOnlyRecv = false ) = 0; + void invokeSafe( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0, bool readOnlyArgs = false, bool readOnlyRecv = false ) { + int res = invoke( func , args , recv, timeoutMs, readOnlyArgs, readOnlyRecv ); if ( res == 0 ) return; throw UserException( 9004 , (string)"invoke failed: " + getError() ); } virtual string getError() = 0; - int invoke( const char* code , const BSONObj& args, int timeoutMs = 0 ); - void invokeSafe( const char* code , const BSONObj& args, int timeoutMs = 0 ) { - if ( invoke( code , args , timeoutMs ) == 0 ) + int invoke( const char* code , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 ); + void invokeSafe( const char* code , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 ) { + if ( invoke( code , args , recv, timeoutMs ) == 0 ) return; throw UserException( 9005 , (string)"invoke failed: " + getError() ); } @@ -119,19 +110,11 @@ namespace mongo { execSetup(file.source, file.name); } - void execCoreFiles() { - // keeping same order as in SConstruct - execSetup(JSFiles::utils); - execSetup(JSFiles::db); - execSetup(JSFiles::mongo); - execSetup(JSFiles::mr); - execSetup(JSFiles::query); - execSetup(JSFiles::collection); - } + void execCoreFiles(); virtual bool execFile( const string& filename , bool printResult , bool reportError , bool assertOnError, int timeoutMs = 0 ); - virtual void injectNative( const char *field, NativeFunction func ) = 0; + virtual void injectNative( const char *field, NativeFunction func, void* data = 0 ) = 0; virtual void gc() = 0; -- cgit v1.2.3