0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

fix passing data pointer for native functions with spidermonkey

This commit is contained in:
agirbal 2011-05-10 20:05:30 -07:00
parent 088f11a6d6
commit d47de50498
2 changed files with 9 additions and 3 deletions

View File

@ -527,7 +527,7 @@ namespace mongo {
// js function to run reduce on all keys // js function to run reduce on all keys
// redfunc = _scope->createFunction("for (var key in hashmap) { print('Key is ' + key); list = hashmap[key]; ret = reduce(key, list); print('Value is ' + ret); };"); // redfunc = _scope->createFunction("for (var key in hashmap) { print('Key is ' + key); list = hashmap[key]; ret = reduce(key, list); print('Value is ' + ret); };");
_reduceAll = _scope->createFunction("for (var key in _mrMap) { list = _mrMap[key]; if (list.length != 1) { ret = _reduce(key, list); _mrMap[key] = [ret]; }"); _reduceAll = _scope->createFunction("for (var key in _mrMap) { list = _mrMap[key]; if (list.length != 1) { ret = _reduce(key, list); _mrMap[key] = [ret]; } }");
_reduceAndFinalize = _scope->createFunction("for (var key in _mrMap) { list = _mrMap[key]; if (list.length == 1) { if (!_doFinal) {continue;} ret = list[0]; } else { ret = _reduce(key, list) }; if (_doFinal){ ret = _finalize(ret); } _mrMap[key] = ret; }"); _reduceAndFinalize = _scope->createFunction("for (var key in _mrMap) { list = _mrMap[key]; if (list.length == 1) { if (!_doFinal) {continue;} ret = list[0]; } else { ret = _reduce(key, list) }; if (_doFinal){ ret = _finalize(ret); } _mrMap[key] = ret; }");
_reduceAndFinalizeAndInsert = _scope->createFunction("for (var key in _mrMap) { list = _mrMap[key]; if (list.length == 1) { ret = list[0]; } else { ret = _reduce(key, list) }; if (_doFinal){ ret = _finalize(ret); } _insertToTemp({_id: key, value: ret}); }"); _reduceAndFinalizeAndInsert = _scope->createFunction("for (var key in _mrMap) { list = _mrMap[key]; if (list.length == 1) { ret = list[0]; } else { ret = _reduce(key, list) }; if (_doFinal){ ret = _finalize(ret); } _insertToTemp({_id: key, value: ret}); }");

View File

@ -921,6 +921,7 @@ namespace mongo {
Convertor c(cx); Convertor c(cx);
NativeFunction func = (NativeFunction)((long long)c.getNumber( obj , "x" ) ); NativeFunction func = (NativeFunction)((long long)c.getNumber( obj , "x" ) );
void* data = (void*)((long long)c.getNumber( obj , "y" ) );
assert( func ); assert( func );
BSONObj a; BSONObj a;
@ -935,7 +936,7 @@ namespace mongo {
BSONObj out; BSONObj out;
try { try {
out = func( a, 0 ); out = func( a, data );
} }
catch ( std::exception& e ) { catch ( std::exception& e ) {
JS_ReportError( cx , e.what() ); JS_ReportError( cx , e.what() );
@ -1529,7 +1530,12 @@ namespace mongo {
_convertor->setProperty( _global , (name + "_").c_str() , _convertor->toval( (double)(long long)func ) ); _convertor->setProperty( _global , (name + "_").c_str() , _convertor->toval( (double)(long long)func ) );
stringstream code; stringstream code;
code << field << "_" << " = { x : " << field << "_ }; "; if (data) {
_convertor->setProperty( _global , (name + "_data_").c_str() , _convertor->toval( (double)(long long)data ) );
code << field << "_" << " = { x : " << field << "_ , y: " << field << "_data_ }; ";
} else {
code << field << "_" << " = { x : " << field << "_ }; ";
}
code << field << " = function(){ return nativeHelper.apply( " << field << "_ , arguments ); }"; code << field << " = function(){ return nativeHelper.apply( " << field << "_ , arguments ); }";
exec( code.str() ); exec( code.str() );
} }