Esempio n. 1
0
 JSThreadConfig( const Arguments &args, bool newScope = false ) : started_(), done_(), newScope_( newScope ) {
     jsassert( args.Length() > 0, "need at least one argument" );
     jsassert( args[ 0 ]->IsFunction(), "first argument must be a function" );
     Local< v8::Function > f = v8::Function::Cast( *args[ 0 ] );
     f_ = Persistent< v8::Function >::New( f );
     for( int i = 1; i < args.Length(); ++i )
         args_.push_back( Persistent< Value >::New( args[ i ] ) );
 }
Esempio n. 2
0
    v8::Handle<v8::Value> ScopedThreadInject(V8Scope* scope, const v8::Arguments& args) {
        v8::HandleScope handle_scope;
        jsassert(args.Length() == 1, "threadInject takes exactly 1 argument");
        jsassert(args[0]->IsObject(), "threadInject needs to be passed a prototype");
        v8::Local<v8::Object> o = args[0]->ToObject();

        scope->injectV8Function("init", ScopedThreadInit, o);
        // inheritance takes care of other member functions

        return handle_scope.Close(v8::Handle<v8::Value>());
    }
Esempio n. 3
0
    Handle< Value > ScopedThreadInject( V8Scope* scope, const Arguments &args ) {
        jsassert( args.Length() == 1 , "threadInject takes exactly 1 argument" );
        jsassert( args[0]->IsObject() , "threadInject needs to be passed a prototype" );

        Local<v8::Object> o = args[0]->ToObject();

        scope->injectV8Function("init", ScopedThreadInit, o);
        // inheritance takes care of other member functions

        return v8::Undefined();
    }
Esempio n. 4
0
        JSThreadConfig( V8Scope* scope, const Arguments &args, bool newScope = false ) : started_(), done_(), newScope_( newScope ) {
            jsassert( args.Length() > 0, "need at least one argument" );
            jsassert( args[ 0 ]->IsFunction(), "first argument must be a function" );

            // arguments need to be copied into the isolate, go through bson
            BSONObjBuilder b;
            for( int i = 0; i < args.Length(); ++i ) {
                scope->v8ToMongoElement(b, "arg" + i, args[i]);
            }
            args_ = b.obj();
        }
Esempio n. 5
0
 Handle< Value > ScopedThreadInject( const Arguments &args ) {
     jsassert( args.Length() == 1 , "threadInject takes exactly 1 argument" );
     jsassert( args[0]->IsObject() , "threadInject needs to be passed a prototype" );
     
     Local<v8::Object> o = args[0]->ToObject();
     
     o->Set( v8::String::New( "init" ) , FunctionTemplate::New( ScopedThreadInit )->GetFunction() );
     // inheritance takes care of other member functions
     
     return v8::Undefined();
 }
Esempio n. 6
0
    v8::Handle<v8::Value> ThreadInject(V8Scope* scope, const v8::Arguments& args) {
        v8::HandleScope handle_scope;
        jsassert(args.Length() == 1, "threadInject takes exactly 1 argument");
        jsassert(args[0]->IsObject(), "threadInject needs to be passed a prototype");
        v8::Local<v8::Object> o = args[0]->ToObject();

        // install method on the Thread object
        scope->injectV8Function("init", ThreadInit, o);
        scope->injectV8Function("start", ThreadStart, o);
        scope->injectV8Function("join", ThreadJoin, o);
        scope->injectV8Function("returnData", ThreadReturnData, o);
        return handle_scope.Close(v8::Handle<v8::Value>());
    }
Esempio n. 7
0
 Handle< Value > ThreadInject( const Arguments &args ) {
     jsassert( args.Length() == 1 , "threadInject takes exactly 1 argument" );
     jsassert( args[0]->IsObject() , "threadInject needs to be passed a prototype" );
     
     Local<v8::Object> o = args[0]->ToObject();
     
     o->Set( v8::String::New( "init" ) , FunctionTemplate::New( ThreadInit )->GetFunction() );
     o->Set( v8::String::New( "start" ) , FunctionTemplate::New( ThreadStart )->GetFunction() );
     o->Set( v8::String::New( "join" ) , FunctionTemplate::New( ThreadJoin )->GetFunction() );
     o->Set( v8::String::New( "returnData" ) , FunctionTemplate::New( ThreadReturnData )->GetFunction() );
     
     return v8::Undefined();    
 }
Esempio n. 8
0
        JSThreadConfig(V8Scope* scope, const v8::Arguments& args, bool newScope = false) :
            _started(),
            _done(),
            _newScope(newScope) {
            jsassert(args.Length() > 0, "need at least one argument");
            jsassert(args[0]->IsFunction(), "first argument must be a function");

            // arguments need to be copied into the isolate, go through bson
            BSONObjBuilder b;
            for(int i = 0; i < args.Length(); ++i) {
                scope->v8ToMongoElement(b, mongoutils::str::stream() << "arg" << i, args[i]);
            }
            _args = b.obj();
        }
Esempio n. 9
0
        JSThreadConfig(V8Scope* scope, const v8::FunctionCallbackInfo<v8::Value>& args,
                       bool newScope = false) :
            _started(),
            _done(),
            _newScope(newScope) {
            jsassert(args.Length() > 0, "need at least one argument");
            jsassert(args[0]->IsFunction(), "first argument must be a function");

            // arguments need to be copied into the isolate, go through bson
            BSONObjBuilder b;
            for(int i = 0; i < args.Length(); ++i) {
                scope->v8ToMongoElement(b, "arg" + BSONObjBuilder::numStr(i), args[i]);
            }
            _args = b.obj();
        }
Esempio n. 10
0
        void start() {
            jsassert( !started_, "Thread already started" );
            // obtain own scope for execution
            // do it here, not in constructor, otherwise it creates an infinite recursion from ScopedThread
            _scope.reset( dynamic_cast< V8Scope * >( globalScriptEngine->newScope() ) );

            JSThread jt( *this );
            thread_.reset( new boost::thread( jt ) );
            started_ = true;
        }
Esempio n. 11
0
 void join() {
     jsassert(_started && !_done, "Thread not running");
     _thread->join();
     _done = true;
 }
Esempio n. 12
0
 void start() {
     jsassert(!_started, "Thread already started");
     JSThread jt(*this);
     _thread.reset(new boost::thread(jt));
     _started = true;
 }
Esempio n. 13
0
 void join() {
     jsassert( started_ && !done_, "Thread not running" );
     thread_->join();
     done_ = true;
 }
Esempio n. 14
0
 void start() {
     jsassert( !started_, "Thread already started" );
     JSThread jt( *this );
     thread_.reset( new boost::thread( jt ) );
     started_ = true;
 }