Skip to content

Commit

Permalink
node-api: format Node-API related code
Browse files Browse the repository at this point in the history
PR-URL: #42396
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
vmoroz authored and juanarbol committed May 31, 2022
1 parent 2b80754 commit c07200c
Show file tree
Hide file tree
Showing 8 changed files with 577 additions and 726 deletions.
81 changes: 35 additions & 46 deletions src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define SRC_JS_NATIVE_API_H_

// This file needs to be compatible with C compilers.
#include <stddef.h> // NOLINT(modernize-deprecated-headers)
#include <stdbool.h> // NOLINT(modernize-deprecated-headers)
#include <stddef.h> // NOLINT(modernize-deprecated-headers)

// Use INT_MAX, this should only be consumed by the pre-processor anyway.
#define NAPI_VERSION_EXPERIMENTAL 2147483647
Expand All @@ -26,14 +26,15 @@
// If you need __declspec(dllimport), either include <node_api.h> instead, or
// define NAPI_EXTERN as __declspec(dllimport) on the compiler's command line.
#ifndef NAPI_EXTERN
#ifdef _WIN32
#define NAPI_EXTERN __declspec(dllexport)
#elif defined(__wasm32__)
#define NAPI_EXTERN __attribute__((visibility("default"))) \
__attribute__((__import_module__("napi")))
#else
#define NAPI_EXTERN __attribute__((visibility("default")))
#endif
#ifdef _WIN32
#define NAPI_EXTERN __declspec(dllexport)
#elif defined(__wasm32__)
#define NAPI_EXTERN \
__attribute__((visibility("default"))) \
__attribute__((__import_module__("napi")))
#else
#define NAPI_EXTERN __attribute__((visibility("default")))
#endif
#endif

#define NAPI_AUTO_LENGTH SIZE_MAX
Expand All @@ -49,8 +50,7 @@
EXTERN_C_START

NAPI_EXTERN napi_status
napi_get_last_error_info(napi_env env,
const napi_extended_error_info** result);
napi_get_last_error_info(napi_env env, const napi_extended_error_info** result);

// Getters for defined singletons
NAPI_EXTERN napi_status napi_get_undefined(napi_env env, napi_value* result);
Expand Down Expand Up @@ -145,18 +145,12 @@ NAPI_EXTERN napi_status napi_get_value_bool(napi_env env,
bool* result);

// Copies LATIN-1 encoded bytes from a string into a buffer.
NAPI_EXTERN napi_status napi_get_value_string_latin1(napi_env env,
napi_value value,
char* buf,
size_t bufsize,
size_t* result);
NAPI_EXTERN napi_status napi_get_value_string_latin1(
napi_env env, napi_value value, char* buf, size_t bufsize, size_t* result);

// Copies UTF-8 encoded bytes from a string into a buffer.
NAPI_EXTERN napi_status napi_get_value_string_utf8(napi_env env,
napi_value value,
char* buf,
size_t bufsize,
size_t* result);
NAPI_EXTERN napi_status napi_get_value_string_utf8(
napi_env env, napi_value value, char* buf, size_t bufsize, size_t* result);

// Copies UTF-16 encoded bytes from a string into a buffer.
NAPI_EXTERN napi_status napi_get_value_string_utf16(napi_env env,
Expand Down Expand Up @@ -208,17 +202,17 @@ NAPI_EXTERN napi_status napi_has_own_property(napi_env env,
napi_value key,
bool* result);
NAPI_EXTERN napi_status napi_set_named_property(napi_env env,
napi_value object,
const char* utf8name,
napi_value value);
napi_value object,
const char* utf8name,
napi_value value);
NAPI_EXTERN napi_status napi_has_named_property(napi_env env,
napi_value object,
const char* utf8name,
bool* result);
napi_value object,
const char* utf8name,
bool* result);
NAPI_EXTERN napi_status napi_get_named_property(napi_env env,
napi_value object,
const char* utf8name,
napi_value* result);
napi_value object,
const char* utf8name,
napi_value* result);
NAPI_EXTERN napi_status napi_set_element(napi_env env,
napi_value object,
uint32_t index,
Expand Down Expand Up @@ -359,12 +353,10 @@ NAPI_EXTERN napi_status napi_open_handle_scope(napi_env env,
napi_handle_scope* result);
NAPI_EXTERN napi_status napi_close_handle_scope(napi_env env,
napi_handle_scope scope);
NAPI_EXTERN napi_status
napi_open_escapable_handle_scope(napi_env env,
napi_escapable_handle_scope* result);
NAPI_EXTERN napi_status
napi_close_escapable_handle_scope(napi_env env,
napi_escapable_handle_scope scope);
NAPI_EXTERN napi_status napi_open_escapable_handle_scope(
napi_env env, napi_escapable_handle_scope* result);
NAPI_EXTERN napi_status napi_close_escapable_handle_scope(
napi_env env, napi_escapable_handle_scope scope);

NAPI_EXTERN napi_status napi_escape_handle(napi_env env,
napi_escapable_handle_scope scope,
Expand All @@ -377,11 +369,11 @@ NAPI_EXTERN napi_status napi_throw_error(napi_env env,
const char* code,
const char* msg);
NAPI_EXTERN napi_status napi_throw_type_error(napi_env env,
const char* code,
const char* msg);
const char* code,
const char* msg);
NAPI_EXTERN napi_status napi_throw_range_error(napi_env env,
const char* code,
const char* msg);
const char* code,
const char* msg);
#ifdef NAPI_EXPERIMENTAL
NAPI_EXTERN napi_status node_api_throw_syntax_error(napi_env env,
const char* code,
Expand Down Expand Up @@ -542,8 +534,7 @@ NAPI_EXTERN napi_status napi_set_instance_data(napi_env env,
napi_finalize finalize_cb,
void* finalize_hint);

NAPI_EXTERN napi_status napi_get_instance_data(napi_env env,
void** data);
NAPI_EXTERN napi_status napi_get_instance_data(napi_env env, void** data);
#endif // NAPI_VERSION >= 6

#if NAPI_VERSION >= 7
Expand All @@ -567,10 +558,8 @@ napi_check_object_type_tag(napi_env env,
napi_value value,
const napi_type_tag* type_tag,
bool* result);
NAPI_EXTERN napi_status napi_object_freeze(napi_env env,
napi_value object);
NAPI_EXTERN napi_status napi_object_seal(napi_env env,
napi_value object);
NAPI_EXTERN napi_status napi_object_freeze(napi_env env, napi_value object);
NAPI_EXTERN napi_status napi_object_seal(napi_env env, napi_value object);
#endif // NAPI_VERSION >= 8

EXTERN_C_END
Expand Down
9 changes: 3 additions & 6 deletions src/js_native_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdint.h> // NOLINT(modernize-deprecated-headers)

#if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
typedef uint16_t char16_t;
typedef uint16_t char16_t;
#endif

// JSVM API types are all opaque pointers for ABI stability
Expand Down Expand Up @@ -36,9 +36,7 @@ typedef enum {
napi_default_method = napi_writable | napi_configurable,

// Default for object properties, like in JS obj[prop].
napi_default_jsproperty = napi_writable |
napi_enumerable |
napi_configurable,
napi_default_jsproperty = napi_writable | napi_enumerable | napi_configurable,
#endif // NAPI_VERSION >= 8
} napi_property_attributes;

Expand Down Expand Up @@ -102,8 +100,7 @@ typedef enum {
// * the definition of `napi_status` in doc/api/n-api.md to reflect the newly
// added value(s).

typedef napi_value (*napi_callback)(napi_env env,
napi_callback_info info);
typedef napi_value (*napi_callback)(napi_env env, napi_callback_info info);
typedef void (*napi_finalize)(napi_env env,
void* finalize_data,
void* finalize_hint);
Expand Down
Loading

0 comments on commit c07200c

Please sign in to comment.