MCPcopy Create free account
hub / github.com/NativeScript/android / SetTimer

Method SetTimer

test-app/runtime/src/main/cpp/Timers.cpp:224–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224void 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.

Callers

nothing calls this directly

Calls 9

ToMaybePositiveValueFunction · 0.85
now_msFunction · 0.85
GetReturnValueMethod · 0.80
addTaskMethod · 0.80
LengthMethod · 0.45
DataMethod · 0.45
ValueMethod · 0.45
SetMethod · 0.45
GetIsolateMethod · 0.45

Tested by

no test coverage detected