Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

handle broken eval scripts correctly

  • Loading branch information...
commit 7155f7aa558dd6241179a5d3aff6200d1836ec7f 1 parent fe54a96
@erh erh authored
View
2  db/dbeval.cpp
@@ -63,7 +63,7 @@ namespace mongo {
ScriptingFunction f = s->createFunction(code);
if ( f == 0 ) {
- errmsg = "compile failed";
+ errmsg = (string)"compile failed: " + s->getError();
return false;
}
View
3  jstests/eval7.js
@@ -0,0 +1,3 @@
+
+assert.eq( 6 , db.eval( "5 + 1" ) , "A" )
+assert.throws( function(z){ db.eval( "5 + function x; + 1" )} );
View
24 scripting/engine_spidermonkey.cpp
@@ -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 ){
Please sign in to comment.
Something went wrong with that request. Please try again.