Changeset 16102 for trunk/FACT++/src
- Timestamp:
- 05/24/13 13:36:21 (11 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r16095 r16102 141 141 return ThrowException(String::New("Argument 1 not a function.")); 142 142 143 if (args.Length()>2 && !args[2]->IsObject()) 144 return ThrowException(String::New("Argument 2 not an object.")); 145 143 146 const int32_t timeout = args[0]->IsNull() ? 0 : args[0]->Int32Value(); 144 147 const bool null = args[0]->IsNull(); … … 148 151 Handle<Function> func = Handle<Function>::Cast(args[1]); 149 152 150 Handle<Value> argv[args.Length()-2]; 151 for (int i=0; i<args.Length()-2; i++) 152 argv[i] = args[i+2]; 153 const int nn = args.Length()==2 ? 0 : args.Length()-3; 154 155 Handle<Value> argv[nn]; 156 for (int i=0; i<nn; i++) 157 argv[i] = args[i+3]; 153 158 154 159 Time t; 155 160 while (1) 156 161 { 157 const Handle<Value> rc = func->Call(func, args.Length()-2, argv);162 const Handle<Value> rc = args.Length()<3 ? func->Call(func, nn, argv) : func->Call(args[2]->ToObject(), nn, argv); 158 163 if (rc.IsEmpty()) 159 164 return Undefined(); … … 179 184 } 180 185 181 void InterpreterV8::Thread(int &id, Persistent< Function> func, uint32_t ms)186 void InterpreterV8::Thread(int &id, Persistent<Object> _this, Persistent<Function> func, uint32_t ms) 182 187 { 183 188 const Locker lock; … … 206 211 const bool rc = ms==0 || !ExecuteInternal("v8.sleep("+to_string(ms)+");").IsEmpty(); 207 212 if (rc) 208 func->Call(func, 0, NULL); 213 { 214 if (_this.IsEmpty()) 215 func->Call(func, 0, NULL); 216 else 217 func->Call(_this, 0, NULL); 218 } 209 219 210 220 func.Dispose(); 221 _this.Dispose(); 222 211 223 fThreadIds.erase(id_local); 212 224 … … 220 232 return ThrowException(String::New("Thread must be called as constructor.")); 221 233 222 if (args.Length()!=2 )223 return ThrowException(String::New("Number of arguments must be two ."));234 if (args.Length()!=2 && args.Length()!=3) 235 return ThrowException(String::New("Number of arguments must be two or three.")); 224 236 225 237 if (!args[0]->IsUint32()) … … 229 241 return ThrowException(String::New("Argument 1 not a function.")); 230 242 243 if (args.Length()==3 && !args[2]->IsObject()) 244 return ThrowException(String::New("Argument 2 not an object.")); 245 231 246 //if (!args.IsConstructCall()) 232 247 // return Constructor(args); … … 236 251 Handle<Function> handle = Handle<Function>::Cast(args[1]); 237 252 238 Persistent<Function> func = Persistent<Function>::New(handle); 253 Persistent<Function> func = Persistent<Function>::New(handle); 254 Persistent<Object> _this; 255 if (args.Length()==3) 256 _this = Persistent<Object>::New(args[2]->ToObject()); 239 257 240 258 const uint32_t ms = args[0]->Uint32Value(); 241 259 242 260 int id=-2; 243 fThreads.push_back(thread(bind(&InterpreterV8::Thread, this, ref(id), func, ms)));261 fThreads.push_back(thread(bind(&InterpreterV8::Thread, this, ref(id), _this, func, ms))); 244 262 { 245 263 // Allow the thread to lock, so we can get the thread id. -
trunk/FACT++/src/InterpreterV8.h
r16071 r16102 65 65 v8::Handle<v8::Value> ExecuteInternal(const std::string &code); 66 66 67 void Thread(int &id, v8::Persistent<v8:: Function> func, uint32_t ms);67 void Thread(int &id, v8::Persistent<v8::Object> _this, v8::Persistent<v8::Function> func, uint32_t ms); 68 68 69 69 std::vector<std::string> ValueToArray(const v8::Handle<v8::Value> &val, bool only=true);
Note:
See TracChangeset
for help on using the changeset viewer.