Skip to content

Commit

Permalink
SERVER-1840 make eval function construction logic in v8 more consiste…
Browse files Browse the repository at this point in the history
…nt with sm
  • Loading branch information
astaple committed Oct 4, 2010
1 parent 9d00c0c commit 92a5d51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions jstests/evale.js
Original file line number Diff line number Diff line change
@@ -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; } } )" );
2 changes: 2 additions & 0 deletions mongo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
932D855211AB912B002749FB /* find7.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = find7.js; sourceTree = "<group>"; };
932D855311AB912B002749FB /* fm4.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = fm4.js; sourceTree = "<group>"; };
932D855411AB912B002749FB /* geo_box1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = geo_box1.js; sourceTree = "<group>"; };
93386F98125A7BB4005E0172 /* evale.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = evale.js; sourceTree = "<group>"; };
933A4D130F55A68600145C4B /* authTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = authTest.cpp; sourceTree = "<group>"; };
933A4D150F55A68600145C4B /* clientTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clientTest.cpp; sourceTree = "<group>"; };
933A4D170F55A68600145C4B /* first.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = first.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -841,6 +842,7 @@
934BEB9A10DFFA9600178102 /* jstests */ = {
isa = PBXGroup;
children = (
93386F98125A7BB4005E0172 /* evale.js */,
936D5EC71251BA2A0015722C /* rename4.js */,
93B771FE124024A4007C8F0C /* evald.js */,
93B77135123F0BB2007C8F0C /* indexk.js */,
Expand Down
9 changes: 8 additions & 1 deletion scripting/engine_v8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ){
Expand Down

0 comments on commit 92a5d51

Please sign in to comment.