Skip to content

Commit

Permalink
src,doc: refactor to replace typedefs with usings
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node-addon-api#910
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
  • Loading branch information
kevindavies8 committed Mar 15, 2021
1 parent fa47a51 commit b592d1c
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 134 deletions.
4 changes: 2 additions & 2 deletions doc/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ This is the type describing a callback returning `void` that will be invoked
from JavaScript.

```cpp
typedef void (*VoidCallback)(const Napi::CallbackInfo& info);
using VoidCallback = void (*)(const Napi::CallbackInfo& info);
```

### Napi::Function::Callback
Expand All @@ -70,7 +70,7 @@ from JavaScript.


```cpp
typedef Value (*Callback)(const Napi::CallbackInfo& info);
using Callback = Value (*)(const Napi::CallbackInfo& info);
```

## Methods
Expand Down
4 changes: 2 additions & 2 deletions doc/property_descriptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Void Init(Env env) {
### PropertyDescriptor::GetterCallback
```cpp
typedef Napi::Value (*GetterCallback)(const Napi::CallbackInfo& info);
using GetterCallback = Napi::Value (*)(const Napi::CallbackInfo& info);
```

This is the signature of a getter function to be passed as a template parameter
Expand All @@ -59,7 +59,7 @@ to `PropertyDescriptor::Accessor`.
### PropertyDescriptor::SetterCallback

```cpp
typedef void (*SetterCallback)(const Napi::CallbackInfo& info);
using SetterCallback = void (*)(const Napi::CallbackInfo& info);
```

This is the signature of a setter function to be passed as a template parameter
Expand Down
16 changes: 8 additions & 8 deletions doc/typed_array_of.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ classes.
The common JavaScript `TypedArray` types are pre-defined for each of use:

```cpp
typedef Napi::TypedArrayOf<int8_t> Int8Array;
typedef Napi::TypedArrayOf<uint8_t> Uint8Array;
typedef Napi::TypedArrayOf<int16_t> Int16Array;
typedef Napi::TypedArrayOf<uint16_t> Uint16Array;
typedef Napi::TypedArrayOf<int32_t> Int32Array;
typedef Napi::TypedArrayOf<uint32_t> Uint32Array;
typedef Napi::TypedArrayOf<float> Float32Array;
typedef Napi::TypedArrayOf<double> Float64Array;
using Int8Array = Napi::TypedArrayOf<int8_t>;
using Uint8Array = Napi::TypedArrayOf<uint8_t>;
using Int16Array = Napi::TypedArrayOf<int16_t>;
using Uint16Array = Napi::TypedArrayOf<uint16_t>;
using Int32Array = Napi::TypedArrayOf<int32_t>;
using Uint32Array = Napi::TypedArrayOf<uint32_t>;
using Float32Array = Napi::TypedArrayOf<float>;
using Float64Array = Napi::TypedArrayOf<double>;
```

The one exception is the `Uint8ClampedArray` which requires explicit
Expand Down
3 changes: 2 additions & 1 deletion doc/version_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ information is stored in the `napi_node_version` structure that is defined as
shown below:
```cpp
typedef struct {
using napi_node_version =
struct {
uint32_t major;
uint32_t minor;
uint32_t patch;
Expand Down
16 changes: 8 additions & 8 deletions napi-inl.deprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PropertyDescriptor::Accessor(const char* utf8name,
Getter getter,
napi_property_attributes attributes,
void* /*data*/) {
typedef details::CallbackData<Getter, Napi::Value> CbData;
using CbData = details::CallbackData<Getter, Napi::Value>;
// TODO: Delete when the function is destroyed
auto callbackData = new CbData({ getter, nullptr });

Expand Down Expand Up @@ -40,7 +40,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
Getter getter,
napi_property_attributes attributes,
void* /*data*/) {
typedef details::CallbackData<Getter, Napi::Value> CbData;
using CbData = details::CallbackData<Getter, Napi::Value>;
// TODO: Delete when the function is destroyed
auto callbackData = new CbData({ getter, nullptr });

Expand Down Expand Up @@ -71,7 +71,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(const char* utf8name,
Setter setter,
napi_property_attributes attributes,
void* /*data*/) {
typedef details::AccessorCallbackData<Getter, Setter> CbData;
using CbData = details::AccessorCallbackData<Getter, Setter>;
// TODO: Delete when the function is destroyed
auto callbackData = new CbData({ getter, setter, nullptr });

Expand Down Expand Up @@ -102,7 +102,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
Setter setter,
napi_property_attributes attributes,
void* /*data*/) {
typedef details::AccessorCallbackData<Getter, Setter> CbData;
using CbData = details::AccessorCallbackData<Getter, Setter>;
// TODO: Delete when the function is destroyed
auto callbackData = new CbData({ getter, setter, nullptr });

Expand Down Expand Up @@ -133,8 +133,8 @@ inline PropertyDescriptor PropertyDescriptor::Function(const char* utf8name,
Callable cb,
napi_property_attributes attributes,
void* /*data*/) {
typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType;
typedef details::CallbackData<Callable, ReturnType> CbData;
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
using CbData = details::CallbackData<Callable, ReturnType>;
// TODO: Delete when the function is destroyed
auto callbackData = new CbData({ cb, nullptr });

Expand Down Expand Up @@ -163,8 +163,8 @@ inline PropertyDescriptor PropertyDescriptor::Function(napi_value name,
Callable cb,
napi_property_attributes attributes,
void* /*data*/) {
typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType;
typedef details::CallbackData<Callable, ReturnType> CbData;
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
using CbData = details::CallbackData<Callable, ReturnType>;
// TODO: Delete when the function is destroyed
auto callbackData = new CbData({ cb, nullptr });

Expand Down
12 changes: 6 additions & 6 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1989,8 +1989,8 @@ inline Function Function::New(napi_env env,
Callable cb,
const char* utf8name,
void* data) {
typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType;
typedef details::CallbackData<Callable, ReturnType> CbData;
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
using CbData = details::CallbackData<Callable, ReturnType>;
auto callbackData = new CbData({ cb, data });

napi_value value;
Expand Down Expand Up @@ -3043,7 +3043,7 @@ PropertyDescriptor::Accessor(Napi::Env env,
Getter getter,
napi_property_attributes attributes,
void* data) {
typedef details::CallbackData<Getter, Napi::Value> CbData;
using CbData = details::CallbackData<Getter, Napi::Value>;
auto callbackData = new CbData({ getter, data });

napi_status status = AttachData(env, object, callbackData);
Expand Down Expand Up @@ -3081,7 +3081,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
Getter getter,
napi_property_attributes attributes,
void* data) {
typedef details::CallbackData<Getter, Napi::Value> CbData;
using CbData = details::CallbackData<Getter, Napi::Value>;
auto callbackData = new CbData({ getter, data });

napi_status status = AttachData(env, object, callbackData);
Expand Down Expand Up @@ -3110,7 +3110,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
Setter setter,
napi_property_attributes attributes,
void* data) {
typedef details::AccessorCallbackData<Getter, Setter> CbData;
using CbData = details::AccessorCallbackData<Getter, Setter>;
auto callbackData = new CbData({ getter, setter, data });

napi_status status = AttachData(env, object, callbackData);
Expand Down Expand Up @@ -3150,7 +3150,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
Setter setter,
napi_property_attributes attributes,
void* data) {
typedef details::AccessorCallbackData<Getter, Setter> CbData;
using CbData = details::AccessorCallbackData<Getter, Setter>;
auto callbackData = new CbData({ getter, setter, data });

napi_status status = AttachData(env, object, callbackData);
Expand Down
Loading

0 comments on commit b592d1c

Please sign in to comment.