doc: fix node-api call example

The `return` statement should not be enclosed in a nested conditional
branch.

PR-URL: https://github.com/nodejs/node/pull/49395
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Harshitha K P <harshitha014@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
This commit is contained in:
Chengzhong Wu authored and Michaël Zasso committed 2023-11-27 11:57:14 +01:00
1 parent ac27431372
commit e26b89e8be
1 file changed
+14 -13
+14 -13
View File
@@ -346,7 +346,7 @@ napi_value create_addon(napi_env env);
// addon.c
#include "addon.h"
#define NAPI_CALL(env, call) \
#define NODE_API_CALL(env, call) \
do { \
napi_status status = (call); \
if (status != napi_ok) { \
@@ -355,13 +355,14 @@ napi_value create_addon(napi_env env);
const char* err_message = error_info->error_message; \
bool is_pending; \
napi_is_exception_pending((env), &is_pending); \
/* If an exception is already pending, don't rethrow it */ \
if (!is_pending) { \
const char* message = (err_message == NULL) \
? "empty error message" \
: err_message; \
napi_throw_error((env), NULL, message); \
return NULL; \
} \
return NULL; \
} \
} while(0)
@@ -373,20 +374,20 @@ DoSomethingUseful(napi_env env, napi_callback_info info) {
napi_value create_addon(napi_env env) {
napi_value result;
NAPI_CALL(env, napi_create_object(env, &result));
NODE_API_CALL(env, napi_create_object(env, &result));
napi_value exported_function;
NAPI_CALL(env, napi_create_function(env,
"doSomethingUseful",
NAPI_AUTO_LENGTH,
DoSomethingUseful,
NULL,
&exported_function));
NODE_API_CALL(env, napi_create_function(env,
"doSomethingUseful",
NAPI_AUTO_LENGTH,
DoSomethingUseful,
NULL,
&exported_function));
NAPI_CALL(env, napi_set_named_property(env,
result,
"doSomethingUseful",
exported_function));
NODE_API_CALL(env, napi_set_named_property(env,
result,
"doSomethingUseful",
exported_function));
return result;
}