From b1eb6d5485d0d22b0493d2091b2eb2afd8947f1e Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Wed, 5 Jul 2017 14:39:06 -0700 Subject: [PATCH] n-api: wrap test macros in do/while PR-URL: https://github.com/nodejs/node/pull/14095 Reviewed-By: Jason Ginchereau Reviewed-By: Colin Ihrig Reviewed-By: Timothy Gu Reviewed-By: Ben Noordhuis Reviewed-By: Michael Dawson Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell --- test/addons-napi/common.h | 26 +++++++++++-------- test/addons-napi/test_object/test_object.c | 2 +- .../test_reference/test_reference.c | 4 +-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/test/addons-napi/common.h b/test/addons-napi/common.h index eae2d48b04459c..e9640935d4154b 100644 --- a/test/addons-napi/common.h +++ b/test/addons-napi/common.h @@ -14,15 +14,17 @@ "empty error message"; \ napi_throw_error((env), error_message); \ } \ - } while(0); + } while (0) #define NAPI_ASSERT_BASE(env, assertion, message, ret_val) \ - if (!(assertion)) { \ - napi_throw_error( \ - (env), \ - "assertion (" #assertion ") failed: " message); \ - return ret_val; \ - } + do { \ + if (!(assertion)) { \ + napi_throw_error( \ + (env), \ + "assertion (" #assertion ") failed: " message); \ + return ret_val; \ + } \ + } while (0) // Returns NULL on failed assertion. // This is meant to be used inside napi_callback methods. @@ -35,10 +37,12 @@ NAPI_ASSERT_BASE(env, assertion, message, NAPI_RETVAL_NOTHING) #define NAPI_CALL_BASE(env, the_call, ret_val) \ - if ((the_call) != napi_ok) { \ - GET_AND_THROW_LAST_ERROR((env)); \ - return ret_val; \ - } + do { \ + if ((the_call) != napi_ok) { \ + GET_AND_THROW_LAST_ERROR((env)); \ + return ret_val; \ + } \ + } while (0) // Returns NULL if the_call doesn't return napi_ok. #define NAPI_CALL(env, the_call) \ diff --git a/test/addons-napi/test_object/test_object.c b/test/addons-napi/test_object/test_object.c index 96a7aa9c205ccf..663e561a35b197 100644 --- a/test/addons-napi/test_object/test_object.c +++ b/test/addons-napi/test_object/test_object.c @@ -53,7 +53,7 @@ napi_value Set(napi_env env, napi_callback_info info) { NAPI_CALL(env, napi_set_property(env, args[0], args[1], args[2])); napi_value valuetrue; - NAPI_CALL(env, napi_get_boolean(env, true, &valuetrue)) + NAPI_CALL(env, napi_get_boolean(env, true, &valuetrue)); return valuetrue; } diff --git a/test/addons-napi/test_reference/test_reference.c b/test/addons-napi/test_reference/test_reference.c index 9be9fd135fb0e9..0d3925ee5d04bc 100644 --- a/test/addons-napi/test_reference/test_reference.c +++ b/test/addons-napi/test_reference/test_reference.c @@ -58,13 +58,13 @@ napi_value CheckExternal(napi_env env, napi_callback_info info) { napi_valuetype argtype; NAPI_CALL(env, napi_typeof(env, arg, &argtype)); - NAPI_ASSERT(env, argtype == napi_external, "Expected an external value.") + NAPI_ASSERT(env, argtype == napi_external, "Expected an external value."); void* data; NAPI_CALL(env, napi_get_value_external(env, arg, &data)); NAPI_ASSERT(env, data != NULL && *(int*)data == test_value, - "An external data value of 1 was expected.") + "An external data value of 1 was expected."); return NULL; }