mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
- Added option for read only objects in JS invoke method
- map function uses RO input object which speeds up MR quite a bit - added a flag in RO objects so that the BSON can be used as is when converting back
This commit is contained in:
parent
559f103ea0
commit
5cc563b581
@ -69,7 +69,7 @@ namespace mongo {
|
||||
void JSMapper::map( const BSONObj& o ) {
|
||||
Scope * s = _func.scope();
|
||||
assert( s );
|
||||
if ( s->invoke( _func.func() , &_params, &o , 0 , true ) )
|
||||
if ( s->invoke( _func.func() , &_params, &o , 0 , true, false, true ) )
|
||||
throw UserException( 9014, str::stream() << "map invoke failed: " + s->getError() );
|
||||
}
|
||||
|
||||
|
@ -417,7 +417,7 @@ namespace mongo {
|
||||
/**
|
||||
* @return 0 on success
|
||||
*/
|
||||
int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs , bool ignoreReturn ) {
|
||||
int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs , bool ignoreReturn, bool readOnlyArgs, bool readOnlyRecv ) {
|
||||
return _real->invoke( func , args , recv, timeoutMs , ignoreReturn );
|
||||
}
|
||||
|
||||
|
@ -85,9 +85,9 @@ namespace mongo {
|
||||
/**
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 , bool ignoreReturn = false ) = 0;
|
||||
void invokeSafe( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 ) {
|
||||
int res = invoke( func , args , recv, timeoutMs );
|
||||
virtual int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 , bool ignoreReturn = false, bool readOnlyArgs = false, bool readOnlyRecv = false ) = 0;
|
||||
void invokeSafe( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0, bool readOnlyArgs = false, bool readOnlyRecv = false ) {
|
||||
int res = invoke( func , args , recv, timeoutMs, readOnlyArgs, readOnlyRecv );
|
||||
if ( res == 0 )
|
||||
return;
|
||||
throw UserException( 9004 , (string)"invoke failed: " + getError() );
|
||||
|
@ -281,6 +281,7 @@ namespace mongo {
|
||||
V8STR_NATIVE_FUNC = getV8Str( "_native_function" );
|
||||
V8STR_NATIVE_DATA = getV8Str( "_native_data" );
|
||||
V8STR_V8_FUNC = getV8Str( "_v8_function" );
|
||||
V8STR_RO = getV8Str( "_v8_ro" );
|
||||
|
||||
injectV8Function("print", Print);
|
||||
injectV8Function("version", Version);
|
||||
@ -598,7 +599,7 @@ namespace mongo {
|
||||
_global->Set( f , v8::Undefined() );
|
||||
}
|
||||
|
||||
int V8Scope::invoke( ScriptingFunction func , const BSONObj* argsObject, const BSONObj* recv, int timeoutMs , bool ignoreReturn ) {
|
||||
int V8Scope::invoke( ScriptingFunction func , const BSONObj* argsObject, const BSONObj* recv, int timeoutMs , bool ignoreReturn, bool readOnlyArgs, bool readOnlyRecv ) {
|
||||
V8_SIMPLE_HEADER
|
||||
Handle<Value> funcValue = _funcs[func-1];
|
||||
|
||||
@ -610,9 +611,9 @@ namespace mongo {
|
||||
BSONObjIterator it( *argsObject );
|
||||
for ( int i=0; i<nargs; i++ ) {
|
||||
BSONElement next = it.next();
|
||||
args[i] = mongoToV8Element( next );
|
||||
args[i] = mongoToV8Element( next, readOnlyArgs );
|
||||
}
|
||||
setObject( "args", *argsObject, false); // for backwards compatibility
|
||||
setObject( "args", *argsObject, readOnlyArgs); // for backwards compatibility
|
||||
}
|
||||
else {
|
||||
_global->Set( V8STR_ARGS, v8::Undefined() );
|
||||
@ -626,7 +627,7 @@ namespace mongo {
|
||||
}
|
||||
Handle<v8::Object> v8recv;
|
||||
if (recv != 0)
|
||||
v8recv = mongoToLZV8(*recv, false);
|
||||
v8recv = mongoToLZV8(*recv, false, readOnlyRecv);
|
||||
else
|
||||
v8recv = _emptyObj;
|
||||
|
||||
@ -1047,6 +1048,7 @@ namespace mongo {
|
||||
|
||||
if (readOnly) {
|
||||
o = roObjectTemplate->NewInstance();
|
||||
o->SetHiddenValue(V8STR_RO, v8::Undefined());
|
||||
} else {
|
||||
if (array) {
|
||||
o = lzArrayTemplate->NewInstance();
|
||||
@ -1351,6 +1353,14 @@ namespace mongo {
|
||||
}
|
||||
|
||||
BSONObj V8Scope::v8ToMongo( v8::Handle<v8::Object> o , int depth ) {
|
||||
if ( !o->GetHiddenValue( V8STR_RO ).IsEmpty() ) {
|
||||
// object was readonly, use bson as is
|
||||
BSONObj* ro = unwrapBSONObj(o);
|
||||
if (ro)
|
||||
return *ro;
|
||||
return BSONObj();
|
||||
}
|
||||
|
||||
BSONObjBuilder b;
|
||||
|
||||
if ( depth == 0 ) {
|
||||
|
@ -92,7 +92,7 @@ namespace mongo {
|
||||
|
||||
virtual ScriptingFunction _createFunction( const char * code );
|
||||
Local< v8::Function > __createFunction( const char * code );
|
||||
virtual int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 , bool ignoreReturn = false );
|
||||
virtual int invoke( ScriptingFunction func , const BSONObj* args, const BSONObj* recv, int timeoutMs = 0 , bool ignoreReturn = false, bool readOnlyArgs = false, bool readOnlyRecv = false );
|
||||
virtual bool exec( const StringData& code , const string& name , bool printResult , bool reportError , bool assertOnError, int timeoutMs );
|
||||
virtual string getError() { return _error; }
|
||||
|
||||
@ -142,6 +142,7 @@ namespace mongo {
|
||||
Handle<v8::String> V8STR_DBPTR;
|
||||
Handle<v8::String> V8STR_BINDATA;
|
||||
Handle<v8::String> V8STR_WRAPPER;
|
||||
Handle<v8::String> V8STR_RO;
|
||||
|
||||
private:
|
||||
void _startCall();
|
||||
|
Loading…
Reference in New Issue
Block a user