CodeWScope SERVER-80

This commit is contained in:
Eliot Horowitz
2009-06-01 12:53:24 -04:00
parent 812cf75ac1
commit d6811aaaad
2 changed files with 46 additions and 3 deletions

View File

@@ -258,13 +258,13 @@ namespace mongo {
return true;
}
JSFunction * compileFunction( const char * code ){
JSFunction * compileFunction( const char * code, JSObject * assoc = 0 ){
if ( ! hasFunctionIdentifier( code ) ){
string s = code;
if ( isSimpleStatement( s ) ){
s = "return " + s;
}
return JS_CompileFunction( _context , 0 , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile_a" , 0 );
return JS_CompileFunction( _context , assoc , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile_a" , 0 );
}
// TODO: there must be a way in spider monkey to do this - this is a total hack
@@ -273,7 +273,7 @@ namespace mongo {
s += code;
s += ";";
JSFunction * func = JS_CompileFunction( _context , 0 , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile_b" , 0 );
JSFunction * func = JS_CompileFunction( _context , assoc , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile_b" , 0 );
if ( ! func ){
cerr << "compile for hack failed" << endl;
return 0;
@@ -383,6 +383,16 @@ namespace mongo {
JSFunction * func = compileFunction( e.valuestr() );
return OBJECT_TO_JSVAL( JS_GetFunctionObject( func ) );
}
case CodeWScope:{
JSFunction * func = compileFunction( e.codeWScopeCode() );
BSONObj extraScope = e.codeWScopeObject();
if ( ! extraScope.isEmpty() ){
log() << "warning: CodeWScope doesn't transfer to db.eval" << endl;
}
return OBJECT_TO_JSVAL( JS_GetFunctionObject( func ) );
}
case Date:
return OBJECT_TO_JSVAL( js_NewDateObjectMsec( _context , (jsdouble) e.date() ) );