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

Merge branch 'master' of github.com:mongodb/mongo

This commit is contained in:
Eliot Horowitz 2009-11-22 22:05:59 -05:00
commit 893346a0ac
3 changed files with 22 additions and 1 deletions

View File

@ -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<External> field = Handle<External>::Cast(args.Data());
void* ptr = field->Value();
V8Scope* self = static_cast<V8Scope*>(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 ){

View File

@ -73,6 +73,8 @@ namespace mongo {
void _startCall();
static Handle< Value > nativeCallback( const Arguments &args );
static Handle< Value > loadCallback( const Arguments &args );
V8ScriptEngine * _engine;

View File

@ -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<v8::Object> o ){