handle broken eval scripts correctly

This commit is contained in:
Eliot Horowitz
2009-05-20 15:47:48 -04:00
parent fe54a96b59
commit 7155f7aa55
3 changed files with 22 additions and 7 deletions

View File

@@ -207,7 +207,7 @@ namespace mongo {
string s = code;
if ( strstr( code , "return" ) == 0 )
s = "return " + s;
return JS_CompileFunction( _context , 0 , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile" , 0 );
return JS_CompileFunction( _context , 0 , "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
@@ -216,9 +216,19 @@ namespace mongo {
s += code;
s += ";";
JSFunction * func = JS_CompileFunction( _context , 0 , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile" , 0 );
JSFunction * func = JS_CompileFunction( _context , 0 , "anonymous" , 0 , 0 , s.c_str() , strlen( s.c_str() ) , "nofile_b" , 0 );
if ( ! func ){
cerr << "compile for hack failed" << endl;
return 0;
}
jsval ret;
JS_CallFunction( _context , 0 , func , 0 , 0 , &ret );
if ( ! JS_CallFunction( _context , 0 , func , 0 , 0 , &ret ) ){
cerr << "call function for hack failed" << endl;
return 0;
}
uassert( "return for compile hack failed" , JS_TypeOfValue( _context , ret ) == JSTYPE_FUNCTION );
return JS_ValueToFunction( _context , ret );
}
@@ -738,6 +748,7 @@ namespace mongo {
// ---- functions -----
ScriptingFunction createFunction( const char * code ){
precall();
return (ScriptingFunction)_convertor->compileFunction( code );
}
@@ -875,9 +886,10 @@ namespace mongo {
}
log() << ss.str() << endl;
currentScope->gotError( ss.str() );
// TODO: send to Scope
if ( currentScope.get() ){
currentScope->gotError( ss.str() );
}
}
JSBool native_load( JSContext *cx , JSObject *obj , uintN argc, jsval *argv , jsval *rval ){