diff --git a/jstests/evale.js b/jstests/evale.js new file mode 100644 index 00000000000..af5a303f167 --- /dev/null +++ b/jstests/evale.js @@ -0,0 +1,5 @@ +t = db.jstests_evale; +t.drop(); + +db.eval( function() { return db.jstests_evale.count( { $where:function() { return true; } } ) } ); +db.eval( "db.jstests_evale.count( { $where:function() { return true; } } )" ); \ No newline at end of file diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index e4f2896729e..bc152affc56 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ 932D855211AB912B002749FB /* find7.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = find7.js; sourceTree = ""; }; 932D855311AB912B002749FB /* fm4.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = fm4.js; sourceTree = ""; }; 932D855411AB912B002749FB /* geo_box1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = geo_box1.js; sourceTree = ""; }; + 93386F98125A7BB4005E0172 /* evale.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = evale.js; sourceTree = ""; }; 933A4D130F55A68600145C4B /* authTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = authTest.cpp; sourceTree = ""; }; 933A4D150F55A68600145C4B /* clientTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clientTest.cpp; sourceTree = ""; }; 933A4D170F55A68600145C4B /* first.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = first.cpp; sourceTree = ""; }; @@ -841,6 +842,7 @@ 934BEB9A10DFFA9600178102 /* jstests */ = { isa = PBXGroup; children = ( + 93386F98125A7BB4005E0172 /* evale.js */, 936D5EC71251BA2A0015722C /* rename4.js */, 93B771FE124024A4007C8F0C /* evald.js */, 93B77135123F0BB2007C8F0C /* indexk.js */, diff --git a/scripting/engine_v8.cpp b/scripting/engine_v8.cpp index 92312008af4..b883a45ca42 100644 --- a/scripting/engine_v8.cpp +++ b/scripting/engine_v8.cpp @@ -250,10 +250,17 @@ namespace mongo { // --- functions ----- + bool hasFunctionIdentifier( const string& code ){ + if ( code.size() < 9 || code.find( "function" ) != 0 ) + return false; + + return code[8] == ' ' || code[8] == '('; + } + Local< v8::Function > V8Scope::__createFunction( const char * raw ){ for(; isspace( *raw ); ++raw ); // skip whitespace string code = raw; - if ( code.find( "function" ) == string::npos ){ + if ( !hasFunctionIdentifier( code ) ) { if ( code.find( "\n" ) == string::npos && ! hasJSReturn( code ) && ( code.find( ";" ) == string::npos || code.find( ";" ) == code.size() - 1 ) ){