mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
* Prefix functions with `static` to make them local
* Remove anonymous namespaces
* `nullptr` -> `NULL`
* .cc -> .c and update binding.gyp
* `static_cast<x>()` -> `(x)()`
* Replace `new`/`delete` with `malloc()`/`free()`
(only in test_callback_scope)
* Move lambda out and convert to local function
(only in test_callback_scope)
* Remove superfluous `#include <vector>`
(only in test_callback_scope_recurse)
Some tests are best left as C++.
```bash
ls -l test/{node-api,js-native-api}/*/*.cc
```
for those remaining as C++ tests.
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
PR-URL: https://github.com/nodejs/node/pull/34615
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
#include <node_api.h>
|
|
#include "../../js-native-api/common.h"
|
|
|
|
static napi_value MakeCallback(napi_env env, napi_callback_info info) {
|
|
size_t argc = 2;
|
|
napi_value args[2];
|
|
// NOLINTNEXTLINE (readability/null_usage)
|
|
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
|
|
|
|
napi_value recv = args[0];
|
|
napi_value func = args[1];
|
|
|
|
napi_status status = napi_make_callback(env, NULL /* async_context */,
|
|
recv, func, 0 /* argc */, NULL /* argv */, NULL /* result */);
|
|
|
|
bool isExceptionPending;
|
|
NAPI_CALL(env, napi_is_exception_pending(env, &isExceptionPending));
|
|
if (isExceptionPending && !(status == napi_pending_exception)) {
|
|
// if there is an exception pending we don't expect any
|
|
// other error
|
|
napi_value pending_error;
|
|
status = napi_get_and_clear_last_exception(env, &pending_error);
|
|
NAPI_CALL(env,
|
|
napi_throw_error((env),
|
|
NULL,
|
|
"error when only pending exception expected"));
|
|
}
|
|
|
|
return recv;
|
|
}
|
|
|
|
static napi_value Init(napi_env env, napi_value exports) {
|
|
napi_value fn;
|
|
NAPI_CALL(env, napi_create_function(
|
|
// NOLINTNEXTLINE (readability/null_usage)
|
|
env, NULL, NAPI_AUTO_LENGTH, MakeCallback, NULL, &fn));
|
|
NAPI_CALL(env, napi_set_named_property(env, exports, "makeCallback", fn));
|
|
return exports;
|
|
}
|
|
|
|
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
|