GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: fix node-api call example · nodejs/node@e26b89e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • n-api.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/n-api.md‎

Copy file name to clipboardExpand all lines: doc/api/n-api.md
+15-14Lines changed: 15 additions & 14 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ napi_value create_addon(napi_env env);
346346
// addon.c
347347
#include "addon.h"
348348

349-
#define NAPI_CALL(env, call) \
349+
#define NODE_API_CALL(env, call) \
350350
do { \
351351
napi_status status = (call); \
352352
if (status != napi_ok) { \
@@ -355,13 +355,14 @@ napi_value create_addon(napi_env env);
355355
const char* err_message = error_info->error_message; \
356356
bool is_pending; \
357357
napi_is_exception_pending((env), &is_pending); \
358+
/* If an exception is already pending, don't rethrow it */ \
358359
if (!is_pending) { \
359360
const char* message = (err_message == NULL) \
360361
? "empty error message" \
361362
: err_message; \
362363
napi_throw_error((env), NULL, message); \
363-
return NULL; \
364364
} \
365+
return NULL; \
365366
} \
366367
} while(0)
367368

@@ -373,20 +374,20 @@ DoSomethingUseful(napi_env env, napi_callback_info info) {
373374

374375
napi_value create_addon(napi_env env) {
375376
napi_value result;
376-
NAPI_CALL(env, napi_create_object(env, &result));
377+
NODE_API_CALL(env, napi_create_object(env, &result));
377378

378379
napi_value exported_function;
379-
NAPI_CALL(env, napi_create_function(env,
380-
"doSomethingUseful",
381-
NAPI_AUTO_LENGTH,
382-
DoSomethingUseful,
383-
NULL,
384-
&exported_function));
385-
386-
NAPI_CALL(env, napi_set_named_property(env,
387-
result,
388-
"doSomethingUseful",
389-
exported_function));
380+
NODE_API_CALL(env, napi_create_function(env,
381+
"doSomethingUseful",
382+
NAPI_AUTO_LENGTH,
383+
DoSomethingUseful,
384+
NULL,
385+
&exported_function));
386+
387+
NODE_API_CALL(env, napi_set_named_property(env,
388+
result,
389+
"doSomethingUseful",
390+
exported_function));
390391

391392
return result;
392393
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.