5
5
#include < android/looper.h>
6
6
#include < unistd.h>
7
7
#include < thread>
8
+ #include " ModuleBinding.h"
9
+ #include " IsolateDisposer.h"
10
+ #include " Util.h"
8
11
9
12
10
13
/* *
15
18
* ALL changes and scheduling of a TimerTask MUST be done when locked in an isolate to ensure consistency
16
19
*/
17
20
18
- using namespace tns ;
19
21
using namespace v8 ;
20
22
21
23
// Takes a value and transform into a positive number
@@ -43,22 +45,18 @@ static double now_ms() {
43
45
return 1000.0 * res.tv_sec + (double ) res.tv_nsec / 1e6 ;
44
46
}
45
47
48
+ namespace tns {
49
+
50
+
51
+
46
52
47
53
void Timers::Init (v8::Isolate *isolate, v8::Local<v8::ObjectTemplate> &globalObjectTemplate) {
48
54
isolate_ = isolate;
49
55
// TODO: remove the __ns__ prefix once this is validated
50
- globalObjectTemplate->Set (ArgConverter::ConvertToV8String (isolate, " __ns__setTimeout" ),
51
- FunctionTemplate::New (isolate, SetTimeoutCallback,
52
- External::New (isolate, this )));
53
- globalObjectTemplate->Set (ArgConverter::ConvertToV8String (isolate, " __ns__setInterval" ),
54
- FunctionTemplate::New (isolate, SetIntervalCallback,
55
- External::New (isolate, this )));
56
- globalObjectTemplate->Set (ArgConverter::ConvertToV8String (isolate, " __ns__clearTimeout" ),
57
- FunctionTemplate::New (isolate, ClearTimer,
58
- External::New (isolate, this )));
59
- globalObjectTemplate->Set (ArgConverter::ConvertToV8String (isolate, " __ns__clearInterval" ),
60
- FunctionTemplate::New (isolate, ClearTimer,
61
- External::New (isolate, this )));
56
+ SetMethod (isolate, globalObjectTemplate, " __ns__setTimeout" , SetTimeoutCallback, External::New (isolate, this ));
57
+ SetMethod (isolate, globalObjectTemplate, " __ns__setInterval" , SetIntervalCallback, External::New (isolate, this ));
58
+ SetMethod (isolate, globalObjectTemplate, " __ns__clearTimeout" , ClearTimer, External::New (isolate, this ));
59
+ SetMethod (isolate, globalObjectTemplate, " __ns__clearInterval" , ClearTimer, External::New (isolate, this ));
62
60
auto res = pipe (fd_);
63
61
assert (res != -1 );
64
62
res = fcntl (fd_[1 ], F_SETFL, O_NONBLOCK);
@@ -324,4 +322,14 @@ int Timers::PumpTimerLoopCallback(int fd, int events, void *data) {
324
322
}
325
323
thiz->bufferFull .notify_one ();
326
324
return 1 ;
327
- }
325
+ }
326
+
327
+ void Timers::InitStatic (v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalObjectTemplate) {
328
+ auto timers = new Timers ();
329
+ timers->Init (isolate, globalObjectTemplate);
330
+ registerIsolateBoundObject (isolate, timers);
331
+ }
332
+
333
+ };
334
+
335
+ NODE_BINDING_PER_ISOLATE_INIT_OBJ (timers, tns::Timers::InitStatic);
0 commit comments