0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00
mongodb/scripting/engine_v8.h

62 lines
2.3 KiB
C
Raw Normal View History

2009-05-04 17:49:18 +02:00
#pragma once
#include "engine.h"
#include <v8.h>
using namespace v8;
2009-05-04 17:49:18 +02:00
namespace mongo {
class V8Scope : public Scope {
public:
virtual void reset() {}
virtual void init( BSONObj * data ) {}
virtual void localConnect( const char * dbName ) {}
virtual double getNumber( const char *field ) { assert( false ); return 0; }
virtual string getString( const char *field ) { assert( false ); return ""; }
virtual bool getBoolean( const char *field ) { assert( false ); return false; }
virtual BSONObj getObject( const char *field ) { assert( false ); return BSONObj(); }
virtual int type( const char *field ) { assert( false ); return 0; }
2009-05-10 04:18:32 +02:00
virtual void setNumber( const char *field , double val ) { assert(0); }
virtual void setString( const char *field , const char * val ) { assert(0); }
virtual void setObject( const char *field , const BSONObj& obj , bool readOnly) { assert(0); }
virtual void setBoolean( const char *field , bool val ) { assert(0); }
virtual void setThis( const BSONObj * obj ) { assert(0); }
2009-05-04 17:49:18 +02:00
virtual ScriptingFunction createFunction( const char * code ) { assert( false ); return 0; }
virtual int invoke( ScriptingFunction func , const BSONObj& args ) { assert( false ); return 0; }
virtual string getError() { assert( false ); return ""; }
virtual void injectNative( const char *field, NativeFunction func ) {
Handle< FunctionTemplate > f( v8::FunctionTemplate::New( nativeCallback ) );
f->Set( v8::String::New( "_native_function" ), External::New( (void*)func ) );
global_->Set( v8::String::New( field ), f );
}
void setGlobal( const Handle< v8::ObjectTemplate > &global ) {
global_ = global;
}
private:
static Handle< Value > nativeCallback( const Arguments &args );
Handle< v8::ObjectTemplate > global_;
2009-05-04 17:49:18 +02:00
};
class V8ScriptEngine : public ScriptEngine {
public:
V8ScriptEngine() {}
virtual ~V8ScriptEngine() {}
virtual Scope * createScope() { return new V8Scope(); }
virtual void runTest() {}
};
extern ScriptEngine * globalScriptEngine;
}