summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-10-12 11:30:43 -0400
committerEliot Horowitz <eliot@10gen.com>2009-10-12 11:30:43 -0400
commit1410fa1b75aaca853b3b84073098e2de58f0cf95 (patch)
treea6b6f80c1c29269a67dd79d4b81e97824aa99ace /scripting
parent6c10cf4d98bbec63663547c97eff708017929f59 (diff)
downloadmongo-1410fa1b75aaca853b3b84073098e2de58f0cf95.tar.gz
v8: more tests pass
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine_v8.cpp18
-rw-r--r--scripting/engine_v8.h3
2 files changed, 17 insertions, 4 deletions
diff --git a/scripting/engine_v8.cpp b/scripting/engine_v8.cpp
index e270599e882..e85d563b158 100644
--- a/scripting/engine_v8.cpp
+++ b/scripting/engine_v8.cpp
@@ -82,16 +82,28 @@ namespace mongo {
_this = mongoToV8( *obj );
}
+ v8::Handle<v8::Value> V8Scope::get( const char * field ){
+ return _global->Get( v8::String::New( field ) );
+ }
+
double V8Scope::getNumber( const char *field ){
- return _global->Get( v8::String::New( field ) )->ToNumber()->Value();
+ return get( field )->ToNumber()->Value();
}
string V8Scope::getString( const char *field ){
- return toSTLString( _global->Get( v8::String::New( field ) ) );
+ return toSTLString( get( field ) );
}
bool V8Scope::getBoolean( const char *field ){
- return _global->Get( v8::String::New( field ) )->ToBoolean()->Value();
+ return get( field )->ToBoolean()->Value();
+ }
+
+ BSONObj V8Scope::getObject( const char * field ){
+ Handle<Value> v = get( field );
+ if ( v->IsNull() || v->IsUndefined() )
+ return BSONObj();
+ uassert( "not an object" , v->IsObject() );
+ return v8ToMongo( v->ToObject() );
}
ScriptingFunction V8Scope::_createFunction( const char * raw ){
diff --git a/scripting/engine_v8.h b/scripting/engine_v8.h
index e0df6bcf3e9..ade97b777be 100644
--- a/scripting/engine_v8.h
+++ b/scripting/engine_v8.h
@@ -22,10 +22,11 @@ namespace mongo {
virtual void localConnect( const char * dbName ){ assert(0); }
virtual void externalSetup(){ assert(0); };
+ v8::Handle<v8::Value> get( const char * field );
virtual double getNumber( const char *field );
virtual string getString( const char *field );
virtual bool getBoolean( const char *field );
- virtual BSONObj getObject( const char *field ){ assert( false ); return BSONObj(); }
+ virtual BSONObj getObject( const char *field );
virtual int type( const char *field ){ assert( false ); return 0; }