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 ] ) ); }
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>()); }
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(); }
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(); }
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(); }
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>()); }
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(); }
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(); }
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(); }
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; }
void join() { jsassert(_started && !_done, "Thread not running"); _thread->join(); _done = true; }
void start() { jsassert(!_started, "Thread already started"); JSThread jt(*this); _thread.reset(new boost::thread(jt)); _started = true; }
void join() { jsassert( started_ && !done_, "Thread not running" ); thread_->join(); done_ = true; }
void start() { jsassert( !started_, "Thread already started" ); JSThread jt( *this ); thread_.reset( new boost::thread( jt ) ); started_ = true; }