Skip to content

Commit 4dc88de

Browse files
Daniel Ballayichoi
authored andcommitted
Add a more secure type validator to Timer module based on #911 (#976)
IoT.js-DCO-1.0-Signed-off-by: Daniel Balla [email protected]
1 parent 37db06d commit 4dc88de

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/modules/iotjs_module_timer.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
static void iotjs_timerwrap_destroy(iotjs_timerwrap_t* timerwrap);
2121
static void iotjs_timerwrap_on_timeout(iotjs_timerwrap_t* timerwrap);
22-
IOTJS_DEFINE_NATIVE_HANDLE_INFO(timerwrap);
22+
IOTJS_DEFINE_NATIVE_HANDLE_INFO_THIS_MODULE(timerwrap);
2323

2424

2525
iotjs_timerwrap_t* iotjs_timerwrap_create(const iotjs_jval_t* jtimer) {
@@ -28,7 +28,8 @@ iotjs_timerwrap_t* iotjs_timerwrap_create(const iotjs_jval_t* jtimer) {
2828
IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_timerwrap_t, timerwrap);
2929

3030
iotjs_handlewrap_initialize(&_this->handlewrap, jtimer,
31-
(uv_handle_t*)(uv_timer), &timerwrap_native_info);
31+
(uv_handle_t*)(uv_timer),
32+
&this_module_native_info);
3233

3334
// Initialize timer handler.
3435
const iotjs_environment_t* env = iotjs_environment_get();
@@ -124,14 +125,9 @@ iotjs_timerwrap_t* iotjs_timerwrap_from_jobject(const iotjs_jval_t* jtimer) {
124125

125126
JHANDLER_FUNCTION(Start) {
126127
// Check parameters.
127-
JHANDLER_CHECK_THIS(object);
128+
JHANDLER_DECLARE_THIS_PTR(timerwrap, timer_wrap);
128129
JHANDLER_CHECK_ARGS(2, number, number);
129130

130-
const iotjs_jval_t* jtimer = JHANDLER_GET_THIS(object);
131-
132-
// Take timer wrap.
133-
iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_from_jobject(jtimer);
134-
135131
// parameters.
136132
uint64_t timeout = JHANDLER_GET_ARG(0, number);
137133
uint64_t repeat = JHANDLER_GET_ARG(1, number);
@@ -144,12 +140,7 @@ JHANDLER_FUNCTION(Start) {
144140

145141

146142
JHANDLER_FUNCTION(Stop) {
147-
JHANDLER_CHECK_THIS(object);
148-
149-
const iotjs_jval_t* jtimer = JHANDLER_GET_THIS(object);
150-
151-
iotjs_timerwrap_t* timer_wrap = iotjs_timerwrap_from_jobject(jtimer);
152-
143+
JHANDLER_DECLARE_THIS_PTR(timerwrap, timer_wrap);
153144
// Stop timer.
154145
int res = iotjs_timerwrap_stop(timer_wrap);
155146

0 commit comments

Comments
 (0)