Skip to content

Commit 88f8e98

Browse files
akosthekisshs0225
authored andcommitted
Unify the use of DJS_CHECK macros (#1899)
Almost all modules use the `DJS_CHECK_*` macros to check arguments of JS bindings. Almost, but not all: some still use the `JS_CHECK_*` variants. This commit makes all modules use the `D` versions. IoT.js-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
1 parent 134508f commit 88f8e98

File tree

7 files changed

+8
-6
lines changed

7 files changed

+8
-6
lines changed

src/iotjs_binding.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ jerry_value_t iotjs_jhelper_eval(const char* name, size_t name_len,
151151

152152
#if defined(EXPERIMENTAL) && !defined(DEBUG)
153153
// This code branch is to be in #ifdef NDEBUG
154+
#define DJS_CHECK(predicate) ((void)0)
154155
#define DJS_CHECK_ARG(index, type) ((void)0)
155156
#define DJS_CHECK_ARGS(argc, ...) ((void)0)
156157
#define DJS_CHECK_THIS() ((void)0)
157158
#define DJS_CHECK_ARG_IF_EXIST(index, type) ((void)0)
158159
#else
160+
#define DJS_CHECK(predicate) JS_CHECK(predicate)
159161
#define DJS_CHECK_ARG(index, type) JS_CHECK_ARG(index, type)
160162
#define DJS_CHECK_ARGS(argc, ...) JS_CHECK_ARGS(argc, __VA_ARGS__)
161163
#define DJS_CHECK_THIS() JS_CHECK_THIS()

src/modules/iotjs_module_blehcisocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ JS_FUNCTION(start) {
7777

7878
JS_FUNCTION(bind_raw) {
7979
JS_DECLARE_THIS_PTR(blehcisocket, blehcisocket);
80-
JS_CHECK(jargc >= 1);
80+
DJS_CHECK(jargc >= 1);
8181

8282
int devId = 0;
8383
int* pDevId = NULL;

src/modules/iotjs_module_console.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// as utf8 is internal string representation in Jerryscript
2121
static jerry_value_t console_print(const jerry_value_t* jargv,
2222
const jerry_length_t jargc, FILE* out_fd) {
23-
JS_CHECK_ARGS(1, string);
23+
DJS_CHECK_ARGS(1, string);
2424
iotjs_string_t msg = JS_GET_ARG(0, string);
2525
const char* str = iotjs_string_data(&msg);
2626
unsigned str_len = iotjs_string_size(&msg);

src/modules/iotjs_module_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ jerry_value_t fs_do_read_or_write(const jerry_value_t jfunc,
225225
iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
226226
char* data = buffer_wrap->buffer;
227227
size_t data_length = iotjs_bufferwrap_length(buffer_wrap);
228-
JS_CHECK(data != NULL && data_length > 0);
228+
DJS_CHECK(data != NULL && data_length > 0);
229229

230230
if (!is_within_bounds(offset, length, data_length)) {
231231
return JS_CREATE_ERROR(RANGE, "length out of bound");

src/modules/iotjs_module_http_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ JS_FUNCTION(js_func_execute) {
397397
iotjs_bufferwrap_t* buffer_wrap = iotjs_bufferwrap_from_jbuffer(jbuffer);
398398
char* buf_data = buffer_wrap->buffer;
399399
size_t buf_len = iotjs_bufferwrap_length(buffer_wrap);
400-
JS_CHECK(buf_data != NULL && buf_len > 0);
400+
DJS_CHECK(buf_data != NULL && buf_len > 0);
401401

402402
iotjs_http_parserwrap_set_buf(parser, jbuffer, buf_data, buf_len);
403403

src/modules/iotjs_module_mqtt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static jerry_value_t iotjs_mqtt_subscribe_handler(
697697
DJS_CHECK_THIS();
698698
DJS_CHECK_ARGS(2, any, number);
699699

700-
JS_CHECK(packet_type == SUBSCRIBE || packet_type == UNSUBSCRIBE);
700+
DJS_CHECK(packet_type == SUBSCRIBE || packet_type == UNSUBSCRIBE);
701701

702702
iotjs_tmp_buffer_t topic;
703703
iotjs_jval_as_tmp_buffer(JS_GET_ARG(0, any), &topic);

src/modules/iotjs_module_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ JS_FUNCTION(timer_stop) {
6969

7070

7171
JS_FUNCTION(timer_constructor) {
72-
JS_CHECK_THIS();
72+
DJS_CHECK_THIS();
7373

7474
const jerry_value_t jtimer = JS_GET_THIS();
7575

0 commit comments

Comments
 (0)