node-addon-api 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +13 -0
- package/README.md +293 -0
- package/common.gypi +21 -0
- package/except.gypi +25 -0
- package/index.js +11 -0
- package/napi-inl.deprecated.h +192 -0
- package/napi-inl.h +6045 -0
- package/napi.h +2907 -0
- package/node_api.gyp +9 -0
- package/noexcept.gypi +26 -0
- package/nothing.c +0 -0
- package/package-support.json +21 -0
- package/package.json +381 -0
- package/tools/README.md +73 -0
- package/tools/check-napi.js +100 -0
- package/tools/clang-format.js +67 -0
- package/tools/conversion.js +309 -0
package/node_api.gyp
ADDED
package/noexcept.gypi
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
|
|
3
|
+
'cflags': [ '-fno-exceptions' ],
|
|
4
|
+
'cflags_cc': [ '-fno-exceptions' ],
|
|
5
|
+
'conditions': [
|
|
6
|
+
["OS=='win'", {
|
|
7
|
+
# _HAS_EXCEPTIONS is already defined and set to 0 in common.gypi
|
|
8
|
+
#"defines": [
|
|
9
|
+
# "_HAS_EXCEPTIONS=0"
|
|
10
|
+
#],
|
|
11
|
+
"msvs_settings": {
|
|
12
|
+
"VCCLCompilerTool": {
|
|
13
|
+
'ExceptionHandling': 0,
|
|
14
|
+
'EnablePREfast': 'true',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}],
|
|
18
|
+
["OS=='mac'", {
|
|
19
|
+
'xcode_settings': {
|
|
20
|
+
'CLANG_CXX_LIBRARY': 'libc++',
|
|
21
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
|
22
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
|
|
23
|
+
},
|
|
24
|
+
}],
|
|
25
|
+
],
|
|
26
|
+
}
|
package/nothing.c
ADDED
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"versions": [
|
|
3
|
+
{
|
|
4
|
+
"version": "*",
|
|
5
|
+
"target": {
|
|
6
|
+
"node": "active"
|
|
7
|
+
},
|
|
8
|
+
"response": {
|
|
9
|
+
"type": "time-permitting",
|
|
10
|
+
"paid": false,
|
|
11
|
+
"contact": {
|
|
12
|
+
"name": "node-addon-api team",
|
|
13
|
+
"url": "https://github.com/nodejs/node-addon-api/issues"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"backing": [ { "project": "https://github.com/nodejs" },
|
|
17
|
+
{ "foundation": "https://openjsf.org/" }
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bugs": {
|
|
3
|
+
"url": "https://github.com/nodejs/node-addon-api/issues"
|
|
4
|
+
},
|
|
5
|
+
"contributors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "Abhishek Kumar Singh",
|
|
8
|
+
"url": "https://github.com/abhi11210646"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "Alba Mendez",
|
|
12
|
+
"url": "https://github.com/jmendeth"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "András Timár, Dr",
|
|
16
|
+
"url": "https://github.com/timarandras"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "Andrew Petersen",
|
|
20
|
+
"url": "https://github.com/kirbysayshi"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "Anisha Rohra",
|
|
24
|
+
"url": "https://github.com/anisha-rohra"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "Anna Henningsen",
|
|
28
|
+
"url": "https://github.com/addaleax"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "Arnaud Botella",
|
|
32
|
+
"url": "https://github.com/BotellaA"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "Arunesh Chandra",
|
|
36
|
+
"url": "https://github.com/aruneshchandra"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "Azlan Mukhtar",
|
|
40
|
+
"url": "https://github.com/azlan"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "Ben Berman",
|
|
44
|
+
"url": "https://github.com/rivertam"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "Benjamin Byholm",
|
|
48
|
+
"url": "https://github.com/kkoopa"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "Bill Gallafent",
|
|
52
|
+
"url": "https://github.com/gallafent"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "blagoev",
|
|
56
|
+
"url": "https://github.com/blagoev"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "Bruce A. MacNaughton",
|
|
60
|
+
"url": "https://github.com/bmacnaughton"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "Cory Mickelson",
|
|
64
|
+
"url": "https://github.com/corymickelson"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "Daniel Bevenius",
|
|
68
|
+
"url": "https://github.com/danbev"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "Darshan Sen",
|
|
72
|
+
"url": "https://github.com/RaisinTen"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "David Halls",
|
|
76
|
+
"url": "https://github.com/davedoesdev"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "Deepak Rajamohan",
|
|
80
|
+
"url": "https://github.com/deepakrkris"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "Dmitry Ashkadov",
|
|
84
|
+
"url": "https://github.com/dmitryash"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "Dongjin Na",
|
|
88
|
+
"url": "https://github.com/nadongguri"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "Ferdinand Holzer",
|
|
92
|
+
"url": "https://github.com/fholzer"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "Eric Bickle",
|
|
96
|
+
"url": "https://github.com/ebickle"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "Gabriel Schulhof",
|
|
100
|
+
"url": "https://github.com/gabrielschulhof"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "Guenter Sandner",
|
|
104
|
+
"url": "https://github.com/gms1"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "Gus Caplan",
|
|
108
|
+
"url": "https://github.com/devsnek"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "Helio Frota",
|
|
112
|
+
"url": "https://github.com/helio-frota"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"name": "Hitesh Kanwathirtha",
|
|
116
|
+
"url": "https://github.com/digitalinfinity"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "ikokostya",
|
|
120
|
+
"url": "https://github.com/ikokostya"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "Jack Xia",
|
|
124
|
+
"url": "https://github.com/JckXia"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "Jake Barnes",
|
|
128
|
+
"url": "https://github.com/DuBistKomisch"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"name": "Jake Yoon",
|
|
132
|
+
"url": "https://github.com/yjaeseok"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "Jason Ginchereau",
|
|
136
|
+
"url": "https://github.com/jasongin"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "Jeroen Janssen",
|
|
140
|
+
"url": "https://github.com/japj"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "Jim Schlight",
|
|
144
|
+
"url": "https://github.com/jschlight"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"name": "Jinho Bang",
|
|
148
|
+
"url": "https://github.com/romandev"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "José Expósito",
|
|
152
|
+
"url": "https://github.com/JoseExposito"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"name": "joshgarde",
|
|
156
|
+
"url": "https://github.com/joshgarde"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"name": "Kasumi Hanazuki",
|
|
160
|
+
"url": "https://github.com/hanazuki"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"name": "Kelvin",
|
|
164
|
+
"url": "https://github.com/kelvinhammond"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "Kevin Eady",
|
|
168
|
+
"url": "https://github.com/KevinEady"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"name": "Kévin VOYER",
|
|
172
|
+
"url": "https://github.com/kecsou"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"name": "kidneysolo",
|
|
176
|
+
"url": "https://github.com/kidneysolo"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"name": "Koki Nishihara",
|
|
180
|
+
"url": "https://github.com/Nishikoh"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"name": "Konstantin Tarkus",
|
|
184
|
+
"url": "https://github.com/koistya"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"name": "Kyle Farnung",
|
|
188
|
+
"url": "https://github.com/kfarnung"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"name": "legendecas",
|
|
192
|
+
"url": "https://github.com/legendecas"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"name": "LongYinan",
|
|
196
|
+
"url": "https://github.com/Brooooooklyn"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"name": "Lovell Fuller",
|
|
200
|
+
"url": "https://github.com/lovell"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"name": "Luciano Martorella",
|
|
204
|
+
"url": "https://github.com/lmartorella"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"name": "mastergberry",
|
|
208
|
+
"url": "https://github.com/mastergberry"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "Mathias Küsel",
|
|
212
|
+
"url": "https://github.com/mathiask88"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"name": "Matteo Collina",
|
|
216
|
+
"url": "https://github.com/mcollina"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"name": "Michael Dawson",
|
|
220
|
+
"url": "https://github.com/mhdawson"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"name": "Michael Price",
|
|
224
|
+
"url": "https://github.com/mikepricedev"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"name": "Michele Campus",
|
|
228
|
+
"url": "https://github.com/kYroL01"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"name": "Mikhail Cheshkov",
|
|
232
|
+
"url": "https://github.com/mcheshkov"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"name": "nempoBu4",
|
|
236
|
+
"url": "https://github.com/nempoBu4"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"name": "Nicola Del Gobbo",
|
|
240
|
+
"url": "https://github.com/NickNaso"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"name": "Nick Soggin",
|
|
244
|
+
"url": "https://github.com/iSkore"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"name": "Nikolai Vavilov",
|
|
248
|
+
"url": "https://github.com/seishun"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "Nurbol Alpysbayev",
|
|
252
|
+
"url": "https://github.com/anurbol"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"name": "pacop",
|
|
256
|
+
"url": "https://github.com/pacop"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"name": "Philipp Renoth",
|
|
260
|
+
"url": "https://github.com/DaAitch"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"name": "Rolf Timmermans",
|
|
264
|
+
"url": "https://github.com/rolftimmermans"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"name": "Ross Weir",
|
|
268
|
+
"url": "https://github.com/ross-weir"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"name": "Ryuichi Okumura",
|
|
272
|
+
"url": "https://github.com/okuryu"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"name": "Sampson Gao",
|
|
276
|
+
"url": "https://github.com/sampsongao"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"name": "Sam Roberts",
|
|
280
|
+
"url": "https://github.com/sam-github"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"name": "strager",
|
|
284
|
+
"url": "https://github.com/strager"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"name": "Taylor Woll",
|
|
288
|
+
"url": "https://github.com/boingoing"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"name": "Thomas Gentilhomme",
|
|
292
|
+
"url": "https://github.com/fraxken"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"name": "Tim Rach",
|
|
296
|
+
"url": "https://github.com/timrach"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"name": "Tobias Nießen",
|
|
300
|
+
"url": "https://github.com/tniessen"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
"name": "todoroff",
|
|
304
|
+
"url": "https://github.com/todoroff"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"name": "Tux3",
|
|
308
|
+
"url": "https://github.com/tux3"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"name": "Vlad Velmisov",
|
|
312
|
+
"url": "https://github.com/Velmisov"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"name": "Yohei Kishimoto",
|
|
316
|
+
"url": "https://github.com/morokosi"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"name": "Yulong Wang",
|
|
320
|
+
"url": "https://github.com/fs-eire"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
"name": "Ziqiu Zhao",
|
|
324
|
+
"url": "https://github.com/ZzqiZQute"
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
"description": "Node.js API (Node-API)",
|
|
328
|
+
"devDependencies": {
|
|
329
|
+
"benchmark": "^2.1.4",
|
|
330
|
+
"bindings": "^1.5.0",
|
|
331
|
+
"clang-format": "^1.4.0",
|
|
332
|
+
"fs-extra": "^9.0.1",
|
|
333
|
+
"path": "^0.12.7",
|
|
334
|
+
"pre-commit": "^1.2.2",
|
|
335
|
+
"safe-buffer": "^5.1.1"
|
|
336
|
+
},
|
|
337
|
+
"directories": {},
|
|
338
|
+
"gypfile": false,
|
|
339
|
+
"homepage": "https://github.com/nodejs/node-addon-api",
|
|
340
|
+
"keywords": [
|
|
341
|
+
"n-api",
|
|
342
|
+
"napi",
|
|
343
|
+
"addon",
|
|
344
|
+
"native",
|
|
345
|
+
"bindings",
|
|
346
|
+
"c",
|
|
347
|
+
"c++",
|
|
348
|
+
"nan",
|
|
349
|
+
"node-addon-api"
|
|
350
|
+
],
|
|
351
|
+
"license": "MIT",
|
|
352
|
+
"main": "index.js",
|
|
353
|
+
"name": "node-addon-api",
|
|
354
|
+
"optionalDependencies": {},
|
|
355
|
+
"readme": "README.md",
|
|
356
|
+
"repository": {
|
|
357
|
+
"type": "git",
|
|
358
|
+
"url": "git://github.com/nodejs/node-addon-api.git"
|
|
359
|
+
},
|
|
360
|
+
"files": [
|
|
361
|
+
"*.{c,h,gyp,gypi}",
|
|
362
|
+
"package-support.json",
|
|
363
|
+
"tools/"
|
|
364
|
+
],
|
|
365
|
+
"scripts": {
|
|
366
|
+
"prebenchmark": "node-gyp rebuild -C benchmark",
|
|
367
|
+
"benchmark": "node benchmark",
|
|
368
|
+
"pretest": "node-gyp rebuild -C test",
|
|
369
|
+
"test": "node test",
|
|
370
|
+
"predev": "node-gyp rebuild -C test --debug",
|
|
371
|
+
"dev": "node test",
|
|
372
|
+
"predev:incremental": "node-gyp configure build -C test --debug",
|
|
373
|
+
"dev:incremental": "node test",
|
|
374
|
+
"doc": "doxygen doc/Doxyfile",
|
|
375
|
+
"lint": "node tools/clang-format",
|
|
376
|
+
"lint:fix": "node tools/clang-format --fix"
|
|
377
|
+
},
|
|
378
|
+
"pre-commit": "lint",
|
|
379
|
+
"version": "4.2.0",
|
|
380
|
+
"support": true
|
|
381
|
+
}
|
package/tools/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Tools
|
|
2
|
+
|
|
3
|
+
## clang-format
|
|
4
|
+
|
|
5
|
+
The clang-format checking tools is designed to check changed lines of code compared to given git-refs.
|
|
6
|
+
|
|
7
|
+
## Migration Script
|
|
8
|
+
|
|
9
|
+
The migration tool is designed to reduce repetitive work in the migration process. However, the script is not aiming to convert every thing for you. There are usually some small fixes and major reconstruction required.
|
|
10
|
+
|
|
11
|
+
### How To Use
|
|
12
|
+
|
|
13
|
+
To run the conversion script, first make sure you have the latest `node-addon-api` in your `node_modules` directory.
|
|
14
|
+
```
|
|
15
|
+
npm install node-addon-api
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then run the script passing your project directory
|
|
19
|
+
```
|
|
20
|
+
node ./node_modules/node-addon-api/tools/conversion.js ./
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
After finish, recompile and debug things that are missed by the script.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Quick Fixes
|
|
27
|
+
Here is the list of things that can be fixed easily.
|
|
28
|
+
1. Change your methods' return value to void if it doesn't return value to JavaScript.
|
|
29
|
+
2. Use `.` to access attribute or to invoke member function in Napi::Object instead of `->`.
|
|
30
|
+
3. `Napi::New(env, value);` to `Napi::[Type]::New(env, value);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Major Reconstructions
|
|
34
|
+
The implementation of `Napi::ObjectWrap` is significantly different from NAN's. `Napi::ObjectWrap` takes a pointer to the wrapped object and creates a reference to the wrapped object inside ObjectWrap constructor. `Napi::ObjectWrap` also associates wrapped object's instance methods to Javascript module instead of static methods like NAN.
|
|
35
|
+
|
|
36
|
+
So if you use Nan::ObjectWrap in your module, you will need to execute the following steps.
|
|
37
|
+
|
|
38
|
+
1. Convert your [ClassName]::New function to a constructor function that takes a `Napi::CallbackInfo`. Declare it as
|
|
39
|
+
```
|
|
40
|
+
[ClassName](const Napi::CallbackInfo& info);
|
|
41
|
+
```
|
|
42
|
+
and define it as
|
|
43
|
+
```
|
|
44
|
+
[ClassName]::[ClassName](const Napi::CallbackInfo& info) : Napi::ObjectWrap<[ClassName]>(info){
|
|
45
|
+
...
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
This way, the `Napi::ObjectWrap` constructor will be invoked after the object has been instantiated and `Napi::ObjectWrap` can use the `this` pointer to create a reference to the wrapped object.
|
|
49
|
+
|
|
50
|
+
2. Move your original constructor code into the new constructor. Delete your original constructor.
|
|
51
|
+
3. In your class initialization function, associate native methods in the following way.
|
|
52
|
+
```
|
|
53
|
+
Napi::FunctionReference constructor;
|
|
54
|
+
|
|
55
|
+
void [ClassName]::Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
|
|
56
|
+
Napi::HandleScope scope(env);
|
|
57
|
+
Napi::Function ctor = DefineClass(env, "Canvas", {
|
|
58
|
+
InstanceMethod<&[ClassName]::Func1>("Func1"),
|
|
59
|
+
InstanceMethod<&[ClassName]::Func2>("Func2"),
|
|
60
|
+
InstanceAccessor<&[ClassName]::ValueGetter>("Value"),
|
|
61
|
+
StaticMethod<&[ClassName]::StaticMethod>("MethodName"),
|
|
62
|
+
InstanceValue("Value", Napi::[Type]::New(env, value)),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
constructor = Napi::Persistent(ctor);
|
|
66
|
+
constructor .SuppressDestruct();
|
|
67
|
+
exports.Set("[ClassName]", ctor);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
4. In function where you need to Unwrap the ObjectWrap in NAN like `[ClassName]* native = Nan::ObjectWrap::Unwrap<[ClassName]>(info.This());`, use `this` pointer directly as the unwrapped object as each ObjectWrap instance is associated with a unique object instance.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
If you still find issues after following this guide, please leave us an issue describing your problem and we will try to resolve it.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Descend into a directory structure and, for each file matching *.node, output
|
|
3
|
+
// based on the imports found in the file whether it's an N-API module or not.
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const child_process = require('child_process');
|
|
8
|
+
|
|
9
|
+
// Read the output of the command, break it into lines, and use the reducer to
|
|
10
|
+
// decide whether the file is an N-API module or not.
|
|
11
|
+
function checkFile(file, command, argv, reducer) {
|
|
12
|
+
const child = child_process.spawn(command, argv, {
|
|
13
|
+
stdio: ['inherit', 'pipe', 'inherit']
|
|
14
|
+
});
|
|
15
|
+
let leftover = '';
|
|
16
|
+
let isNapi = undefined;
|
|
17
|
+
child.stdout.on('data', (chunk) => {
|
|
18
|
+
if (isNapi === undefined) {
|
|
19
|
+
chunk = (leftover + chunk.toString()).split(/[\r\n]+/);
|
|
20
|
+
leftover = chunk.pop();
|
|
21
|
+
isNapi = chunk.reduce(reducer, isNapi);
|
|
22
|
+
if (isNapi !== undefined) {
|
|
23
|
+
child.kill();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
child.on('close', (code, signal) => {
|
|
28
|
+
if ((code === null && signal !== null) || (code !== 0)) {
|
|
29
|
+
console.log(
|
|
30
|
+
command + ' exited with code: ' + code + ' and signal: ' + signal);
|
|
31
|
+
} else {
|
|
32
|
+
// Green if it's a N-API module, red otherwise.
|
|
33
|
+
console.log(
|
|
34
|
+
'\x1b[' + (isNapi ? '42' : '41') + 'm' +
|
|
35
|
+
(isNapi ? ' N-API' : 'Not N-API') +
|
|
36
|
+
'\x1b[0m: ' + file);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Use nm -a to list symbols.
|
|
42
|
+
function checkFileUNIX(file) {
|
|
43
|
+
checkFile(file, 'nm', ['-a', file], (soFar, line) => {
|
|
44
|
+
if (soFar === undefined) {
|
|
45
|
+
line = line.match(/([0-9a-f]*)? ([a-zA-Z]) (.*$)/);
|
|
46
|
+
if (line[2] === 'U') {
|
|
47
|
+
if (/^napi/.test(line[3])) {
|
|
48
|
+
soFar = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return soFar;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Use dumpbin /imports to list symbols.
|
|
57
|
+
function checkFileWin32(file) {
|
|
58
|
+
checkFile(file, 'dumpbin', ['/imports', file], (soFar, line) => {
|
|
59
|
+
if (soFar === undefined) {
|
|
60
|
+
line = line.match(/([0-9a-f]*)? +([a-zA-Z0-9]) (.*$)/);
|
|
61
|
+
if (line && /^napi/.test(line[line.length - 1])) {
|
|
62
|
+
soFar = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return soFar;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Descend into a directory structure and pass each file ending in '.node' to
|
|
70
|
+
// one of the above checks, depending on the OS.
|
|
71
|
+
function recurse(top) {
|
|
72
|
+
fs.readdir(top, (error, items) => {
|
|
73
|
+
if (error) {
|
|
74
|
+
throw ("error reading directory " + top + ": " + error);
|
|
75
|
+
}
|
|
76
|
+
items.forEach((item) => {
|
|
77
|
+
item = path.join(top, item);
|
|
78
|
+
fs.stat(item, ((item) => (error, stats) => {
|
|
79
|
+
if (error) {
|
|
80
|
+
throw ("error about " + item + ": " + error);
|
|
81
|
+
}
|
|
82
|
+
if (stats.isDirectory()) {
|
|
83
|
+
recurse(item);
|
|
84
|
+
} else if (/[.]node$/.test(item) &&
|
|
85
|
+
// Explicitly ignore files called 'nothing.node' because they are
|
|
86
|
+
// artefacts of node-addon-api having identified a version of
|
|
87
|
+
// Node.js that ships with a correct implementation of N-API.
|
|
88
|
+
path.basename(item) !== 'nothing.node') {
|
|
89
|
+
process.platform === 'win32' ?
|
|
90
|
+
checkFileWin32(item) :
|
|
91
|
+
checkFileUNIX(item);
|
|
92
|
+
}
|
|
93
|
+
})(item));
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Start with the directory given on the command line or the current directory
|
|
99
|
+
// if nothing was given.
|
|
100
|
+
recurse(process.argv.length > 3 ? process.argv[2] : '.');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const spawn = require('child_process').spawnSync;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const filesToCheck = ['*.h', '*.cc'];
|
|
7
|
+
const CLANG_FORMAT_START = process.env.CLANG_FORMAT_START || 'main';
|
|
8
|
+
|
|
9
|
+
function main(args) {
|
|
10
|
+
let fix = false;
|
|
11
|
+
while (args.length > 0) {
|
|
12
|
+
switch (args[0]) {
|
|
13
|
+
case '-f':
|
|
14
|
+
case '--fix':
|
|
15
|
+
fix = true;
|
|
16
|
+
default:
|
|
17
|
+
}
|
|
18
|
+
args.shift();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let clangFormatPath = path.dirname(require.resolve('clang-format'));
|
|
22
|
+
const options = ['--binary=node_modules/.bin/clang-format', '--style=file'];
|
|
23
|
+
if (fix) {
|
|
24
|
+
options.push(CLANG_FORMAT_START);
|
|
25
|
+
} else {
|
|
26
|
+
options.push('--diff', CLANG_FORMAT_START);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const gitClangFormatPath = path.join(clangFormatPath,
|
|
30
|
+
'bin/git-clang-format');
|
|
31
|
+
const result = spawn('python', [
|
|
32
|
+
gitClangFormatPath,
|
|
33
|
+
...options,
|
|
34
|
+
'--',
|
|
35
|
+
...filesToCheck
|
|
36
|
+
], { encoding: 'utf-8' });
|
|
37
|
+
|
|
38
|
+
if (result.stderr) {
|
|
39
|
+
console.error('Error running git-clang-format:', result.stderr);
|
|
40
|
+
return 2;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const clangFormatOutput = result.stdout.trim();
|
|
44
|
+
// Bail fast if in fix mode.
|
|
45
|
+
if (fix) {
|
|
46
|
+
console.log(clangFormatOutput);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
// Detect if there is any complains from clang-format
|
|
50
|
+
if (clangFormatOutput !== '' &&
|
|
51
|
+
clangFormatOutput !== ('no modified files to format') &&
|
|
52
|
+
clangFormatOutput !== ('clang-format did not modify any files')) {
|
|
53
|
+
console.error(clangFormatOutput);
|
|
54
|
+
const fixCmd = 'npm run lint:fix';
|
|
55
|
+
console.error(`
|
|
56
|
+
ERROR: please run "${fixCmd}" to format changes in your commit
|
|
57
|
+
Note that when running the command locally, please keep your local
|
|
58
|
+
main branch and working branch up to date with nodejs/node-addon-api
|
|
59
|
+
to exclude un-related complains.
|
|
60
|
+
Or you can run "env CLANG_FORMAT_START=upstream/main ${fixCmd}".`);
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (require.main === module) {
|
|
66
|
+
process.exitCode = main(process.argv.slice(2));
|
|
67
|
+
}
|