diff --git a/scripting/engine_v8.cpp b/scripting/engine_v8.cpp index 064daf54988..cfc86f5d507 100644 --- a/scripting/engine_v8.cpp +++ b/scripting/engine_v8.cpp @@ -60,6 +60,9 @@ namespace mongo { _global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print)->GetFunction() ); _global->Set(v8::String::New("version"), v8::FunctionTemplate::New(Version)->GetFunction() ); + _global->Set(v8::String::New("load") + ,v8::FunctionTemplate::New(loadCallback, v8::External::New(this))->GetFunction() ); + //_externalTemplate = getMongoFunctionTemplate( false ); //_localTemplate = getMongoFunctionTemplate( true ); @@ -92,6 +95,22 @@ namespace mongo { return mongoToV8Element( ret.firstElement() ); } + Handle< Value > V8Scope::loadCallback( const Arguments &args ) { + HandleScope scope; + Handle field = Handle::Cast(args.Data()); + void* ptr = field->Value(); + V8Scope* self = static_cast(ptr); + + Context::Scope context_scope(self->_context); + for (int i = 0; i < args.Length(); ++i) { + std::string filename(toSTLString(args[i])); + if (!self->execFile(filename, false , true , false)) { + return v8::ThrowException(v8::String::New((std::string("error loading file: ") + filename).c_str())); + } + } + return v8::True(); + } + // ---- global stuff ---- void V8Scope::init( BSONObj * data ){ diff --git a/scripting/engine_v8.h b/scripting/engine_v8.h index a26c354413e..2e784aa77ab 100644 --- a/scripting/engine_v8.h +++ b/scripting/engine_v8.h @@ -73,6 +73,8 @@ namespace mongo { void _startCall(); static Handle< Value > nativeCallback( const Arguments &args ); + + static Handle< Value > loadCallback( const Arguments &args ); V8ScriptEngine * _engine; diff --git a/scripting/v8_wrapper.cpp b/scripting/v8_wrapper.cpp index bce4461a0ce..2f319a4ae69 100644 --- a/scripting/v8_wrapper.cpp +++ b/scripting/v8_wrapper.cpp @@ -293,7 +293,7 @@ namespace mongo { return; } - cout << "don't know how to covert to mongo field [" << name << "]\t" << value << endl; + cout << "don't know how to convert to mongo field [" << name << "]\t" << value << endl; } BSONObj v8ToMongo( v8::Handle o ){