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: #19447
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 Apr 16, 2018
1 parent b565ba2 commit c09a713
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/node_api.cc
Expand Up @@ -75,10 +75,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 c09a713

Please sign in to comment.