Skip to content

Commit

Permalink
n-api: wrap control flow macro in do/while
Browse files Browse the repository at this point in the history
Make CHECK_ENV() safe to use in the following context:

    if (condition)
      CHECK_ENV(env);
    else
      something_else();

Backport-PR-URL: #19265
PR-URL: #18532
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
  • Loading branch information
bnoordhuis authored and MylesBorins committed May 1, 2018
1 parent d89f593 commit 969a520
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ struct napi_env__ {
} \
} while (0)

#define CHECK_ENV(env) \
if ((env) == nullptr) { \
return napi_invalid_arg; \
}
#define CHECK_ENV(env) \
do { \
if ((env) == nullptr) { \
return napi_invalid_arg; \
} \
} while (0)

#define CHECK_ARG(env, arg) \
RETURN_STATUS_IF_FALSE((env), ((arg) != nullptr), napi_invalid_arg)
Expand Down

0 comments on commit 969a520

Please sign in to comment.