summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-09-01 01:32:04 -0400
committerEliot Horowitz <eliot@10gen.com>2010-09-01 01:32:35 -0400
commitb416e09061258dcb0af8ab30147b0eb0dcb0cbf1 (patch)
tree48aef2ffc076ef1863c95c1984b4c9ec9f9e2bd6 /scripting
parenta6e3b04263d32885d4462d4b34c7f77badef820e (diff)
downloadmongo-b416e09061258dcb0af8ab30147b0eb0dcb0cbf1.tar.gz
Scope::rename and ability to block db access prep for SERVER-1715
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine.cpp4
-rw-r--r--scripting/engine.h18
-rw-r--r--scripting/engine_spidermonkey.cpp9
-rw-r--r--scripting/engine_v8.cpp8
-rw-r--r--scripting/engine_v8.h2
5 files changed, 40 insertions, 1 deletions
diff --git a/scripting/engine.cpp b/scripting/engine.cpp
index 91f386f0ca4..4367b758d98 100644
--- a/scripting/engine.cpp
+++ b/scripting/engine.cpp
@@ -385,6 +385,10 @@ namespace mongo {
return _real->createFunction( code );
}
+ void rename( const char * from , const char * to ){
+ _real->rename( from , to );
+ }
+
/**
* @return 0 on success
*/
diff --git a/scripting/engine.h b/scripting/engine.h
index 046f1778148..995b527e0a8 100644
--- a/scripting/engine.h
+++ b/scripting/engine.h
@@ -54,7 +54,22 @@ namespace mongo {
virtual void localConnect( const char * dbName ) = 0;
virtual void externalSetup() = 0;
-
+
+ class NoDBAccess {
+ Scope * _s;
+ public:
+ NoDBAccess( Scope * s ){
+ _s = s;
+ }
+ ~NoDBAccess(){
+ _s->rename( "____db____" , "db" );
+ }
+ };
+ NoDBAccess disableDBAccess( const char * why ){
+ rename( "db" , "____db____" );
+ return NoDBAccess( this );
+ }
+
virtual double getNumber( const char *field ) = 0;
virtual int getNumberInt( const char *field ){ return (int)getNumber( field ); }
virtual long long getNumberLongLong( const char *field ){ return (long long)getNumber( field ); }
@@ -75,6 +90,7 @@ namespace mongo {
virtual ScriptingFunction createFunction( const char * code );
+ virtual void rename( const char * from , const char * to ) = 0;
/**
* @return 0 on success
*/
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index cb3ad2092a3..8952b339702 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -1323,6 +1323,15 @@ namespace mongo {
}
}
+ void rename( const char * from , const char * to ){
+ smlock;
+ jsval v;
+ assert( JS_GetProperty( _context , _global , from , &v ) );
+ assert( JS_SetProperty( _context , _global , to , &v ) );
+ v = JSVAL_VOID;
+ assert( JS_SetProperty( _context , _global , from , &v ) );
+ }
+
// ---- functions -----
ScriptingFunction _createFunction( const char * code ){
diff --git a/scripting/engine_v8.cpp b/scripting/engine_v8.cpp
index 99da4a3309e..38b78aa748d 100644
--- a/scripting/engine_v8.cpp
+++ b/scripting/engine_v8.cpp
@@ -296,6 +296,14 @@ namespace mongo {
argv[0] = v8::External::New( createWrapperHolder( obj , true , false ) );
_this = Persistent< v8::Object >::New( _wrapper->NewInstance( 1, argv ) );
}
+
+ void V8Scope::rename( const char * from , const char * to ){
+ V8_SIMPLE_HEADER;
+ v8::Local<v8::String> f = v8::String::New( from );
+ v8::Local<v8::String> t = v8::String::New( to );
+ _global->Set( t , _global->Get( f ) );
+ _global->Set( f , v8::Undefined() );
+ }
int V8Scope::invoke( ScriptingFunction func , const BSONObj& argsObject, int timeoutMs , bool ignoreReturn ){
V8_SIMPLE_HEADER
diff --git a/scripting/engine_v8.h b/scripting/engine_v8.h
index f9689b68926..ca44f4843b8 100644
--- a/scripting/engine_v8.h
+++ b/scripting/engine_v8.h
@@ -55,6 +55,8 @@ namespace mongo {
virtual void setElement( const char *field , const BSONElement& e );
virtual void setObject( const char *field , const BSONObj& obj , bool readOnly);
virtual void setThis( const BSONObj * obj );
+
+ virtual void rename( const char * from , const char * to );
virtual ScriptingFunction _createFunction( const char * code );
Local< v8::Function > __createFunction( const char * code );