Skip to content

Commit 71494a4

Browse files
RaisinTenmhdawson
authored andcommitted
src,doc: refactor to replace typedefs with usings
PR-URL: #910 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: NickNaso <[email protected]>
1 parent 298ff8d commit 71494a4

File tree

7 files changed

+152
-134
lines changed

7 files changed

+152
-134
lines changed

doc/function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ This is the type describing a callback returning `void` that will be invoked
6060
from JavaScript.
6161

6262
```cpp
63-
typedef void (*VoidCallback)(const Napi::CallbackInfo& info);
63+
using VoidCallback = void (*)(const Napi::CallbackInfo& info);
6464
```
6565

6666
### Napi::Function::Callback
@@ -70,7 +70,7 @@ from JavaScript.
7070

7171

7272
```cpp
73-
typedef Value (*Callback)(const Napi::CallbackInfo& info);
73+
using Callback = Value (*)(const Napi::CallbackInfo& info);
7474
```
7575

7676
## Methods

doc/property_descriptor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Void Init(Env env) {
5050
### PropertyDescriptor::GetterCallback
5151
5252
```cpp
53-
typedef Napi::Value (*GetterCallback)(const Napi::CallbackInfo& info);
53+
using GetterCallback = Napi::Value (*)(const Napi::CallbackInfo& info);
5454
```
5555

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

6161
```cpp
62-
typedef void (*SetterCallback)(const Napi::CallbackInfo& info);
62+
using SetterCallback = void (*)(const Napi::CallbackInfo& info);
6363
```
6464

6565
This is the signature of a setter function to be passed as a template parameter

doc/typed_array_of.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ classes.
1111
The common JavaScript `TypedArray` types are pre-defined for each of use:
1212

1313
```cpp
14-
typedef Napi::TypedArrayOf<int8_t> Int8Array;
15-
typedef Napi::TypedArrayOf<uint8_t> Uint8Array;
16-
typedef Napi::TypedArrayOf<int16_t> Int16Array;
17-
typedef Napi::TypedArrayOf<uint16_t> Uint16Array;
18-
typedef Napi::TypedArrayOf<int32_t> Int32Array;
19-
typedef Napi::TypedArrayOf<uint32_t> Uint32Array;
20-
typedef Napi::TypedArrayOf<float> Float32Array;
21-
typedef Napi::TypedArrayOf<double> Float64Array;
14+
using Int8Array = Napi::TypedArrayOf<int8_t>;
15+
using Uint8Array = Napi::TypedArrayOf<uint8_t>;
16+
using Int16Array = Napi::TypedArrayOf<int16_t>;
17+
using Uint16Array = Napi::TypedArrayOf<uint16_t>;
18+
using Int32Array = Napi::TypedArrayOf<int32_t>;
19+
using Uint32Array = Napi::TypedArrayOf<uint32_t>;
20+
using Float32Array = Napi::TypedArrayOf<float>;
21+
using Float64Array = Napi::TypedArrayOf<double>;
2222
```
2323

2424
The one exception is the `Uint8ClampedArray` which requires explicit

doc/version_management.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ information is stored in the `napi_node_version` structure that is defined as
2525
shown below:
2626
2727
```cpp
28-
typedef struct {
28+
using napi_node_version =
29+
struct {
2930
uint32_t major;
3031
uint32_t minor;
3132
uint32_t patch;

napi-inl.deprecated.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PropertyDescriptor::Accessor(const char* utf8name,
1111
Getter getter,
1212
napi_property_attributes attributes,
1313
void* /*data*/) {
14-
typedef details::CallbackData<Getter, Napi::Value> CbData;
14+
using CbData = details::CallbackData<Getter, Napi::Value>;
1515
// TODO: Delete when the function is destroyed
1616
auto callbackData = new CbData({ getter, nullptr });
1717

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

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

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

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

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

napi-inl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,8 +1989,8 @@ inline Function Function::New(napi_env env,
19891989
Callable cb,
19901990
const char* utf8name,
19911991
void* data) {
1992-
typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType;
1993-
typedef details::CallbackData<Callable, ReturnType> CbData;
1992+
using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
1993+
using CbData = details::CallbackData<Callable, ReturnType>;
19941994
auto callbackData = new CbData({ cb, data });
19951995

19961996
napi_value value;
@@ -3043,7 +3043,7 @@ PropertyDescriptor::Accessor(Napi::Env env,
30433043
Getter getter,
30443044
napi_property_attributes attributes,
30453045
void* data) {
3046-
typedef details::CallbackData<Getter, Napi::Value> CbData;
3046+
using CbData = details::CallbackData<Getter, Napi::Value>;
30473047
auto callbackData = new CbData({ getter, data });
30483048

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

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

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

31563156
napi_status status = AttachData(env, object, callbackData);

0 commit comments

Comments
 (0)