Skip to content

Commit 3a1a45b

Browse files
knightburtonyichoi
authored andcommitted
Add a more secure type validator to UART module based on #911 (#990)
IoT.js-DCO-1.0-Signed-off-by: Imre Kiss [email protected]
1 parent 8943ad0 commit 3a1a45b

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

src/modules/iotjs_module_uart.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,21 @@
2020
#include "iotjs_objectwrap.h"
2121

2222

23-
static void iotjs_uart_destroy(iotjs_uart_t* uart);
2423
static iotjs_uart_t* iotjs_uart_instance_from_jval(const iotjs_jval_t* juart);
25-
IOTJS_DEFINE_NATIVE_HANDLE_INFO(uart);
26-
24+
IOTJS_DEFINE_NATIVE_HANDLE_INFO_THIS_MODULE(uart);
2725

2826
static iotjs_uart_t* iotjs_uart_create(const iotjs_jval_t* juart) {
2927
iotjs_uart_t* uart = IOTJS_ALLOC(iotjs_uart_t);
3028
IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_uart_t, uart);
31-
iotjs_jobjectwrap_initialize(&_this->jobjectwrap, juart, &uart_native_info);
29+
iotjs_jobjectwrap_initialize(&_this->jobjectwrap, juart,
30+
&this_module_native_info);
3231

3332
_this->device_fd = -1;
3433

3534
return uart;
3635
}
3736

3837

39-
static void iotjs_uart_destroy(iotjs_uart_t* uart) {
40-
IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_uart_t, uart);
41-
iotjs_jobjectwrap_destroy(&_this->jobjectwrap);
42-
iotjs_string_destroy(&_this->device_path);
43-
IOTJS_RELEASE(uart);
44-
}
45-
46-
4738
#define THIS iotjs_uart_reqwrap_t* uart_reqwrap
4839

4940

@@ -292,13 +283,11 @@ JHANDLER_FUNCTION(UartConstructor) {
292283

293284

294285
JHANDLER_FUNCTION(Write) {
295-
DJHANDLER_CHECK_THIS(object);
286+
JHANDLER_DECLARE_THIS_PTR(uart, uart);
296287
DJHANDLER_CHECK_ARGS(1, string);
297288
DJHANDLER_CHECK_ARG_IF_EXIST(1, function);
298289

299290
const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(1, function);
300-
const iotjs_jval_t* juart = JHANDLER_GET_THIS(object);
301-
iotjs_uart_t* uart = iotjs_uart_instance_from_jval(juart);
302291

303292
IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
304293

@@ -322,12 +311,10 @@ JHANDLER_FUNCTION(Write) {
322311

323312

324313
JHANDLER_FUNCTION(Close) {
325-
DJHANDLER_CHECK_THIS(object);
314+
JHANDLER_DECLARE_THIS_PTR(uart, uart);
326315
DJHANDLER_CHECK_ARG_IF_EXIST(0, function);
327316

328317
const iotjs_jval_t* jcallback = JHANDLER_GET_ARG_IF_EXIST(0, function);
329-
const iotjs_jval_t* juart = JHANDLER_GET_THIS(object);
330-
iotjs_uart_t* uart = iotjs_uart_instance_from_jval(juart);
331318

332319
IOTJS_VALIDATED_STRUCT_METHOD(iotjs_uart_t, uart);
333320
iotjs_jval_destroy(&_this->jemitter_this);

0 commit comments

Comments
 (0)