| 222 | } |
| 223 | |
| 224 | void Timers::SetTimer(const v8::FunctionCallbackInfo<v8::Value> &args, bool repeatable) { |
| 225 | auto argLength = args.Length(); |
| 226 | auto extData = args.Data().As<External>(); |
| 227 | auto thiz = reinterpret_cast<Timers *>(extData->Value()); |
| 228 | int id = ++thiz->currentTimerId; |
| 229 | if (argLength >= 1) { |
| 230 | if (!args[0]->IsFunction()) { |
| 231 | args.GetReturnValue().Set(-1); |
| 232 | return; |
| 233 | } |
| 234 | auto handler = args[0].As<Function>(); |
| 235 | auto isolate = args.GetIsolate(); |
| 236 | auto ctx = isolate->GetCurrentContext(); |
| 237 | long timeout = 0; |
| 238 | if (argLength >= 2) { |
| 239 | timeout = (long) ToMaybePositiveValue(args[1], ctx); |
| 240 | if (timeout < 0) { |
| 241 | timeout = 0; |
| 242 | } |
| 243 | } |
| 244 | std::shared_ptr<std::vector<std::shared_ptr<Persistent<Value>>>> argArray; |
| 245 | if (argLength >= 3) { |
| 246 | auto otherArgLength = argLength - 2; |
| 247 | argArray = std::make_shared<std::vector<std::shared_ptr<Persistent<Value>>>>( |
| 248 | otherArgLength); |
| 249 | for (int i = 0; i < otherArgLength; i++) { |
| 250 | (*argArray)[i] = std::make_shared<Persistent<Value>>(isolate, args[i + 2]); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | |
| 255 | auto task = std::make_shared<TimerTask>(isolate, ctx, handler, timeout, repeatable, |
| 256 | argArray, id, now_ms()); |
| 257 | thiz->addTask(task); |
| 258 | } |
| 259 | args.GetReturnValue().Set(id); |
| 260 | |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * ALooper callback. |
nothing calls this directly
no test coverage detected