Skip to content

Commit b1eb6d5

Browse files
kfarnungaddaleax
authored andcommitted
n-api: wrap test macros in do/while
PR-URL: #14095 Reviewed-By: Jason Ginchereau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f2054f3 commit b1eb6d5

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

test/addons-napi/common.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
"empty error message"; \
1515
napi_throw_error((env), error_message); \
1616
} \
17-
} while(0);
17+
} while (0)
1818

1919
#define NAPI_ASSERT_BASE(env, assertion, message, ret_val) \
20-
if (!(assertion)) { \
21-
napi_throw_error( \
22-
(env), \
23-
"assertion (" #assertion ") failed: " message); \
24-
return ret_val; \
25-
}
20+
do { \
21+
if (!(assertion)) { \
22+
napi_throw_error( \
23+
(env), \
24+
"assertion (" #assertion ") failed: " message); \
25+
return ret_val; \
26+
} \
27+
} while (0)
2628

2729
// Returns NULL on failed assertion.
2830
// This is meant to be used inside napi_callback methods.
@@ -35,10 +37,12 @@
3537
NAPI_ASSERT_BASE(env, assertion, message, NAPI_RETVAL_NOTHING)
3638

3739
#define NAPI_CALL_BASE(env, the_call, ret_val) \
38-
if ((the_call) != napi_ok) { \
39-
GET_AND_THROW_LAST_ERROR((env)); \
40-
return ret_val; \
41-
}
40+
do { \
41+
if ((the_call) != napi_ok) { \
42+
GET_AND_THROW_LAST_ERROR((env)); \
43+
return ret_val; \
44+
} \
45+
} while (0)
4246

4347
// Returns NULL if the_call doesn't return napi_ok.
4448
#define NAPI_CALL(env, the_call) \

test/addons-napi/test_object/test_object.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ napi_value Set(napi_env env, napi_callback_info info) {
5353
NAPI_CALL(env, napi_set_property(env, args[0], args[1], args[2]));
5454

5555
napi_value valuetrue;
56-
NAPI_CALL(env, napi_get_boolean(env, true, &valuetrue))
56+
NAPI_CALL(env, napi_get_boolean(env, true, &valuetrue));
5757

5858
return valuetrue;
5959
}

test/addons-napi/test_reference/test_reference.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ napi_value CheckExternal(napi_env env, napi_callback_info info) {
5858
napi_valuetype argtype;
5959
NAPI_CALL(env, napi_typeof(env, arg, &argtype));
6060

61-
NAPI_ASSERT(env, argtype == napi_external, "Expected an external value.")
61+
NAPI_ASSERT(env, argtype == napi_external, "Expected an external value.");
6262

6363
void* data;
6464
NAPI_CALL(env, napi_get_value_external(env, arg, &data));
6565

6666
NAPI_ASSERT(env, data != NULL && *(int*)data == test_value,
67-
"An external data value of 1 was expected.")
67+
"An external data value of 1 was expected.");
6868

6969
return NULL;
7070
}

0 commit comments

Comments
 (0)