diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-08-28 15:06:09 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-08-28 15:06:09 -0400 |
commit | 5f898ab0007fa6379a6e328d20a5eed481798fbf (patch) | |
tree | bb68896633d81c5c9dc8f0de22052272fec575f8 /scripting | |
parent | 7245d462e9c588ba722a92540645b431a11c3936 (diff) | |
download | mongo-5f898ab0007fa6379a6e328d20a5eed481798fbf.tar.gz |
fix function rooting and function names
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/engine_spidermonkey.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index cbbf1f13fcc..666b690a570 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -329,8 +329,12 @@ namespace mongo { size_t start = code.find( '(' ); assert( start != string::npos ); - string fname = code.substr( 9 , start - 9 ); + stringstream fname; + fname << trim( code.substr( 9 , start - 9 ) ); + static int fnum = 1; + fname << "_" << fnum++; + code = code.substr( start + 1 ); size_t end = code.find( ')' ); assert( end != string::npos ); @@ -354,7 +358,7 @@ namespace mongo { for ( size_t i=0; i<params.size(); i++ ) paramArray[i] = params[i].c_str(); - JSFunction * func = JS_CompileFunction( _context , assoc , "anonymous" , params.size() , paramArray , code.c_str() , strlen( code.c_str() ) , "nofile_b" , 0 ); + JSFunction * func = JS_CompileFunction( _context , assoc , fname.str().c_str() , params.size() , paramArray , code.c_str() , strlen( code.c_str() ) , "nofile_b" , 0 ); delete paramArray; if ( ! func ){ cerr << "compile failed for: " << raw << endl; @@ -1090,7 +1094,6 @@ namespace mongo { JS_RemoveRoot( _context , &_this ); _this = _convertor->toJSObject( obj ); - JS_AddNamedRoot( _context , &_this , "scope this" ); } @@ -1348,8 +1351,10 @@ namespace mongo { SMScope * scope = currentScope.get(); uassert( "need a scope" , scope ); + + JSObject * o = JS_GetFunctionObject( f ); - scope->addRoot( f , "cf" ); + scope->addRoot( &o , "cf" ); } } |