@basemaps/lambda-tiler 6.19.0 → 6.22.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.
Files changed (656) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE +2 -2
  3. package/build/__test__/tile.set.cache.test.js +4 -10
  4. package/build/__test__/tile.style.json.test.d.ts +2 -0
  5. package/build/__test__/tile.style.json.test.d.ts.map +1 -0
  6. package/build/__test__/tile.style.json.test.js +33 -0
  7. package/build/__test__/xyz.test.js +24 -23
  8. package/build/cli/dump.js +2 -2
  9. package/build/cli/validate.js +2 -1
  10. package/build/index.d.ts.map +1 -1
  11. package/build/index.js +10 -1
  12. package/build/routes/__test__/attribution.test.js +3 -13
  13. package/build/routes/attribution.d.ts.map +1 -1
  14. package/build/routes/attribution.js +7 -20
  15. package/build/routes/esri/rest.d.ts +10 -0
  16. package/build/routes/esri/rest.d.ts.map +1 -0
  17. package/build/routes/esri/rest.js +87 -0
  18. package/build/routes/imagery.d.ts +2 -0
  19. package/build/routes/imagery.d.ts.map +1 -1
  20. package/build/routes/imagery.js +3 -1
  21. package/build/routes/response.d.ts +4 -0
  22. package/build/routes/response.d.ts.map +1 -0
  23. package/build/routes/response.js +3 -0
  24. package/build/routes/tile.d.ts +0 -20
  25. package/build/routes/tile.d.ts.map +1 -1
  26. package/build/routes/tile.js +11 -161
  27. package/build/routes/tile.json.d.ts +10 -0
  28. package/build/routes/tile.json.d.ts.map +1 -0
  29. package/build/routes/tile.json.js +31 -0
  30. package/build/routes/tile.style.json.d.ts +10 -0
  31. package/build/routes/tile.style.json.d.ts.map +1 -0
  32. package/build/routes/tile.style.json.js +74 -0
  33. package/build/routes/tile.wmts.d.ts +9 -0
  34. package/build/routes/tile.wmts.d.ts.map +1 -0
  35. package/build/routes/tile.wmts.js +57 -0
  36. package/build/routes/tile.xyz.d.ts +13 -0
  37. package/build/routes/tile.xyz.d.ts.map +1 -0
  38. package/build/routes/tile.xyz.js +28 -0
  39. package/build/source.tracer.d.ts +17 -0
  40. package/build/source.tracer.d.ts.map +1 -0
  41. package/build/source.tracer.js +22 -0
  42. package/build/tile.set.cache.js +3 -3
  43. package/build/tile.set.d.ts +0 -16
  44. package/build/tile.set.d.ts.map +1 -1
  45. package/build/tile.set.js +1 -20
  46. package/build/tile.set.raster.d.ts +9 -4
  47. package/build/tile.set.raster.d.ts.map +1 -1
  48. package/build/tile.set.raster.js +17 -6
  49. package/build/tile.set.vector.d.ts +10 -4
  50. package/build/tile.set.vector.d.ts.map +1 -1
  51. package/build/tile.set.vector.js +18 -8
  52. package/bundle.sh +2 -2
  53. package/package.json +14 -14
  54. package/scripts/create.deployment.package.mjs +34 -0
  55. package/src/__test__/tile.set.cache.test.ts +4 -12
  56. package/src/__test__/tile.style.json.test.ts +40 -0
  57. package/src/__test__/xyz.test.ts +32 -30
  58. package/src/cli/dump.ts +2 -2
  59. package/src/cli/validate.ts +2 -1
  60. package/src/index.ts +13 -1
  61. package/src/routes/__test__/attribution.test.ts +3 -13
  62. package/src/routes/attribution.ts +6 -17
  63. package/src/routes/esri/rest.ts +90 -0
  64. package/src/routes/imagery.ts +3 -1
  65. package/src/routes/response.ts +4 -0
  66. package/src/routes/tile.json.ts +44 -0
  67. package/src/routes/tile.style.json.ts +77 -0
  68. package/src/routes/tile.ts +11 -183
  69. package/src/routes/tile.wmts.ts +59 -0
  70. package/src/routes/tile.xyz.ts +30 -0
  71. package/src/source.tracer.ts +34 -0
  72. package/src/tile.set.cache.ts +3 -3
  73. package/src/tile.set.raster.ts +32 -7
  74. package/src/tile.set.ts +0 -40
  75. package/src/tile.set.vector.ts +26 -7
  76. package/tsconfig.tsbuildinfo +1 -1
  77. package/dist/index.js +0 -29740
  78. package/dist/node_modules/ansi-regex/index.js +0 -4
  79. package/dist/node_modules/ansi-regex/license +0 -21
  80. package/dist/node_modules/ansi-regex/package.json +0 -108
  81. package/dist/node_modules/ansi-regex/readme.md +0 -39
  82. package/dist/node_modules/aproba/LICENSE +0 -14
  83. package/dist/node_modules/aproba/README.md +0 -94
  84. package/dist/node_modules/aproba/index.js +0 -105
  85. package/dist/node_modules/aproba/package.json +0 -62
  86. package/dist/node_modules/are-we-there-yet/CHANGES.md +0 -37
  87. package/dist/node_modules/are-we-there-yet/LICENSE +0 -5
  88. package/dist/node_modules/are-we-there-yet/README.md +0 -195
  89. package/dist/node_modules/are-we-there-yet/index.js +0 -4
  90. package/dist/node_modules/are-we-there-yet/package.json +0 -63
  91. package/dist/node_modules/are-we-there-yet/tracker-base.js +0 -11
  92. package/dist/node_modules/are-we-there-yet/tracker-group.js +0 -107
  93. package/dist/node_modules/are-we-there-yet/tracker-stream.js +0 -36
  94. package/dist/node_modules/are-we-there-yet/tracker.js +0 -30
  95. package/dist/node_modules/base64-js/LICENSE +0 -21
  96. package/dist/node_modules/base64-js/README.md +0 -34
  97. package/dist/node_modules/base64-js/base64js.min.js +0 -1
  98. package/dist/node_modules/base64-js/index.d.ts +0 -3
  99. package/dist/node_modules/base64-js/index.js +0 -150
  100. package/dist/node_modules/base64-js/package.json +0 -75
  101. package/dist/node_modules/bl/.travis.yml +0 -17
  102. package/dist/node_modules/bl/BufferList.js +0 -396
  103. package/dist/node_modules/bl/LICENSE.md +0 -13
  104. package/dist/node_modules/bl/README.md +0 -247
  105. package/dist/node_modules/bl/bl.js +0 -84
  106. package/dist/node_modules/bl/node_modules/readable-stream/CONTRIBUTING.md +0 -38
  107. package/dist/node_modules/bl/node_modules/readable-stream/GOVERNANCE.md +0 -136
  108. package/dist/node_modules/bl/node_modules/readable-stream/LICENSE +0 -47
  109. package/dist/node_modules/bl/node_modules/readable-stream/README.md +0 -106
  110. package/dist/node_modules/bl/node_modules/readable-stream/errors-browser.js +0 -127
  111. package/dist/node_modules/bl/node_modules/readable-stream/errors.js +0 -116
  112. package/dist/node_modules/bl/node_modules/readable-stream/experimentalWarning.js +0 -17
  113. package/dist/node_modules/bl/node_modules/readable-stream/lib/_stream_duplex.js +0 -139
  114. package/dist/node_modules/bl/node_modules/readable-stream/lib/_stream_passthrough.js +0 -39
  115. package/dist/node_modules/bl/node_modules/readable-stream/lib/_stream_readable.js +0 -1124
  116. package/dist/node_modules/bl/node_modules/readable-stream/lib/_stream_transform.js +0 -201
  117. package/dist/node_modules/bl/node_modules/readable-stream/lib/_stream_writable.js +0 -697
  118. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -207
  119. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -210
  120. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -105
  121. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -104
  122. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
  123. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/from.js +0 -64
  124. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -97
  125. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/state.js +0 -27
  126. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  127. package/dist/node_modules/bl/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  128. package/dist/node_modules/bl/node_modules/readable-stream/package.json +0 -97
  129. package/dist/node_modules/bl/node_modules/readable-stream/readable-browser.js +0 -9
  130. package/dist/node_modules/bl/node_modules/readable-stream/readable.js +0 -16
  131. package/dist/node_modules/bl/package.json +0 -69
  132. package/dist/node_modules/bl/test/convert.js +0 -21
  133. package/dist/node_modules/bl/test/indexOf.js +0 -492
  134. package/dist/node_modules/bl/test/isBufferList.js +0 -32
  135. package/dist/node_modules/bl/test/test.js +0 -869
  136. package/dist/node_modules/buffer/AUTHORS.md +0 -70
  137. package/dist/node_modules/buffer/LICENSE +0 -21
  138. package/dist/node_modules/buffer/README.md +0 -410
  139. package/dist/node_modules/buffer/index.d.ts +0 -186
  140. package/dist/node_modules/buffer/index.js +0 -1817
  141. package/dist/node_modules/buffer/package.json +0 -127
  142. package/dist/node_modules/chownr/LICENSE +0 -15
  143. package/dist/node_modules/chownr/README.md +0 -3
  144. package/dist/node_modules/chownr/chownr.js +0 -167
  145. package/dist/node_modules/chownr/package.json +0 -62
  146. package/dist/node_modules/code-point-at/index.js +0 -32
  147. package/dist/node_modules/code-point-at/license +0 -21
  148. package/dist/node_modules/code-point-at/package.json +0 -70
  149. package/dist/node_modules/code-point-at/readme.md +0 -32
  150. package/dist/node_modules/color/LICENSE +0 -21
  151. package/dist/node_modules/color/README.md +0 -123
  152. package/dist/node_modules/color/index.js +0 -482
  153. package/dist/node_modules/color/package.json +0 -72
  154. package/dist/node_modules/color-convert/CHANGELOG.md +0 -54
  155. package/dist/node_modules/color-convert/LICENSE +0 -21
  156. package/dist/node_modules/color-convert/README.md +0 -68
  157. package/dist/node_modules/color-convert/conversions.js +0 -868
  158. package/dist/node_modules/color-convert/index.js +0 -78
  159. package/dist/node_modules/color-convert/package.json +0 -81
  160. package/dist/node_modules/color-convert/route.js +0 -97
  161. package/dist/node_modules/color-name/.eslintrc.json +0 -43
  162. package/dist/node_modules/color-name/LICENSE +0 -8
  163. package/dist/node_modules/color-name/README.md +0 -11
  164. package/dist/node_modules/color-name/index.js +0 -152
  165. package/dist/node_modules/color-name/package.json +0 -54
  166. package/dist/node_modules/color-name/test.js +0 -7
  167. package/dist/node_modules/color-string/LICENSE +0 -21
  168. package/dist/node_modules/color-string/README.md +0 -62
  169. package/dist/node_modules/color-string/index.js +0 -242
  170. package/dist/node_modules/color-string/package.json +0 -81
  171. package/dist/node_modules/console-control-strings/LICENSE +0 -13
  172. package/dist/node_modules/console-control-strings/README.md +0 -145
  173. package/dist/node_modules/console-control-strings/README.md~ +0 -140
  174. package/dist/node_modules/console-control-strings/index.js +0 -125
  175. package/dist/node_modules/console-control-strings/package.json +0 -61
  176. package/dist/node_modules/core-util-is/LICENSE +0 -19
  177. package/dist/node_modules/core-util-is/README.md +0 -3
  178. package/dist/node_modules/core-util-is/lib/util.js +0 -107
  179. package/dist/node_modules/core-util-is/package.json +0 -68
  180. package/dist/node_modules/decompress-response/index.d.ts +0 -29
  181. package/dist/node_modules/decompress-response/index.js +0 -40
  182. package/dist/node_modules/decompress-response/license +0 -9
  183. package/dist/node_modules/decompress-response/package.json +0 -82
  184. package/dist/node_modules/decompress-response/readme.md +0 -52
  185. package/dist/node_modules/deep-extend/CHANGELOG.md +0 -46
  186. package/dist/node_modules/deep-extend/LICENSE +0 -20
  187. package/dist/node_modules/deep-extend/README.md +0 -91
  188. package/dist/node_modules/deep-extend/index.js +0 -1
  189. package/dist/node_modules/deep-extend/lib/deep-extend.js +0 -150
  190. package/dist/node_modules/deep-extend/package.json +0 -92
  191. package/dist/node_modules/delegates/History.md +0 -22
  192. package/dist/node_modules/delegates/License +0 -20
  193. package/dist/node_modules/delegates/Makefile +0 -8
  194. package/dist/node_modules/delegates/Readme.md +0 -94
  195. package/dist/node_modules/delegates/index.js +0 -121
  196. package/dist/node_modules/delegates/package.json +0 -48
  197. package/dist/node_modules/delegates/test/index.js +0 -94
  198. package/dist/node_modules/detect-libc/LICENSE +0 -201
  199. package/dist/node_modules/detect-libc/README.md +0 -78
  200. package/dist/node_modules/detect-libc/bin/detect-libc.js +0 -18
  201. package/dist/node_modules/detect-libc/lib/detect-libc.js +0 -92
  202. package/dist/node_modules/detect-libc/package.json +0 -71
  203. package/dist/node_modules/end-of-stream/LICENSE +0 -21
  204. package/dist/node_modules/end-of-stream/README.md +0 -54
  205. package/dist/node_modules/end-of-stream/index.js +0 -94
  206. package/dist/node_modules/end-of-stream/package.json +0 -66
  207. package/dist/node_modules/expand-template/.travis.yml +0 -6
  208. package/dist/node_modules/expand-template/LICENSE +0 -21
  209. package/dist/node_modules/expand-template/README.md +0 -43
  210. package/dist/node_modules/expand-template/index.js +0 -26
  211. package/dist/node_modules/expand-template/package.json +0 -60
  212. package/dist/node_modules/expand-template/test.js +0 -67
  213. package/dist/node_modules/fs-constants/LICENSE +0 -21
  214. package/dist/node_modules/fs-constants/README.md +0 -26
  215. package/dist/node_modules/fs-constants/browser.js +0 -1
  216. package/dist/node_modules/fs-constants/index.js +0 -1
  217. package/dist/node_modules/fs-constants/package.json +0 -47
  218. package/dist/node_modules/gauge/CHANGELOG.md +0 -160
  219. package/dist/node_modules/gauge/LICENSE +0 -13
  220. package/dist/node_modules/gauge/README.md +0 -399
  221. package/dist/node_modules/gauge/base-theme.js +0 -14
  222. package/dist/node_modules/gauge/error.js +0 -24
  223. package/dist/node_modules/gauge/has-color.js +0 -12
  224. package/dist/node_modules/gauge/index.js +0 -233
  225. package/dist/node_modules/gauge/package.json +0 -91
  226. package/dist/node_modules/gauge/plumbing.js +0 -48
  227. package/dist/node_modules/gauge/process.js +0 -3
  228. package/dist/node_modules/gauge/progress-bar.js +0 -35
  229. package/dist/node_modules/gauge/render-template.js +0 -181
  230. package/dist/node_modules/gauge/set-immediate.js +0 -7
  231. package/dist/node_modules/gauge/set-interval.js +0 -3
  232. package/dist/node_modules/gauge/spin.js +0 -5
  233. package/dist/node_modules/gauge/template-item.js +0 -73
  234. package/dist/node_modules/gauge/theme-set.js +0 -115
  235. package/dist/node_modules/gauge/themes.js +0 -54
  236. package/dist/node_modules/gauge/wide-truncate.js +0 -25
  237. package/dist/node_modules/github-from-package/.travis.yml +0 -4
  238. package/dist/node_modules/github-from-package/LICENSE +0 -18
  239. package/dist/node_modules/github-from-package/example/package.json +0 -8
  240. package/dist/node_modules/github-from-package/example/url.js +0 -3
  241. package/dist/node_modules/github-from-package/index.js +0 -17
  242. package/dist/node_modules/github-from-package/package.json +0 -58
  243. package/dist/node_modules/github-from-package/readme.markdown +0 -53
  244. package/dist/node_modules/github-from-package/test/a.json +0 -8
  245. package/dist/node_modules/github-from-package/test/b.json +0 -5
  246. package/dist/node_modules/github-from-package/test/c.json +0 -5
  247. package/dist/node_modules/github-from-package/test/d.json +0 -7
  248. package/dist/node_modules/github-from-package/test/e.json +0 -5
  249. package/dist/node_modules/github-from-package/test/url.js +0 -19
  250. package/dist/node_modules/has-unicode/LICENSE +0 -14
  251. package/dist/node_modules/has-unicode/README.md +0 -43
  252. package/dist/node_modules/has-unicode/index.js +0 -16
  253. package/dist/node_modules/has-unicode/package.json +0 -58
  254. package/dist/node_modules/ieee754/LICENSE +0 -11
  255. package/dist/node_modules/ieee754/README.md +0 -51
  256. package/dist/node_modules/ieee754/index.d.ts +0 -10
  257. package/dist/node_modules/ieee754/index.js +0 -85
  258. package/dist/node_modules/ieee754/package.json +0 -84
  259. package/dist/node_modules/inherits/LICENSE +0 -16
  260. package/dist/node_modules/inherits/README.md +0 -42
  261. package/dist/node_modules/inherits/inherits.js +0 -9
  262. package/dist/node_modules/inherits/inherits_browser.js +0 -27
  263. package/dist/node_modules/inherits/package.json +0 -65
  264. package/dist/node_modules/ini/LICENSE +0 -15
  265. package/dist/node_modules/ini/README.md +0 -102
  266. package/dist/node_modules/ini/ini.js +0 -206
  267. package/dist/node_modules/ini/package.json +0 -66
  268. package/dist/node_modules/is-arrayish/LICENSE +0 -21
  269. package/dist/node_modules/is-arrayish/README.md +0 -16
  270. package/dist/node_modules/is-arrayish/index.js +0 -9
  271. package/dist/node_modules/is-arrayish/package.json +0 -77
  272. package/dist/node_modules/is-arrayish/yarn-error.log +0 -1443
  273. package/dist/node_modules/is-fullwidth-code-point/index.js +0 -46
  274. package/dist/node_modules/is-fullwidth-code-point/license +0 -21
  275. package/dist/node_modules/is-fullwidth-code-point/package.json +0 -77
  276. package/dist/node_modules/is-fullwidth-code-point/readme.md +0 -39
  277. package/dist/node_modules/isarray/.travis.yml +0 -4
  278. package/dist/node_modules/isarray/Makefile +0 -6
  279. package/dist/node_modules/isarray/README.md +0 -60
  280. package/dist/node_modules/isarray/component.json +0 -19
  281. package/dist/node_modules/isarray/index.js +0 -5
  282. package/dist/node_modules/isarray/package.json +0 -73
  283. package/dist/node_modules/isarray/test.js +0 -20
  284. package/dist/node_modules/lru-cache/LICENSE +0 -15
  285. package/dist/node_modules/lru-cache/README.md +0 -166
  286. package/dist/node_modules/lru-cache/index.js +0 -334
  287. package/dist/node_modules/lru-cache/package.json +0 -69
  288. package/dist/node_modules/mimic-response/index.d.ts +0 -17
  289. package/dist/node_modules/mimic-response/index.js +0 -38
  290. package/dist/node_modules/mimic-response/license +0 -9
  291. package/dist/node_modules/mimic-response/package.json +0 -74
  292. package/dist/node_modules/mimic-response/readme.md +0 -57
  293. package/dist/node_modules/minimist/.travis.yml +0 -8
  294. package/dist/node_modules/minimist/LICENSE +0 -18
  295. package/dist/node_modules/minimist/example/parse.js +0 -2
  296. package/dist/node_modules/minimist/index.js +0 -245
  297. package/dist/node_modules/minimist/package.json +0 -74
  298. package/dist/node_modules/minimist/readme.markdown +0 -95
  299. package/dist/node_modules/minimist/test/all_bool.js +0 -32
  300. package/dist/node_modules/minimist/test/bool.js +0 -178
  301. package/dist/node_modules/minimist/test/dash.js +0 -31
  302. package/dist/node_modules/minimist/test/default_bool.js +0 -35
  303. package/dist/node_modules/minimist/test/dotted.js +0 -22
  304. package/dist/node_modules/minimist/test/kv_short.js +0 -16
  305. package/dist/node_modules/minimist/test/long.js +0 -31
  306. package/dist/node_modules/minimist/test/num.js +0 -36
  307. package/dist/node_modules/minimist/test/parse.js +0 -197
  308. package/dist/node_modules/minimist/test/parse_modified.js +0 -9
  309. package/dist/node_modules/minimist/test/proto.js +0 -44
  310. package/dist/node_modules/minimist/test/short.js +0 -67
  311. package/dist/node_modules/minimist/test/stop_early.js +0 -15
  312. package/dist/node_modules/minimist/test/unknown.js +0 -102
  313. package/dist/node_modules/minimist/test/whitespace.js +0 -8
  314. package/dist/node_modules/mkdirp-classic/LICENSE +0 -21
  315. package/dist/node_modules/mkdirp-classic/README.md +0 -18
  316. package/dist/node_modules/mkdirp-classic/index.js +0 -98
  317. package/dist/node_modules/mkdirp-classic/package.json +0 -47
  318. package/dist/node_modules/napi-build-utils/LICENSE +0 -21
  319. package/dist/node_modules/napi-build-utils/README.md +0 -48
  320. package/dist/node_modules/napi-build-utils/index.js +0 -213
  321. package/dist/node_modules/napi-build-utils/index.md +0 -81
  322. package/dist/node_modules/napi-build-utils/package.json +0 -68
  323. package/dist/node_modules/node-abi/.github/workflows/update-abi.yml +0 -41
  324. package/dist/node_modules/node-abi/.travis.yml +0 -17
  325. package/dist/node_modules/node-abi/CODE_OF_CONDUCT.md +0 -73
  326. package/dist/node_modules/node-abi/CONTRIBUTING.md +0 -53
  327. package/dist/node_modules/node-abi/LICENSE +0 -21
  328. package/dist/node_modules/node-abi/README.md +0 -50
  329. package/dist/node_modules/node-abi/abi_registry.json +0 -144
  330. package/dist/node_modules/node-abi/index.js +0 -176
  331. package/dist/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -39
  332. package/dist/node_modules/node-abi/node_modules/semver/LICENSE +0 -15
  333. package/dist/node_modules/node-abi/node_modules/semver/README.md +0 -412
  334. package/dist/node_modules/node-abi/node_modules/semver/bin/semver +0 -160
  335. package/dist/node_modules/node-abi/node_modules/semver/package.json +0 -60
  336. package/dist/node_modules/node-abi/node_modules/semver/range.bnf +0 -16
  337. package/dist/node_modules/node-abi/node_modules/semver/semver.js +0 -1483
  338. package/dist/node_modules/node-abi/package.json +0 -65
  339. package/dist/node_modules/node-abi/scripts/update-abi-registry.js +0 -119
  340. package/dist/node_modules/node-abi/test/index.js +0 -174
  341. package/dist/node_modules/node-addon-api/CHANGELOG.md +0 -722
  342. package/dist/node_modules/node-addon-api/LICENSE.md +0 -13
  343. package/dist/node_modules/node-addon-api/README.md +0 -293
  344. package/dist/node_modules/node-addon-api/common.gypi +0 -21
  345. package/dist/node_modules/node-addon-api/except.gypi +0 -16
  346. package/dist/node_modules/node-addon-api/index.js +0 -11
  347. package/dist/node_modules/node-addon-api/napi-inl.deprecated.h +0 -192
  348. package/dist/node_modules/node-addon-api/napi-inl.h +0 -5671
  349. package/dist/node_modules/node-addon-api/napi.h +0 -2727
  350. package/dist/node_modules/node-addon-api/node_api.gyp +0 -9
  351. package/dist/node_modules/node-addon-api/noexcept.gypi +0 -16
  352. package/dist/node_modules/node-addon-api/nothing.c +0 -0
  353. package/dist/node_modules/node-addon-api/package-support.json +0 -21
  354. package/dist/node_modules/node-addon-api/package.json +0 -393
  355. package/dist/node_modules/node-addon-api/tools/README.md +0 -73
  356. package/dist/node_modules/node-addon-api/tools/check-napi.js +0 -100
  357. package/dist/node_modules/node-addon-api/tools/clang-format.js +0 -67
  358. package/dist/node_modules/node-addon-api/tools/conversion.js +0 -309
  359. package/dist/node_modules/npmlog/CHANGELOG.md +0 -49
  360. package/dist/node_modules/npmlog/LICENSE +0 -15
  361. package/dist/node_modules/npmlog/README.md +0 -216
  362. package/dist/node_modules/npmlog/log.js +0 -309
  363. package/dist/node_modules/npmlog/package.json +0 -61
  364. package/dist/node_modules/number-is-nan/index.js +0 -4
  365. package/dist/node_modules/number-is-nan/license +0 -21
  366. package/dist/node_modules/number-is-nan/package.json +0 -67
  367. package/dist/node_modules/number-is-nan/readme.md +0 -28
  368. package/dist/node_modules/object-assign/index.js +0 -90
  369. package/dist/node_modules/object-assign/license +0 -21
  370. package/dist/node_modules/object-assign/package.json +0 -74
  371. package/dist/node_modules/object-assign/readme.md +0 -61
  372. package/dist/node_modules/once/LICENSE +0 -15
  373. package/dist/node_modules/once/README.md +0 -79
  374. package/dist/node_modules/once/once.js +0 -42
  375. package/dist/node_modules/once/package.json +0 -68
  376. package/dist/node_modules/prebuild-install/CHANGELOG.md +0 -81
  377. package/dist/node_modules/prebuild-install/CONTRIBUTING.md +0 -6
  378. package/dist/node_modules/prebuild-install/LICENSE +0 -21
  379. package/dist/node_modules/prebuild-install/README.md +0 -139
  380. package/dist/node_modules/prebuild-install/asset.js +0 -44
  381. package/dist/node_modules/prebuild-install/bin.js +0 -78
  382. package/dist/node_modules/prebuild-install/download.js +0 -142
  383. package/dist/node_modules/prebuild-install/error.js +0 -14
  384. package/dist/node_modules/prebuild-install/help.txt +0 -16
  385. package/dist/node_modules/prebuild-install/index.js +0 -1
  386. package/dist/node_modules/prebuild-install/log.js +0 -25
  387. package/dist/node_modules/prebuild-install/package.json +0 -127
  388. package/dist/node_modules/prebuild-install/proxy.js +0 -35
  389. package/dist/node_modules/prebuild-install/rc.js +0 -60
  390. package/dist/node_modules/prebuild-install/util.js +0 -143
  391. package/dist/node_modules/process-nextick-args/index.js +0 -45
  392. package/dist/node_modules/process-nextick-args/license.md +0 -19
  393. package/dist/node_modules/process-nextick-args/package.json +0 -50
  394. package/dist/node_modules/process-nextick-args/readme.md +0 -18
  395. package/dist/node_modules/pump/.travis.yml +0 -5
  396. package/dist/node_modules/pump/LICENSE +0 -21
  397. package/dist/node_modules/pump/README.md +0 -65
  398. package/dist/node_modules/pump/index.js +0 -82
  399. package/dist/node_modules/pump/package.json +0 -60
  400. package/dist/node_modules/pump/test-browser.js +0 -66
  401. package/dist/node_modules/pump/test-node.js +0 -53
  402. package/dist/node_modules/rc/LICENSE.APACHE2 +0 -15
  403. package/dist/node_modules/rc/LICENSE.BSD +0 -26
  404. package/dist/node_modules/rc/LICENSE.MIT +0 -24
  405. package/dist/node_modules/rc/README.md +0 -227
  406. package/dist/node_modules/rc/browser.js +0 -7
  407. package/dist/node_modules/rc/cli.js +0 -4
  408. package/dist/node_modules/rc/index.js +0 -53
  409. package/dist/node_modules/rc/lib/utils.js +0 -104
  410. package/dist/node_modules/rc/package.json +0 -64
  411. package/dist/node_modules/rc/test/ini.js +0 -16
  412. package/dist/node_modules/rc/test/nested-env-vars.js +0 -50
  413. package/dist/node_modules/rc/test/test.js +0 -59
  414. package/dist/node_modules/readable-stream/.travis.yml +0 -34
  415. package/dist/node_modules/readable-stream/CONTRIBUTING.md +0 -38
  416. package/dist/node_modules/readable-stream/GOVERNANCE.md +0 -136
  417. package/dist/node_modules/readable-stream/LICENSE +0 -47
  418. package/dist/node_modules/readable-stream/README.md +0 -58
  419. package/dist/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +0 -60
  420. package/dist/node_modules/readable-stream/duplex-browser.js +0 -1
  421. package/dist/node_modules/readable-stream/duplex.js +0 -1
  422. package/dist/node_modules/readable-stream/lib/_stream_duplex.js +0 -131
  423. package/dist/node_modules/readable-stream/lib/_stream_passthrough.js +0 -47
  424. package/dist/node_modules/readable-stream/lib/_stream_readable.js +0 -1019
  425. package/dist/node_modules/readable-stream/lib/_stream_transform.js +0 -214
  426. package/dist/node_modules/readable-stream/lib/_stream_writable.js +0 -687
  427. package/dist/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
  428. package/dist/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -74
  429. package/dist/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  430. package/dist/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  431. package/dist/node_modules/readable-stream/package.json +0 -81
  432. package/dist/node_modules/readable-stream/passthrough.js +0 -1
  433. package/dist/node_modules/readable-stream/readable-browser.js +0 -7
  434. package/dist/node_modules/readable-stream/readable.js +0 -19
  435. package/dist/node_modules/readable-stream/transform.js +0 -1
  436. package/dist/node_modules/readable-stream/writable-browser.js +0 -1
  437. package/dist/node_modules/readable-stream/writable.js +0 -8
  438. package/dist/node_modules/safe-buffer/LICENSE +0 -21
  439. package/dist/node_modules/safe-buffer/README.md +0 -584
  440. package/dist/node_modules/safe-buffer/index.d.ts +0 -187
  441. package/dist/node_modules/safe-buffer/index.js +0 -62
  442. package/dist/node_modules/safe-buffer/package.json +0 -64
  443. package/dist/node_modules/semver/CHANGELOG.md +0 -111
  444. package/dist/node_modules/semver/LICENSE +0 -15
  445. package/dist/node_modules/semver/README.md +0 -566
  446. package/dist/node_modules/semver/bin/semver.js +0 -173
  447. package/dist/node_modules/semver/classes/comparator.js +0 -135
  448. package/dist/node_modules/semver/classes/index.js +0 -5
  449. package/dist/node_modules/semver/classes/range.js +0 -510
  450. package/dist/node_modules/semver/classes/semver.js +0 -287
  451. package/dist/node_modules/semver/functions/clean.js +0 -6
  452. package/dist/node_modules/semver/functions/cmp.js +0 -48
  453. package/dist/node_modules/semver/functions/coerce.js +0 -51
  454. package/dist/node_modules/semver/functions/compare-build.js +0 -7
  455. package/dist/node_modules/semver/functions/compare-loose.js +0 -3
  456. package/dist/node_modules/semver/functions/compare.js +0 -5
  457. package/dist/node_modules/semver/functions/diff.js +0 -23
  458. package/dist/node_modules/semver/functions/eq.js +0 -3
  459. package/dist/node_modules/semver/functions/gt.js +0 -3
  460. package/dist/node_modules/semver/functions/gte.js +0 -3
  461. package/dist/node_modules/semver/functions/inc.js +0 -15
  462. package/dist/node_modules/semver/functions/lt.js +0 -3
  463. package/dist/node_modules/semver/functions/lte.js +0 -3
  464. package/dist/node_modules/semver/functions/major.js +0 -3
  465. package/dist/node_modules/semver/functions/minor.js +0 -3
  466. package/dist/node_modules/semver/functions/neq.js +0 -3
  467. package/dist/node_modules/semver/functions/parse.js +0 -33
  468. package/dist/node_modules/semver/functions/patch.js +0 -3
  469. package/dist/node_modules/semver/functions/prerelease.js +0 -6
  470. package/dist/node_modules/semver/functions/rcompare.js +0 -3
  471. package/dist/node_modules/semver/functions/rsort.js +0 -3
  472. package/dist/node_modules/semver/functions/satisfies.js +0 -10
  473. package/dist/node_modules/semver/functions/sort.js +0 -3
  474. package/dist/node_modules/semver/functions/valid.js +0 -6
  475. package/dist/node_modules/semver/index.js +0 -48
  476. package/dist/node_modules/semver/internal/constants.js +0 -17
  477. package/dist/node_modules/semver/internal/debug.js +0 -9
  478. package/dist/node_modules/semver/internal/identifiers.js +0 -23
  479. package/dist/node_modules/semver/internal/parse-options.js +0 -11
  480. package/dist/node_modules/semver/internal/re.js +0 -182
  481. package/dist/node_modules/semver/package.json +0 -73
  482. package/dist/node_modules/semver/preload.js +0 -2
  483. package/dist/node_modules/semver/range.bnf +0 -16
  484. package/dist/node_modules/semver/ranges/gtr.js +0 -4
  485. package/dist/node_modules/semver/ranges/intersects.js +0 -7
  486. package/dist/node_modules/semver/ranges/ltr.js +0 -4
  487. package/dist/node_modules/semver/ranges/max-satisfying.js +0 -25
  488. package/dist/node_modules/semver/ranges/min-satisfying.js +0 -24
  489. package/dist/node_modules/semver/ranges/min-version.js +0 -60
  490. package/dist/node_modules/semver/ranges/outside.js +0 -80
  491. package/dist/node_modules/semver/ranges/simplify.js +0 -44
  492. package/dist/node_modules/semver/ranges/subset.js +0 -222
  493. package/dist/node_modules/semver/ranges/to-comparators.js +0 -8
  494. package/dist/node_modules/semver/ranges/valid.js +0 -11
  495. package/dist/node_modules/set-blocking/CHANGELOG.md +0 -26
  496. package/dist/node_modules/set-blocking/LICENSE.txt +0 -14
  497. package/dist/node_modules/set-blocking/README.md +0 -31
  498. package/dist/node_modules/set-blocking/index.js +0 -7
  499. package/dist/node_modules/set-blocking/package.json +0 -70
  500. package/dist/node_modules/sharp/LICENSE +0 -191
  501. package/dist/node_modules/sharp/README.md +0 -117
  502. package/dist/node_modules/sharp/binding.gyp +0 -230
  503. package/dist/node_modules/sharp/build/Release/sharp.node +0 -0
  504. package/dist/node_modules/sharp/install/can-compile.js +0 -11
  505. package/dist/node_modules/sharp/install/dll-copy.js +0 -37
  506. package/dist/node_modules/sharp/install/libvips.js +0 -180
  507. package/dist/node_modules/sharp/lib/agent.js +0 -40
  508. package/dist/node_modules/sharp/lib/channel.js +0 -167
  509. package/dist/node_modules/sharp/lib/colour.js +0 -130
  510. package/dist/node_modules/sharp/lib/composite.js +0 -178
  511. package/dist/node_modules/sharp/lib/constructor.js +0 -392
  512. package/dist/node_modules/sharp/lib/index.js +0 -13
  513. package/dist/node_modules/sharp/lib/input.js +0 -429
  514. package/dist/node_modules/sharp/lib/is.js +0 -129
  515. package/dist/node_modules/sharp/lib/libvips.js +0 -123
  516. package/dist/node_modules/sharp/lib/operation.js +0 -648
  517. package/dist/node_modules/sharp/lib/output.js +0 -1035
  518. package/dist/node_modules/sharp/lib/platform.js +0 -25
  519. package/dist/node_modules/sharp/lib/resize.js +0 -454
  520. package/dist/node_modules/sharp/lib/utility.js +0 -179
  521. package/dist/node_modules/sharp/package.json +0 -427
  522. package/dist/node_modules/sharp/src/common.cc +0 -827
  523. package/dist/node_modules/sharp/src/common.h +0 -308
  524. package/dist/node_modules/sharp/src/libvips/cplusplus/VConnection.cpp +0 -178
  525. package/dist/node_modules/sharp/src/libvips/cplusplus/VError.cpp +0 -50
  526. package/dist/node_modules/sharp/src/libvips/cplusplus/VImage.cpp +0 -1467
  527. package/dist/node_modules/sharp/src/libvips/cplusplus/VInterpolate.cpp +0 -76
  528. package/dist/node_modules/sharp/src/libvips/cplusplus/vips-operators.cpp +0 -3526
  529. package/dist/node_modules/sharp/src/metadata.cc +0 -271
  530. package/dist/node_modules/sharp/src/metadata.h +0 -90
  531. package/dist/node_modules/sharp/src/operations.cc +0 -285
  532. package/dist/node_modules/sharp/src/operations.h +0 -102
  533. package/dist/node_modules/sharp/src/pipeline.cc +0 -1516
  534. package/dist/node_modules/sharp/src/pipeline.h +0 -325
  535. package/dist/node_modules/sharp/src/sharp.cc +0 -52
  536. package/dist/node_modules/sharp/src/stats.cc +0 -193
  537. package/dist/node_modules/sharp/src/stats.h +0 -70
  538. package/dist/node_modules/sharp/src/utilities.cc +0 -243
  539. package/dist/node_modules/sharp/src/utilities.h +0 -29
  540. package/dist/node_modules/sharp/vendor/8.10.6/THIRD-PARTY-NOTICES.md +0 -42
  541. package/dist/node_modules/sharp/vendor/8.10.6/lib/libvips-cpp.so.42 +0 -0
  542. package/dist/node_modules/sharp/vendor/8.10.6/platform.json +0 -1
  543. package/dist/node_modules/sharp/vendor/8.10.6/versions.json +0 -31
  544. package/dist/node_modules/signal-exit/LICENSE.txt +0 -16
  545. package/dist/node_modules/signal-exit/README.md +0 -39
  546. package/dist/node_modules/signal-exit/index.js +0 -200
  547. package/dist/node_modules/signal-exit/package.json +0 -66
  548. package/dist/node_modules/signal-exit/signals.js +0 -53
  549. package/dist/node_modules/simple-concat/.travis.yml +0 -3
  550. package/dist/node_modules/simple-concat/LICENSE +0 -20
  551. package/dist/node_modules/simple-concat/README.md +0 -44
  552. package/dist/node_modules/simple-concat/index.js +0 -15
  553. package/dist/node_modules/simple-concat/package.json +0 -72
  554. package/dist/node_modules/simple-concat/test/basic.js +0 -41
  555. package/dist/node_modules/simple-get/LICENSE +0 -20
  556. package/dist/node_modules/simple-get/README.md +0 -319
  557. package/dist/node_modules/simple-get/index.js +0 -99
  558. package/dist/node_modules/simple-get/package.json +0 -79
  559. package/dist/node_modules/simple-swizzle/LICENSE +0 -21
  560. package/dist/node_modules/simple-swizzle/README.md +0 -39
  561. package/dist/node_modules/simple-swizzle/index.js +0 -29
  562. package/dist/node_modules/simple-swizzle/package.json +0 -71
  563. package/dist/node_modules/string-width/index.js +0 -37
  564. package/dist/node_modules/string-width/license +0 -21
  565. package/dist/node_modules/string-width/package.json +0 -89
  566. package/dist/node_modules/string-width/readme.md +0 -42
  567. package/dist/node_modules/string_decoder/.travis.yml +0 -50
  568. package/dist/node_modules/string_decoder/LICENSE +0 -48
  569. package/dist/node_modules/string_decoder/README.md +0 -47
  570. package/dist/node_modules/string_decoder/lib/string_decoder.js +0 -296
  571. package/dist/node_modules/string_decoder/package.json +0 -61
  572. package/dist/node_modules/strip-ansi/index.js +0 -6
  573. package/dist/node_modules/strip-ansi/license +0 -21
  574. package/dist/node_modules/strip-ansi/package.json +0 -102
  575. package/dist/node_modules/strip-ansi/readme.md +0 -33
  576. package/dist/node_modules/strip-json-comments/index.js +0 -70
  577. package/dist/node_modules/strip-json-comments/license +0 -21
  578. package/dist/node_modules/strip-json-comments/package.json +0 -74
  579. package/dist/node_modules/strip-json-comments/readme.md +0 -64
  580. package/dist/node_modules/tar-fs/.travis.yml +0 -6
  581. package/dist/node_modules/tar-fs/LICENSE +0 -21
  582. package/dist/node_modules/tar-fs/README.md +0 -165
  583. package/dist/node_modules/tar-fs/index.js +0 -351
  584. package/dist/node_modules/tar-fs/package.json +0 -69
  585. package/dist/node_modules/tar-fs/test/fixtures/a/hello.txt +0 -1
  586. package/dist/node_modules/tar-fs/test/fixtures/b/a/test.txt +0 -1
  587. package/dist/node_modules/tar-fs/test/fixtures/d/file1 +0 -0
  588. package/dist/node_modules/tar-fs/test/fixtures/d/file2 +0 -0
  589. package/dist/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 +0 -0
  590. package/dist/node_modules/tar-fs/test/fixtures/d/sub-files/file3 +0 -0
  591. package/dist/node_modules/tar-fs/test/fixtures/d/sub-files/file4 +0 -0
  592. package/dist/node_modules/tar-fs/test/fixtures/e/directory/.ignore +0 -0
  593. package/dist/node_modules/tar-fs/test/fixtures/e/file +0 -0
  594. package/dist/node_modules/tar-fs/test/fixtures/invalid.tar +0 -0
  595. package/dist/node_modules/tar-fs/test/index.js +0 -346
  596. package/dist/node_modules/tar-stream/LICENSE +0 -21
  597. package/dist/node_modules/tar-stream/README.md +0 -168
  598. package/dist/node_modules/tar-stream/extract.js +0 -257
  599. package/dist/node_modules/tar-stream/headers.js +0 -295
  600. package/dist/node_modules/tar-stream/index.js +0 -2
  601. package/dist/node_modules/tar-stream/node_modules/readable-stream/CONTRIBUTING.md +0 -38
  602. package/dist/node_modules/tar-stream/node_modules/readable-stream/GOVERNANCE.md +0 -136
  603. package/dist/node_modules/tar-stream/node_modules/readable-stream/LICENSE +0 -47
  604. package/dist/node_modules/tar-stream/node_modules/readable-stream/README.md +0 -106
  605. package/dist/node_modules/tar-stream/node_modules/readable-stream/errors-browser.js +0 -127
  606. package/dist/node_modules/tar-stream/node_modules/readable-stream/errors.js +0 -116
  607. package/dist/node_modules/tar-stream/node_modules/readable-stream/experimentalWarning.js +0 -17
  608. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/_stream_duplex.js +0 -139
  609. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/_stream_passthrough.js +0 -39
  610. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/_stream_readable.js +0 -1124
  611. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/_stream_transform.js +0 -201
  612. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/_stream_writable.js +0 -697
  613. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -207
  614. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -210
  615. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -105
  616. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -104
  617. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
  618. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/from.js +0 -64
  619. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -97
  620. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/state.js +0 -27
  621. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  622. package/dist/node_modules/tar-stream/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  623. package/dist/node_modules/tar-stream/node_modules/readable-stream/package.json +0 -97
  624. package/dist/node_modules/tar-stream/node_modules/readable-stream/readable-browser.js +0 -9
  625. package/dist/node_modules/tar-stream/node_modules/readable-stream/readable.js +0 -16
  626. package/dist/node_modules/tar-stream/pack.js +0 -255
  627. package/dist/node_modules/tar-stream/package.json +0 -90
  628. package/dist/node_modules/tar-stream/sandbox.js +0 -11
  629. package/dist/node_modules/tunnel-agent/LICENSE +0 -55
  630. package/dist/node_modules/tunnel-agent/README.md +0 -4
  631. package/dist/node_modules/tunnel-agent/index.js +0 -244
  632. package/dist/node_modules/tunnel-agent/package.json +0 -56
  633. package/dist/node_modules/util-deprecate/History.md +0 -16
  634. package/dist/node_modules/util-deprecate/LICENSE +0 -24
  635. package/dist/node_modules/util-deprecate/README.md +0 -53
  636. package/dist/node_modules/util-deprecate/browser.js +0 -67
  637. package/dist/node_modules/util-deprecate/node.js +0 -6
  638. package/dist/node_modules/util-deprecate/package.json +0 -58
  639. package/dist/node_modules/wide-align/LICENSE +0 -14
  640. package/dist/node_modules/wide-align/README.md +0 -47
  641. package/dist/node_modules/wide-align/align.js +0 -65
  642. package/dist/node_modules/wide-align/package.json +0 -66
  643. package/dist/node_modules/wrappy/LICENSE +0 -15
  644. package/dist/node_modules/wrappy/README.md +0 -36
  645. package/dist/node_modules/wrappy/package.json +0 -58
  646. package/dist/node_modules/wrappy/wrappy.js +0 -33
  647. package/dist/node_modules/yallist/LICENSE +0 -15
  648. package/dist/node_modules/yallist/README.md +0 -204
  649. package/dist/node_modules/yallist/iterator.js +0 -8
  650. package/dist/node_modules/yallist/package.json +0 -62
  651. package/dist/node_modules/yallist/yallist.js +0 -426
  652. package/dist/package-lock.json +0 -507
  653. package/dist/package.json +0 -63
  654. package/dist/static/expected_tile_2193_153_255_z7.png +0 -0
  655. package/dist/static/expected_tile_NZTM2000Quad_30_33_z6.png +0 -0
  656. package/dist/static/expected_tile_WebMercatorQuad_252_156_z8.png +0 -0
@@ -1,2727 +0,0 @@
1
- #ifndef SRC_NAPI_H_
2
- #define SRC_NAPI_H_
3
-
4
- #include <node_api.h>
5
- #include <functional>
6
- #include <initializer_list>
7
- #include <memory>
8
- #include <mutex>
9
- #include <string>
10
- #include <vector>
11
-
12
- // VS2015 RTM has bugs with constexpr, so require min of VS2015 Update 3 (known good version)
13
- #if !defined(_MSC_VER) || _MSC_FULL_VER >= 190024210
14
- #define NAPI_HAS_CONSTEXPR 1
15
- #endif
16
-
17
- // VS2013 does not support char16_t literal strings, so we'll work around it using wchar_t strings
18
- // and casting them. This is safe as long as the character sizes are the same.
19
- #if defined(_MSC_VER) && _MSC_VER <= 1800
20
- static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16_t and wchar_t");
21
- #define NAPI_WIDE_TEXT(x) reinterpret_cast<char16_t*>(L ## x)
22
- #else
23
- #define NAPI_WIDE_TEXT(x) u ## x
24
- #endif
25
-
26
- // If C++ exceptions are not explicitly enabled or disabled, enable them
27
- // if exceptions were enabled in the compiler settings.
28
- #if !defined(NAPI_CPP_EXCEPTIONS) && !defined(NAPI_DISABLE_CPP_EXCEPTIONS)
29
- #if defined(_CPPUNWIND) || defined (__EXCEPTIONS)
30
- #define NAPI_CPP_EXCEPTIONS
31
- #else
32
- #error Exception support not detected. \
33
- Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS.
34
- #endif
35
- #endif
36
-
37
- #ifdef _NOEXCEPT
38
- #define NAPI_NOEXCEPT _NOEXCEPT
39
- #else
40
- #define NAPI_NOEXCEPT noexcept
41
- #endif
42
-
43
- #ifdef NAPI_CPP_EXCEPTIONS
44
-
45
- // When C++ exceptions are enabled, Errors are thrown directly. There is no need
46
- // to return anything after the throw statements. The variadic parameter is an
47
- // optional return value that is ignored.
48
- // We need _VOID versions of the macros to avoid warnings resulting from
49
- // leaving the NAPI_THROW_* `...` argument empty.
50
-
51
- #define NAPI_THROW(e, ...) throw e
52
- #define NAPI_THROW_VOID(e) throw e
53
-
54
- #define NAPI_THROW_IF_FAILED(env, status, ...) \
55
- if ((status) != napi_ok) throw Napi::Error::New(env);
56
-
57
- #define NAPI_THROW_IF_FAILED_VOID(env, status) \
58
- if ((status) != napi_ok) throw Napi::Error::New(env);
59
-
60
- #else // NAPI_CPP_EXCEPTIONS
61
-
62
- // When C++ exceptions are disabled, Errors are thrown as JavaScript exceptions,
63
- // which are pending until the callback returns to JS. The variadic parameter
64
- // is an optional return value; usually it is an empty result.
65
- // We need _VOID versions of the macros to avoid warnings resulting from
66
- // leaving the NAPI_THROW_* `...` argument empty.
67
-
68
- #define NAPI_THROW(e, ...) \
69
- do { \
70
- (e).ThrowAsJavaScriptException(); \
71
- return __VA_ARGS__; \
72
- } while (0)
73
-
74
- #define NAPI_THROW_VOID(e) \
75
- do { \
76
- (e).ThrowAsJavaScriptException(); \
77
- return; \
78
- } while (0)
79
-
80
- #define NAPI_THROW_IF_FAILED(env, status, ...) \
81
- if ((status) != napi_ok) { \
82
- Napi::Error::New(env).ThrowAsJavaScriptException(); \
83
- return __VA_ARGS__; \
84
- }
85
-
86
- #define NAPI_THROW_IF_FAILED_VOID(env, status) \
87
- if ((status) != napi_ok) { \
88
- Napi::Error::New(env).ThrowAsJavaScriptException(); \
89
- return; \
90
- }
91
-
92
- #endif // NAPI_CPP_EXCEPTIONS
93
-
94
- # define NAPI_DISALLOW_ASSIGN(CLASS) void operator=(const CLASS&) = delete;
95
- # define NAPI_DISALLOW_COPY(CLASS) CLASS(const CLASS&) = delete;
96
-
97
- #define NAPI_DISALLOW_ASSIGN_COPY(CLASS) \
98
- NAPI_DISALLOW_ASSIGN(CLASS) \
99
- NAPI_DISALLOW_COPY(CLASS)
100
-
101
- #define NAPI_FATAL_IF_FAILED(status, location, message) \
102
- do { \
103
- if ((status) != napi_ok) { \
104
- Napi::Error::Fatal((location), (message)); \
105
- } \
106
- } while (0)
107
-
108
- ////////////////////////////////////////////////////////////////////////////////
109
- /// Node-API C++ Wrapper Classes
110
- ///
111
- /// These classes wrap the "Node-API" ABI-stable C APIs for Node.js, providing a
112
- /// C++ object model and C++ exception-handling semantics with low overhead.
113
- /// The wrappers are all header-only so that they do not affect the ABI.
114
- ////////////////////////////////////////////////////////////////////////////////
115
- namespace Napi {
116
-
117
- // Forward declarations
118
- class Env;
119
- class Value;
120
- class Boolean;
121
- class Number;
122
- #if NAPI_VERSION > 5
123
- class BigInt;
124
- #endif // NAPI_VERSION > 5
125
- #if (NAPI_VERSION > 4)
126
- class Date;
127
- #endif
128
- class String;
129
- class Object;
130
- class Array;
131
- class ArrayBuffer;
132
- class Function;
133
- class Error;
134
- class PropertyDescriptor;
135
- class CallbackInfo;
136
- class TypedArray;
137
- template <typename T> class TypedArrayOf;
138
-
139
- using Int8Array =
140
- TypedArrayOf<int8_t>; ///< Typed-array of signed 8-bit integers
141
- using Uint8Array =
142
- TypedArrayOf<uint8_t>; ///< Typed-array of unsigned 8-bit integers
143
- using Int16Array =
144
- TypedArrayOf<int16_t>; ///< Typed-array of signed 16-bit integers
145
- using Uint16Array =
146
- TypedArrayOf<uint16_t>; ///< Typed-array of unsigned 16-bit integers
147
- using Int32Array =
148
- TypedArrayOf<int32_t>; ///< Typed-array of signed 32-bit integers
149
- using Uint32Array =
150
- TypedArrayOf<uint32_t>; ///< Typed-array of unsigned 32-bit integers
151
- using Float32Array =
152
- TypedArrayOf<float>; ///< Typed-array of 32-bit floating-point values
153
- using Float64Array =
154
- TypedArrayOf<double>; ///< Typed-array of 64-bit floating-point values
155
- #if NAPI_VERSION > 5
156
- using BigInt64Array =
157
- TypedArrayOf<int64_t>; ///< Typed array of signed 64-bit integers
158
- using BigUint64Array =
159
- TypedArrayOf<uint64_t>; ///< Typed array of unsigned 64-bit integers
160
- #endif // NAPI_VERSION > 5
161
-
162
- /// Defines the signature of a Node-API C++ module's registration callback
163
- /// (init) function.
164
- using ModuleRegisterCallback = Object (*)(Env env, Object exports);
165
-
166
- class MemoryManagement;
167
-
168
- /// Environment for Node-API values and operations.
169
- ///
170
- /// All Node-API values and operations must be associated with an environment.
171
- /// An environment instance is always provided to callback functions; that
172
- /// environment must then be used for any creation of Node-API values or other
173
- /// Node-API operations within the callback. (Many methods infer the
174
- /// environment from the `this` instance that the method is called on.)
175
- ///
176
- /// In the future, multiple environments per process may be supported,
177
- /// although current implementations only support one environment per process.
178
- ///
179
- /// In the V8 JavaScript engine, a Node-API environment approximately
180
- /// corresponds to an Isolate.
181
- class Env {
182
- #if NAPI_VERSION > 5
183
- private:
184
- template <typename T> static void DefaultFini(Env, T* data);
185
- template <typename DataType, typename HintType>
186
- static void DefaultFiniWithHint(Env, DataType* data, HintType* hint);
187
- #endif // NAPI_VERSION > 5
188
- public:
189
- Env(napi_env env);
190
-
191
- operator napi_env() const;
192
-
193
- Object Global() const;
194
- Value Undefined() const;
195
- Value Null() const;
196
-
197
- bool IsExceptionPending() const;
198
- Error GetAndClearPendingException();
199
-
200
- Value RunScript(const char* utf8script);
201
- Value RunScript(const std::string& utf8script);
202
- Value RunScript(String script);
203
-
204
- #if NAPI_VERSION > 5
205
- template <typename T> T* GetInstanceData();
206
-
207
- template <typename T> using Finalizer = void (*)(Env, T*);
208
- template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
209
- void SetInstanceData(T* data);
210
-
211
- template <typename DataType, typename HintType>
212
- using FinalizerWithHint = void (*)(Env, DataType*, HintType*);
213
- template <typename DataType,
214
- typename HintType,
215
- FinalizerWithHint<DataType, HintType> fini =
216
- Env::DefaultFiniWithHint<DataType, HintType>>
217
- void SetInstanceData(DataType* data, HintType* hint);
218
- #endif // NAPI_VERSION > 5
219
-
220
- private:
221
- napi_env _env;
222
- };
223
-
224
- /// A JavaScript value of unknown type.
225
- ///
226
- /// For type-specific operations, convert to one of the Value subclasses using a `To*` or `As()`
227
- /// method. The `To*` methods do type coercion; the `As()` method does not.
228
- ///
229
- /// Napi::Value value = ...
230
- /// if (!value.IsString()) throw Napi::TypeError::New(env, "Invalid arg...");
231
- /// Napi::String str = value.As<Napi::String>(); // Cast to a string value
232
- ///
233
- /// Napi::Value anotherValue = ...
234
- /// bool isTruthy = anotherValue.ToBoolean(); // Coerce to a boolean value
235
- class Value {
236
- public:
237
- Value(); ///< Creates a new _empty_ Value instance.
238
- Value(napi_env env,
239
- napi_value value); ///< Wraps a Node-API value primitive.
240
-
241
- /// Creates a JS value from a C++ primitive.
242
- ///
243
- /// `value` may be any of:
244
- /// - bool
245
- /// - Any integer type
246
- /// - Any floating point type
247
- /// - const char* (encoded using UTF-8, null-terminated)
248
- /// - const char16_t* (encoded using UTF-16-LE, null-terminated)
249
- /// - std::string (encoded using UTF-8)
250
- /// - std::u16string
251
- /// - napi::Value
252
- /// - napi_value
253
- template <typename T>
254
- static Value From(napi_env env, const T& value);
255
-
256
- /// Converts to a Node-API value primitive.
257
- ///
258
- /// If the instance is _empty_, this returns `nullptr`.
259
- operator napi_value() const;
260
-
261
- /// Tests if this value strictly equals another value.
262
- bool operator ==(const Value& other) const;
263
-
264
- /// Tests if this value does not strictly equal another value.
265
- bool operator !=(const Value& other) const;
266
-
267
- /// Tests if this value strictly equals another value.
268
- bool StrictEquals(const Value& other) const;
269
-
270
- /// Gets the environment the value is associated with.
271
- Napi::Env Env() const;
272
-
273
- /// Checks if the value is empty (uninitialized).
274
- ///
275
- /// An empty value is invalid, and most attempts to perform an operation on an empty value
276
- /// will result in an exception. Note an empty value is distinct from JavaScript `null` or
277
- /// `undefined`, which are valid values.
278
- ///
279
- /// When C++ exceptions are disabled at compile time, a method with a `Value` return type may
280
- /// return an empty value to indicate a pending exception. So when not using C++ exceptions,
281
- /// callers should check whether the value is empty before attempting to use it.
282
- bool IsEmpty() const;
283
-
284
- napi_valuetype Type() const; ///< Gets the type of the value.
285
-
286
- bool IsUndefined() const; ///< Tests if a value is an undefined JavaScript value.
287
- bool IsNull() const; ///< Tests if a value is a null JavaScript value.
288
- bool IsBoolean() const; ///< Tests if a value is a JavaScript boolean.
289
- bool IsNumber() const; ///< Tests if a value is a JavaScript number.
290
- #if NAPI_VERSION > 5
291
- bool IsBigInt() const; ///< Tests if a value is a JavaScript bigint.
292
- #endif // NAPI_VERSION > 5
293
- #if (NAPI_VERSION > 4)
294
- bool IsDate() const; ///< Tests if a value is a JavaScript date.
295
- #endif
296
- bool IsString() const; ///< Tests if a value is a JavaScript string.
297
- bool IsSymbol() const; ///< Tests if a value is a JavaScript symbol.
298
- bool IsArray() const; ///< Tests if a value is a JavaScript array.
299
- bool IsArrayBuffer() const; ///< Tests if a value is a JavaScript array buffer.
300
- bool IsTypedArray() const; ///< Tests if a value is a JavaScript typed array.
301
- bool IsObject() const; ///< Tests if a value is a JavaScript object.
302
- bool IsFunction() const; ///< Tests if a value is a JavaScript function.
303
- bool IsPromise() const; ///< Tests if a value is a JavaScript promise.
304
- bool IsDataView() const; ///< Tests if a value is a JavaScript data view.
305
- bool IsBuffer() const; ///< Tests if a value is a Node buffer.
306
- bool IsExternal() const; ///< Tests if a value is a pointer to external data.
307
-
308
- /// Casts to another type of `Napi::Value`, when the actual type is known or assumed.
309
- ///
310
- /// This conversion does NOT coerce the type. Calling any methods inappropriate for the actual
311
- /// value type will throw `Napi::Error`.
312
- template <typename T> T As() const;
313
-
314
- Boolean ToBoolean() const; ///< Coerces a value to a JavaScript boolean.
315
- Number ToNumber() const; ///< Coerces a value to a JavaScript number.
316
- String ToString() const; ///< Coerces a value to a JavaScript string.
317
- Object ToObject() const; ///< Coerces a value to a JavaScript object.
318
-
319
- protected:
320
- /// !cond INTERNAL
321
- napi_env _env;
322
- napi_value _value;
323
- /// !endcond
324
- };
325
-
326
- /// A JavaScript boolean value.
327
- class Boolean : public Value {
328
- public:
329
- static Boolean New(napi_env env, ///< Node-API environment
330
- bool value ///< Boolean value
331
- );
332
-
333
- Boolean(); ///< Creates a new _empty_ Boolean instance.
334
- Boolean(napi_env env,
335
- napi_value value); ///< Wraps a Node-API value primitive.
336
-
337
- operator bool() const; ///< Converts a Boolean value to a boolean primitive.
338
- bool Value() const; ///< Converts a Boolean value to a boolean primitive.
339
- };
340
-
341
- /// A JavaScript number value.
342
- class Number : public Value {
343
- public:
344
- static Number New(napi_env env, ///< Node-API environment
345
- double value ///< Number value
346
- );
347
-
348
- Number(); ///< Creates a new _empty_ Number instance.
349
- Number(napi_env env,
350
- napi_value value); ///< Wraps a Node-API value primitive.
351
-
352
- operator int32_t()
353
- const; ///< Converts a Number value to a 32-bit signed integer value.
354
- operator uint32_t()
355
- const; ///< Converts a Number value to a 32-bit unsigned integer value.
356
- operator int64_t()
357
- const; ///< Converts a Number value to a 64-bit signed integer value.
358
- operator float()
359
- const; ///< Converts a Number value to a 32-bit floating-point value.
360
- operator double()
361
- const; ///< Converts a Number value to a 64-bit floating-point value.
362
-
363
- int32_t Int32Value()
364
- const; ///< Converts a Number value to a 32-bit signed integer value.
365
- uint32_t Uint32Value()
366
- const; ///< Converts a Number value to a 32-bit unsigned integer value.
367
- int64_t Int64Value()
368
- const; ///< Converts a Number value to a 64-bit signed integer value.
369
- float FloatValue()
370
- const; ///< Converts a Number value to a 32-bit floating-point value.
371
- double DoubleValue()
372
- const; ///< Converts a Number value to a 64-bit floating-point value.
373
- };
374
-
375
- #if NAPI_VERSION > 5
376
- /// A JavaScript bigint value.
377
- class BigInt : public Value {
378
- public:
379
- static BigInt New(napi_env env, ///< Node-API environment
380
- int64_t value ///< Number value
381
- );
382
- static BigInt New(napi_env env, ///< Node-API environment
383
- uint64_t value ///< Number value
384
- );
385
-
386
- /// Creates a new BigInt object using a specified sign bit and a
387
- /// specified list of digits/words.
388
- /// The resulting number is calculated as:
389
- /// (-1)^sign_bit * (words[0] * (2^64)^0 + words[1] * (2^64)^1 + ...)
390
- static BigInt New(napi_env env, ///< Node-API environment
391
- int sign_bit, ///< Sign bit. 1 if negative.
392
- size_t word_count, ///< Number of words in array
393
- const uint64_t* words ///< Array of words
394
- );
395
-
396
- BigInt(); ///< Creates a new _empty_ BigInt instance.
397
- BigInt(napi_env env,
398
- napi_value value); ///< Wraps a Node-API value primitive.
399
-
400
- int64_t Int64Value(bool* lossless)
401
- const; ///< Converts a BigInt value to a 64-bit signed integer value.
402
- uint64_t Uint64Value(bool* lossless)
403
- const; ///< Converts a BigInt value to a 64-bit unsigned integer value.
404
-
405
- size_t WordCount() const; ///< The number of 64-bit words needed to store
406
- ///< the result of ToWords().
407
-
408
- /// Writes the contents of this BigInt to a specified memory location.
409
- /// `sign_bit` must be provided and will be set to 1 if this BigInt is
410
- /// negative.
411
- /// `*word_count` has to be initialized to the length of the `words` array.
412
- /// Upon return, it will be set to the actual number of words that would
413
- /// be needed to store this BigInt (i.e. the return value of `WordCount()`).
414
- void ToWords(int* sign_bit, size_t* word_count, uint64_t* words);
415
- };
416
- #endif // NAPI_VERSION > 5
417
-
418
- #if (NAPI_VERSION > 4)
419
- /// A JavaScript date value.
420
- class Date : public Value {
421
- public:
422
- /// Creates a new Date value from a double primitive.
423
- static Date New(napi_env env, ///< Node-API environment
424
- double value ///< Number value
425
- );
426
-
427
- Date(); ///< Creates a new _empty_ Date instance.
428
- Date(napi_env env, napi_value value); ///< Wraps a Node-API value primitive.
429
- operator double() const; ///< Converts a Date value to double primitive
430
-
431
- double ValueOf() const; ///< Converts a Date value to a double primitive.
432
- };
433
- #endif
434
-
435
- /// A JavaScript string or symbol value (that can be used as a property name).
436
- class Name : public Value {
437
- public:
438
- Name(); ///< Creates a new _empty_ Name instance.
439
- Name(napi_env env,
440
- napi_value value); ///< Wraps a Node-API value primitive.
441
- };
442
-
443
- /// A JavaScript string value.
444
- class String : public Name {
445
- public:
446
- /// Creates a new String value from a UTF-8 encoded C++ string.
447
- static String New(napi_env env, ///< Node-API environment
448
- const std::string& value ///< UTF-8 encoded C++ string
449
- );
450
-
451
- /// Creates a new String value from a UTF-16 encoded C++ string.
452
- static String New(napi_env env, ///< Node-API environment
453
- const std::u16string& value ///< UTF-16 encoded C++ string
454
- );
455
-
456
- /// Creates a new String value from a UTF-8 encoded C string.
457
- static String New(
458
- napi_env env, ///< Node-API environment
459
- const char* value ///< UTF-8 encoded null-terminated C string
460
- );
461
-
462
- /// Creates a new String value from a UTF-16 encoded C string.
463
- static String New(
464
- napi_env env, ///< Node-API environment
465
- const char16_t* value ///< UTF-16 encoded null-terminated C string
466
- );
467
-
468
- /// Creates a new String value from a UTF-8 encoded C string with specified
469
- /// length.
470
- static String New(napi_env env, ///< Node-API environment
471
- const char* value, ///< UTF-8 encoded C string (not
472
- ///< necessarily null-terminated)
473
- size_t length ///< length of the string in bytes
474
- );
475
-
476
- /// Creates a new String value from a UTF-16 encoded C string with specified
477
- /// length.
478
- static String New(
479
- napi_env env, ///< Node-API environment
480
- const char16_t* value, ///< UTF-16 encoded C string (not necessarily
481
- ///< null-terminated)
482
- size_t length ///< Length of the string in 2-byte code units
483
- );
484
-
485
- /// Creates a new String based on the original object's type.
486
- ///
487
- /// `value` may be any of:
488
- /// - const char* (encoded using UTF-8, null-terminated)
489
- /// - const char16_t* (encoded using UTF-16-LE, null-terminated)
490
- /// - std::string (encoded using UTF-8)
491
- /// - std::u16string
492
- template <typename T>
493
- static String From(napi_env env, const T& value);
494
-
495
- String(); ///< Creates a new _empty_ String instance.
496
- String(napi_env env,
497
- napi_value value); ///< Wraps a Node-API value primitive.
498
-
499
- operator std::string()
500
- const; ///< Converts a String value to a UTF-8 encoded C++ string.
501
- operator std::u16string()
502
- const; ///< Converts a String value to a UTF-16 encoded C++ string.
503
- std::string Utf8Value()
504
- const; ///< Converts a String value to a UTF-8 encoded C++ string.
505
- std::u16string Utf16Value()
506
- const; ///< Converts a String value to a UTF-16 encoded C++ string.
507
- };
508
-
509
- /// A JavaScript symbol value.
510
- class Symbol : public Name {
511
- public:
512
- /// Creates a new Symbol value with an optional description.
513
- static Symbol New(
514
- napi_env env, ///< Node-API environment
515
- const char* description =
516
- nullptr ///< Optional UTF-8 encoded null-terminated C string
517
- /// describing the symbol
518
- );
519
-
520
- /// Creates a new Symbol value with a description.
521
- static Symbol New(
522
- napi_env env, ///< Node-API environment
523
- const std::string&
524
- description ///< UTF-8 encoded C++ string describing the symbol
525
- );
526
-
527
- /// Creates a new Symbol value with a description.
528
- static Symbol New(napi_env env, ///< Node-API environment
529
- String description ///< String value describing the symbol
530
- );
531
-
532
- /// Creates a new Symbol value with a description.
533
- static Symbol New(
534
- napi_env env, ///< Node-API environment
535
- napi_value description ///< String value describing the symbol
536
- );
537
-
538
- /// Get a public Symbol (e.g. Symbol.iterator).
539
- static Symbol WellKnown(napi_env, const std::string& name);
540
-
541
- Symbol(); ///< Creates a new _empty_ Symbol instance.
542
- Symbol(napi_env env,
543
- napi_value value); ///< Wraps a Node-API value primitive.
544
- };
545
-
546
- /// A JavaScript object value.
547
- class Object : public Value {
548
- public:
549
- /// Enables property and element assignments using indexing syntax.
550
- ///
551
- /// Example:
552
- ///
553
- /// Napi::Value propertyValue = object1['A'];
554
- /// object2['A'] = propertyValue;
555
- /// Napi::Value elementValue = array[0];
556
- /// array[1] = elementValue;
557
- template <typename Key>
558
- class PropertyLValue {
559
- public:
560
- /// Converts an L-value to a value.
561
- operator Value() const;
562
-
563
- /// Assigns a value to the property. The type of value can be
564
- /// anything supported by `Object::Set`.
565
- template <typename ValueType>
566
- PropertyLValue& operator =(ValueType value);
567
-
568
- private:
569
- PropertyLValue() = delete;
570
- PropertyLValue(Object object, Key key);
571
- napi_env _env;
572
- napi_value _object;
573
- Key _key;
574
-
575
- friend class Napi::Object;
576
- };
577
-
578
- /// Creates a new Object value.
579
- static Object New(napi_env env ///< Node-API environment
580
- );
581
-
582
- Object(); ///< Creates a new _empty_ Object instance.
583
- Object(napi_env env,
584
- napi_value value); ///< Wraps a Node-API value primitive.
585
-
586
- /// Gets or sets a named property.
587
- PropertyLValue<std::string> operator [](
588
- const char* utf8name ///< UTF-8 encoded null-terminated property name
589
- );
590
-
591
- /// Gets or sets a named property.
592
- PropertyLValue<std::string> operator [](
593
- const std::string& utf8name ///< UTF-8 encoded property name
594
- );
595
-
596
- /// Gets or sets an indexed property or array element.
597
- PropertyLValue<uint32_t> operator [](
598
- uint32_t index /// Property / element index
599
- );
600
-
601
- /// Gets a named property.
602
- Value operator [](
603
- const char* utf8name ///< UTF-8 encoded null-terminated property name
604
- ) const;
605
-
606
- /// Gets a named property.
607
- Value operator [](
608
- const std::string& utf8name ///< UTF-8 encoded property name
609
- ) const;
610
-
611
- /// Gets an indexed property or array element.
612
- Value operator [](
613
- uint32_t index ///< Property / element index
614
- ) const;
615
-
616
- /// Checks whether a property is present.
617
- bool Has(
618
- napi_value key ///< Property key primitive
619
- ) const;
620
-
621
- /// Checks whether a property is present.
622
- bool Has(
623
- Value key ///< Property key
624
- ) const;
625
-
626
- /// Checks whether a named property is present.
627
- bool Has(
628
- const char* utf8name ///< UTF-8 encoded null-terminated property name
629
- ) const;
630
-
631
- /// Checks whether a named property is present.
632
- bool Has(
633
- const std::string& utf8name ///< UTF-8 encoded property name
634
- ) const;
635
-
636
- /// Checks whether a own property is present.
637
- bool HasOwnProperty(
638
- napi_value key ///< Property key primitive
639
- ) const;
640
-
641
- /// Checks whether a own property is present.
642
- bool HasOwnProperty(
643
- Value key ///< Property key
644
- ) const;
645
-
646
- /// Checks whether a own property is present.
647
- bool HasOwnProperty(
648
- const char* utf8name ///< UTF-8 encoded null-terminated property name
649
- ) const;
650
-
651
- /// Checks whether a own property is present.
652
- bool HasOwnProperty(
653
- const std::string& utf8name ///< UTF-8 encoded property name
654
- ) const;
655
-
656
- /// Gets a property.
657
- Value Get(
658
- napi_value key ///< Property key primitive
659
- ) const;
660
-
661
- /// Gets a property.
662
- Value Get(
663
- Value key ///< Property key
664
- ) const;
665
-
666
- /// Gets a named property.
667
- Value Get(
668
- const char* utf8name ///< UTF-8 encoded null-terminated property name
669
- ) const;
670
-
671
- /// Gets a named property.
672
- Value Get(
673
- const std::string& utf8name ///< UTF-8 encoded property name
674
- ) const;
675
-
676
- /// Sets a property.
677
- template <typename ValueType>
678
- bool Set(napi_value key, ///< Property key primitive
679
- const ValueType& value ///< Property value primitive
680
- );
681
-
682
- /// Sets a property.
683
- template <typename ValueType>
684
- bool Set(Value key, ///< Property key
685
- const ValueType& value ///< Property value
686
- );
687
-
688
- /// Sets a named property.
689
- template <typename ValueType>
690
- bool Set(
691
- const char* utf8name, ///< UTF-8 encoded null-terminated property name
692
- const ValueType& value);
693
-
694
- /// Sets a named property.
695
- template <typename ValueType>
696
- bool Set(const std::string& utf8name, ///< UTF-8 encoded property name
697
- const ValueType& value ///< Property value primitive
698
- );
699
-
700
- /// Delete property.
701
- bool Delete(
702
- napi_value key ///< Property key primitive
703
- );
704
-
705
- /// Delete property.
706
- bool Delete(
707
- Value key ///< Property key
708
- );
709
-
710
- /// Delete property.
711
- bool Delete(
712
- const char* utf8name ///< UTF-8 encoded null-terminated property name
713
- );
714
-
715
- /// Delete property.
716
- bool Delete(
717
- const std::string& utf8name ///< UTF-8 encoded property name
718
- );
719
-
720
- /// Checks whether an indexed property is present.
721
- bool Has(
722
- uint32_t index ///< Property / element index
723
- ) const;
724
-
725
- /// Gets an indexed property or array element.
726
- Value Get(
727
- uint32_t index ///< Property / element index
728
- ) const;
729
-
730
- /// Sets an indexed property or array element.
731
- template <typename ValueType>
732
- bool Set(uint32_t index, ///< Property / element index
733
- const ValueType& value ///< Property value primitive
734
- );
735
-
736
- /// Deletes an indexed property or array element.
737
- bool Delete(
738
- uint32_t index ///< Property / element index
739
- );
740
-
741
- Array GetPropertyNames() const; ///< Get all property names
742
-
743
- /// Defines a property on the object.
744
- bool DefineProperty(
745
- const PropertyDescriptor&
746
- property ///< Descriptor for the property to be defined
747
- );
748
-
749
- /// Defines properties on the object.
750
- bool DefineProperties(
751
- const std::initializer_list<PropertyDescriptor>& properties
752
- ///< List of descriptors for the properties to be defined
753
- );
754
-
755
- /// Defines properties on the object.
756
- bool DefineProperties(
757
- const std::vector<PropertyDescriptor>& properties
758
- ///< Vector of descriptors for the properties to be defined
759
- );
760
-
761
- /// Checks if an object is an instance created by a constructor function.
762
- ///
763
- /// This is equivalent to the JavaScript `instanceof` operator.
764
- bool InstanceOf(
765
- const Function& constructor ///< Constructor function
766
- ) const;
767
-
768
- template <typename Finalizer, typename T>
769
- inline void AddFinalizer(Finalizer finalizeCallback, T* data);
770
-
771
- template <typename Finalizer, typename T, typename Hint>
772
- inline void AddFinalizer(Finalizer finalizeCallback,
773
- T* data,
774
- Hint* finalizeHint);
775
- #if NAPI_VERSION >= 8
776
- bool Freeze();
777
- bool Seal();
778
- #endif // NAPI_VERSION >= 8
779
- };
780
-
781
- template <typename T>
782
- class External : public Value {
783
- public:
784
- static External New(napi_env env, T* data);
785
-
786
- // Finalizer must implement `void operator()(Env env, T* data)`.
787
- template <typename Finalizer>
788
- static External New(napi_env env,
789
- T* data,
790
- Finalizer finalizeCallback);
791
- // Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`.
792
- template <typename Finalizer, typename Hint>
793
- static External New(napi_env env,
794
- T* data,
795
- Finalizer finalizeCallback,
796
- Hint* finalizeHint);
797
-
798
- External();
799
- External(napi_env env, napi_value value);
800
-
801
- T* Data() const;
802
- };
803
-
804
- class Array : public Object {
805
- public:
806
- static Array New(napi_env env);
807
- static Array New(napi_env env, size_t length);
808
-
809
- Array();
810
- Array(napi_env env, napi_value value);
811
-
812
- uint32_t Length() const;
813
- };
814
-
815
- /// A JavaScript array buffer value.
816
- class ArrayBuffer : public Object {
817
- public:
818
- /// Creates a new ArrayBuffer instance over a new automatically-allocated buffer.
819
- static ArrayBuffer New(
820
- napi_env env, ///< Node-API environment
821
- size_t byteLength ///< Length of the buffer to be allocated, in bytes
822
- );
823
-
824
- /// Creates a new ArrayBuffer instance, using an external buffer with
825
- /// specified byte length.
826
- static ArrayBuffer New(
827
- napi_env env, ///< Node-API environment
828
- void* externalData, ///< Pointer to the external buffer to be used by
829
- ///< the array
830
- size_t byteLength ///< Length of the external buffer to be used by the
831
- ///< array, in bytes
832
- );
833
-
834
- /// Creates a new ArrayBuffer instance, using an external buffer with
835
- /// specified byte length.
836
- template <typename Finalizer>
837
- static ArrayBuffer New(
838
- napi_env env, ///< Node-API environment
839
- void* externalData, ///< Pointer to the external buffer to be used by
840
- ///< the array
841
- size_t byteLength, ///< Length of the external buffer to be used by the
842
- ///< array,
843
- /// in bytes
844
- Finalizer finalizeCallback ///< Function to be called when the array
845
- ///< buffer is destroyed;
846
- /// must implement `void operator()(Env env,
847
- /// void* externalData)`
848
- );
849
-
850
- /// Creates a new ArrayBuffer instance, using an external buffer with
851
- /// specified byte length.
852
- template <typename Finalizer, typename Hint>
853
- static ArrayBuffer New(
854
- napi_env env, ///< Node-API environment
855
- void* externalData, ///< Pointer to the external buffer to be used by
856
- ///< the array
857
- size_t byteLength, ///< Length of the external buffer to be used by the
858
- ///< array,
859
- /// in bytes
860
- Finalizer finalizeCallback, ///< Function to be called when the array
861
- ///< buffer is destroyed;
862
- /// must implement `void operator()(Env
863
- /// env, void* externalData, Hint* hint)`
864
- Hint* finalizeHint ///< Hint (second parameter) to be passed to the
865
- ///< finalize callback
866
- );
867
-
868
- ArrayBuffer(); ///< Creates a new _empty_ ArrayBuffer instance.
869
- ArrayBuffer(napi_env env,
870
- napi_value value); ///< Wraps a Node-API value primitive.
871
-
872
- void* Data(); ///< Gets a pointer to the data buffer.
873
- size_t ByteLength(); ///< Gets the length of the array buffer in bytes.
874
-
875
- #if NAPI_VERSION >= 7
876
- bool IsDetached() const;
877
- void Detach();
878
- #endif // NAPI_VERSION >= 7
879
- };
880
-
881
- /// A JavaScript typed-array value with unknown array type.
882
- ///
883
- /// For type-specific operations, cast to a `TypedArrayOf<T>` instance using the `As()`
884
- /// method:
885
- ///
886
- /// Napi::TypedArray array = ...
887
- /// if (t.TypedArrayType() == napi_int32_array) {
888
- /// Napi::Int32Array int32Array = t.As<Napi::Int32Array>();
889
- /// }
890
- class TypedArray : public Object {
891
- public:
892
- TypedArray(); ///< Creates a new _empty_ TypedArray instance.
893
- TypedArray(napi_env env,
894
- napi_value value); ///< Wraps a Node-API value primitive.
895
-
896
- napi_typedarray_type TypedArrayType() const; ///< Gets the type of this typed-array.
897
- Napi::ArrayBuffer ArrayBuffer() const; ///< Gets the backing array buffer.
898
-
899
- uint8_t ElementSize() const; ///< Gets the size in bytes of one element in the array.
900
- size_t ElementLength() const; ///< Gets the number of elements in the array.
901
- size_t ByteOffset() const; ///< Gets the offset into the buffer where the array starts.
902
- size_t ByteLength() const; ///< Gets the length of the array in bytes.
903
-
904
- protected:
905
- /// !cond INTERNAL
906
- napi_typedarray_type _type;
907
- size_t _length;
908
-
909
- TypedArray(napi_env env, napi_value value, napi_typedarray_type type, size_t length);
910
-
911
- static const napi_typedarray_type unknown_array_type = static_cast<napi_typedarray_type>(-1);
912
-
913
- template <typename T>
914
- static
915
- #if defined(NAPI_HAS_CONSTEXPR)
916
- constexpr
917
- #endif
918
- napi_typedarray_type TypedArrayTypeForPrimitiveType() {
919
- return std::is_same<T, int8_t>::value ? napi_int8_array
920
- : std::is_same<T, uint8_t>::value ? napi_uint8_array
921
- : std::is_same<T, int16_t>::value ? napi_int16_array
922
- : std::is_same<T, uint16_t>::value ? napi_uint16_array
923
- : std::is_same<T, int32_t>::value ? napi_int32_array
924
- : std::is_same<T, uint32_t>::value ? napi_uint32_array
925
- : std::is_same<T, float>::value ? napi_float32_array
926
- : std::is_same<T, double>::value ? napi_float64_array
927
- #if NAPI_VERSION > 5
928
- : std::is_same<T, int64_t>::value ? napi_bigint64_array
929
- : std::is_same<T, uint64_t>::value ? napi_biguint64_array
930
- #endif // NAPI_VERSION > 5
931
- : unknown_array_type;
932
- }
933
- /// !endcond
934
- };
935
-
936
- /// A JavaScript typed-array value with known array type.
937
- ///
938
- /// Note while it is possible to create and access Uint8 "clamped" arrays using this class,
939
- /// the _clamping_ behavior is only applied in JavaScript.
940
- template <typename T>
941
- class TypedArrayOf : public TypedArray {
942
- public:
943
- /// Creates a new TypedArray instance over a new automatically-allocated array buffer.
944
- ///
945
- /// The array type parameter can normally be omitted (because it is inferred from the template
946
- /// parameter T), except when creating a "clamped" array:
947
- ///
948
- /// Uint8Array::New(env, length, napi_uint8_clamped_array)
949
- static TypedArrayOf New(
950
- napi_env env, ///< Node-API environment
951
- size_t elementLength, ///< Length of the created array, as a number of
952
- ///< elements
953
- #if defined(NAPI_HAS_CONSTEXPR)
954
- napi_typedarray_type type =
955
- TypedArray::TypedArrayTypeForPrimitiveType<T>()
956
- #else
957
- napi_typedarray_type type
958
- #endif
959
- ///< Type of array, if different from the default array type for the
960
- ///< template parameter T.
961
- );
962
-
963
- /// Creates a new TypedArray instance over a provided array buffer.
964
- ///
965
- /// The array type parameter can normally be omitted (because it is inferred from the template
966
- /// parameter T), except when creating a "clamped" array:
967
- ///
968
- /// Uint8Array::New(env, length, buffer, 0, napi_uint8_clamped_array)
969
- static TypedArrayOf New(
970
- napi_env env, ///< Node-API environment
971
- size_t elementLength, ///< Length of the created array, as a number of
972
- ///< elements
973
- Napi::ArrayBuffer arrayBuffer, ///< Backing array buffer instance to use
974
- size_t bufferOffset, ///< Offset into the array buffer where the
975
- ///< typed-array starts
976
- #if defined(NAPI_HAS_CONSTEXPR)
977
- napi_typedarray_type type =
978
- TypedArray::TypedArrayTypeForPrimitiveType<T>()
979
- #else
980
- napi_typedarray_type type
981
- #endif
982
- ///< Type of array, if different from the default array type for the
983
- ///< template parameter T.
984
- );
985
-
986
- TypedArrayOf(); ///< Creates a new _empty_ TypedArrayOf instance.
987
- TypedArrayOf(napi_env env,
988
- napi_value value); ///< Wraps a Node-API value primitive.
989
-
990
- T& operator [](size_t index); ///< Gets or sets an element in the array.
991
- const T& operator [](size_t index) const; ///< Gets an element in the array.
992
-
993
- /// Gets a pointer to the array's backing buffer.
994
- ///
995
- /// This is not necessarily the same as the `ArrayBuffer::Data()` pointer, because the
996
- /// typed-array may have a non-zero `ByteOffset()` into the `ArrayBuffer`.
997
- T* Data();
998
-
999
- /// Gets a pointer to the array's backing buffer.
1000
- ///
1001
- /// This is not necessarily the same as the `ArrayBuffer::Data()` pointer, because the
1002
- /// typed-array may have a non-zero `ByteOffset()` into the `ArrayBuffer`.
1003
- const T* Data() const;
1004
-
1005
- private:
1006
- T* _data;
1007
-
1008
- TypedArrayOf(napi_env env,
1009
- napi_value value,
1010
- napi_typedarray_type type,
1011
- size_t length,
1012
- T* data);
1013
- };
1014
-
1015
- /// The DataView provides a low-level interface for reading/writing multiple
1016
- /// number types in an ArrayBuffer irrespective of the platform's endianness.
1017
- class DataView : public Object {
1018
- public:
1019
- static DataView New(napi_env env,
1020
- Napi::ArrayBuffer arrayBuffer);
1021
- static DataView New(napi_env env,
1022
- Napi::ArrayBuffer arrayBuffer,
1023
- size_t byteOffset);
1024
- static DataView New(napi_env env,
1025
- Napi::ArrayBuffer arrayBuffer,
1026
- size_t byteOffset,
1027
- size_t byteLength);
1028
-
1029
- DataView(); ///< Creates a new _empty_ DataView instance.
1030
- DataView(napi_env env,
1031
- napi_value value); ///< Wraps a Node-API value primitive.
1032
-
1033
- Napi::ArrayBuffer ArrayBuffer() const; ///< Gets the backing array buffer.
1034
- size_t ByteOffset() const; ///< Gets the offset into the buffer where the array starts.
1035
- size_t ByteLength() const; ///< Gets the length of the array in bytes.
1036
-
1037
- void* Data() const;
1038
-
1039
- float GetFloat32(size_t byteOffset) const;
1040
- double GetFloat64(size_t byteOffset) const;
1041
- int8_t GetInt8(size_t byteOffset) const;
1042
- int16_t GetInt16(size_t byteOffset) const;
1043
- int32_t GetInt32(size_t byteOffset) const;
1044
- uint8_t GetUint8(size_t byteOffset) const;
1045
- uint16_t GetUint16(size_t byteOffset) const;
1046
- uint32_t GetUint32(size_t byteOffset) const;
1047
-
1048
- void SetFloat32(size_t byteOffset, float value) const;
1049
- void SetFloat64(size_t byteOffset, double value) const;
1050
- void SetInt8(size_t byteOffset, int8_t value) const;
1051
- void SetInt16(size_t byteOffset, int16_t value) const;
1052
- void SetInt32(size_t byteOffset, int32_t value) const;
1053
- void SetUint8(size_t byteOffset, uint8_t value) const;
1054
- void SetUint16(size_t byteOffset, uint16_t value) const;
1055
- void SetUint32(size_t byteOffset, uint32_t value) const;
1056
-
1057
- private:
1058
- template <typename T>
1059
- T ReadData(size_t byteOffset) const;
1060
-
1061
- template <typename T>
1062
- void WriteData(size_t byteOffset, T value) const;
1063
-
1064
- void* _data;
1065
- size_t _length;
1066
- };
1067
-
1068
- class Function : public Object {
1069
- public:
1070
- using VoidCallback = void (*)(const CallbackInfo& info);
1071
- using Callback = Value (*)(const CallbackInfo& info);
1072
-
1073
- template <VoidCallback cb>
1074
- static Function New(napi_env env,
1075
- const char* utf8name = nullptr,
1076
- void* data = nullptr);
1077
-
1078
- template <Callback cb>
1079
- static Function New(napi_env env,
1080
- const char* utf8name = nullptr,
1081
- void* data = nullptr);
1082
-
1083
- template <VoidCallback cb>
1084
- static Function New(napi_env env,
1085
- const std::string& utf8name,
1086
- void* data = nullptr);
1087
-
1088
- template <Callback cb>
1089
- static Function New(napi_env env,
1090
- const std::string& utf8name,
1091
- void* data = nullptr);
1092
-
1093
- /// Callable must implement operator() accepting a const CallbackInfo&
1094
- /// and return either void or Value.
1095
- template <typename Callable>
1096
- static Function New(napi_env env,
1097
- Callable cb,
1098
- const char* utf8name = nullptr,
1099
- void* data = nullptr);
1100
- /// Callable must implement operator() accepting a const CallbackInfo&
1101
- /// and return either void or Value.
1102
- template <typename Callable>
1103
- static Function New(napi_env env,
1104
- Callable cb,
1105
- const std::string& utf8name,
1106
- void* data = nullptr);
1107
-
1108
- Function();
1109
- Function(napi_env env, napi_value value);
1110
-
1111
- Value operator()(const std::initializer_list<napi_value>& args) const;
1112
-
1113
- Value Call(const std::initializer_list<napi_value>& args) const;
1114
- Value Call(const std::vector<napi_value>& args) const;
1115
- Value Call(size_t argc, const napi_value* args) const;
1116
- Value Call(napi_value recv,
1117
- const std::initializer_list<napi_value>& args) const;
1118
- Value Call(napi_value recv, const std::vector<napi_value>& args) const;
1119
- Value Call(napi_value recv, size_t argc, const napi_value* args) const;
1120
-
1121
- Value MakeCallback(napi_value recv,
1122
- const std::initializer_list<napi_value>& args,
1123
- napi_async_context context = nullptr) const;
1124
- Value MakeCallback(napi_value recv,
1125
- const std::vector<napi_value>& args,
1126
- napi_async_context context = nullptr) const;
1127
- Value MakeCallback(napi_value recv,
1128
- size_t argc,
1129
- const napi_value* args,
1130
- napi_async_context context = nullptr) const;
1131
-
1132
- Object New(const std::initializer_list<napi_value>& args) const;
1133
- Object New(const std::vector<napi_value>& args) const;
1134
- Object New(size_t argc, const napi_value* args) const;
1135
- };
1136
-
1137
- class Promise : public Object {
1138
- public:
1139
- class Deferred {
1140
- public:
1141
- static Deferred New(napi_env env);
1142
- Deferred(napi_env env);
1143
-
1144
- Napi::Promise Promise() const;
1145
- Napi::Env Env() const;
1146
-
1147
- void Resolve(napi_value value) const;
1148
- void Reject(napi_value value) const;
1149
-
1150
- private:
1151
- napi_env _env;
1152
- napi_deferred _deferred;
1153
- napi_value _promise;
1154
- };
1155
-
1156
- Promise(napi_env env, napi_value value);
1157
- };
1158
-
1159
- template <typename T>
1160
- class Buffer : public Uint8Array {
1161
- public:
1162
- static Buffer<T> New(napi_env env, size_t length);
1163
- static Buffer<T> New(napi_env env, T* data, size_t length);
1164
-
1165
- // Finalizer must implement `void operator()(Env env, T* data)`.
1166
- template <typename Finalizer>
1167
- static Buffer<T> New(napi_env env, T* data,
1168
- size_t length,
1169
- Finalizer finalizeCallback);
1170
- // Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`.
1171
- template <typename Finalizer, typename Hint>
1172
- static Buffer<T> New(napi_env env, T* data,
1173
- size_t length,
1174
- Finalizer finalizeCallback,
1175
- Hint* finalizeHint);
1176
-
1177
- static Buffer<T> Copy(napi_env env, const T* data, size_t length);
1178
-
1179
- Buffer();
1180
- Buffer(napi_env env, napi_value value);
1181
- size_t Length() const;
1182
- T* Data() const;
1183
-
1184
- private:
1185
- mutable size_t _length;
1186
- mutable T* _data;
1187
-
1188
- Buffer(napi_env env, napi_value value, size_t length, T* data);
1189
- void EnsureInfo() const;
1190
- };
1191
-
1192
- /// Holds a counted reference to a value; initially a weak reference unless otherwise specified,
1193
- /// may be changed to/from a strong reference by adjusting the refcount.
1194
- ///
1195
- /// The referenced value is not immediately destroyed when the reference count is zero; it is
1196
- /// merely then eligible for garbage-collection if there are no other references to the value.
1197
- template <typename T>
1198
- class Reference {
1199
- public:
1200
- static Reference<T> New(const T& value, uint32_t initialRefcount = 0);
1201
-
1202
- Reference();
1203
- Reference(napi_env env, napi_ref ref);
1204
- ~Reference();
1205
-
1206
- // A reference can be moved but cannot be copied.
1207
- Reference(Reference<T>&& other);
1208
- Reference<T>& operator =(Reference<T>&& other);
1209
- NAPI_DISALLOW_ASSIGN(Reference<T>)
1210
-
1211
- operator napi_ref() const;
1212
- bool operator ==(const Reference<T> &other) const;
1213
- bool operator !=(const Reference<T> &other) const;
1214
-
1215
- Napi::Env Env() const;
1216
- bool IsEmpty() const;
1217
-
1218
- // Note when getting the value of a Reference it is usually correct to do so
1219
- // within a HandleScope so that the value handle gets cleaned up efficiently.
1220
- T Value() const;
1221
-
1222
- uint32_t Ref();
1223
- uint32_t Unref();
1224
- void Reset();
1225
- void Reset(const T& value, uint32_t refcount = 0);
1226
-
1227
- // Call this on a reference that is declared as static data, to prevent its
1228
- // destructor from running at program shutdown time, which would attempt to
1229
- // reset the reference when the environment is no longer valid. Avoid using
1230
- // this if at all possible. If you do need to use static data, MAKE SURE to
1231
- // warn your users that your addon is NOT threadsafe.
1232
- void SuppressDestruct();
1233
-
1234
- protected:
1235
- Reference(const Reference<T>&);
1236
-
1237
- /// !cond INTERNAL
1238
- napi_env _env;
1239
- napi_ref _ref;
1240
- /// !endcond
1241
-
1242
- private:
1243
- bool _suppressDestruct;
1244
- };
1245
-
1246
- class ObjectReference: public Reference<Object> {
1247
- public:
1248
- ObjectReference();
1249
- ObjectReference(napi_env env, napi_ref ref);
1250
-
1251
- // A reference can be moved but cannot be copied.
1252
- ObjectReference(Reference<Object>&& other);
1253
- ObjectReference& operator =(Reference<Object>&& other);
1254
- ObjectReference(ObjectReference&& other);
1255
- ObjectReference& operator =(ObjectReference&& other);
1256
- NAPI_DISALLOW_ASSIGN(ObjectReference)
1257
-
1258
- Napi::Value Get(const char* utf8name) const;
1259
- Napi::Value Get(const std::string& utf8name) const;
1260
- bool Set(const char* utf8name, napi_value value);
1261
- bool Set(const char* utf8name, Napi::Value value);
1262
- bool Set(const char* utf8name, const char* utf8value);
1263
- bool Set(const char* utf8name, bool boolValue);
1264
- bool Set(const char* utf8name, double numberValue);
1265
- bool Set(const std::string& utf8name, napi_value value);
1266
- bool Set(const std::string& utf8name, Napi::Value value);
1267
- bool Set(const std::string& utf8name, std::string& utf8value);
1268
- bool Set(const std::string& utf8name, bool boolValue);
1269
- bool Set(const std::string& utf8name, double numberValue);
1270
-
1271
- Napi::Value Get(uint32_t index) const;
1272
- bool Set(uint32_t index, const napi_value value);
1273
- bool Set(uint32_t index, const Napi::Value value);
1274
- bool Set(uint32_t index, const char* utf8value);
1275
- bool Set(uint32_t index, const std::string& utf8value);
1276
- bool Set(uint32_t index, bool boolValue);
1277
- bool Set(uint32_t index, double numberValue);
1278
-
1279
- protected:
1280
- ObjectReference(const ObjectReference&);
1281
- };
1282
-
1283
- class FunctionReference: public Reference<Function> {
1284
- public:
1285
- FunctionReference();
1286
- FunctionReference(napi_env env, napi_ref ref);
1287
-
1288
- // A reference can be moved but cannot be copied.
1289
- FunctionReference(Reference<Function>&& other);
1290
- FunctionReference& operator =(Reference<Function>&& other);
1291
- FunctionReference(FunctionReference&& other);
1292
- FunctionReference& operator =(FunctionReference&& other);
1293
- NAPI_DISALLOW_ASSIGN_COPY(FunctionReference)
1294
-
1295
- Napi::Value operator ()(const std::initializer_list<napi_value>& args) const;
1296
-
1297
- Napi::Value Call(const std::initializer_list<napi_value>& args) const;
1298
- Napi::Value Call(const std::vector<napi_value>& args) const;
1299
- Napi::Value Call(napi_value recv, const std::initializer_list<napi_value>& args) const;
1300
- Napi::Value Call(napi_value recv, const std::vector<napi_value>& args) const;
1301
- Napi::Value Call(napi_value recv, size_t argc, const napi_value* args) const;
1302
-
1303
- Napi::Value MakeCallback(napi_value recv,
1304
- const std::initializer_list<napi_value>& args,
1305
- napi_async_context context = nullptr) const;
1306
- Napi::Value MakeCallback(napi_value recv,
1307
- const std::vector<napi_value>& args,
1308
- napi_async_context context = nullptr) const;
1309
- Napi::Value MakeCallback(napi_value recv,
1310
- size_t argc,
1311
- const napi_value* args,
1312
- napi_async_context context = nullptr) const;
1313
-
1314
- Object New(const std::initializer_list<napi_value>& args) const;
1315
- Object New(const std::vector<napi_value>& args) const;
1316
- };
1317
-
1318
- // Shortcuts to creating a new reference with inferred type and refcount = 0.
1319
- template <typename T> Reference<T> Weak(T value);
1320
- ObjectReference Weak(Object value);
1321
- FunctionReference Weak(Function value);
1322
-
1323
- // Shortcuts to creating a new reference with inferred type and refcount = 1.
1324
- template <typename T> Reference<T> Persistent(T value);
1325
- ObjectReference Persistent(Object value);
1326
- FunctionReference Persistent(Function value);
1327
-
1328
- /// A persistent reference to a JavaScript error object. Use of this class
1329
- /// depends somewhat on whether C++ exceptions are enabled at compile time.
1330
- ///
1331
- /// ### Handling Errors With C++ Exceptions
1332
- ///
1333
- /// If C++ exceptions are enabled, then the `Error` class extends
1334
- /// `std::exception` and enables integrated error-handling for C++ exceptions
1335
- /// and JavaScript exceptions.
1336
- ///
1337
- /// If a Node-API call fails without executing any JavaScript code (for
1338
- /// example due to an invalid argument), then the Node-API wrapper
1339
- /// automatically converts and throws the error as a C++ exception of type
1340
- /// `Napi::Error`. Or if a JavaScript function called by C++ code via Node-API
1341
- /// throws a JavaScript exception, then the Node-API wrapper automatically
1342
- /// converts and throws it as a C++ exception of type `Napi::Error`.
1343
- ///
1344
- /// If a C++ exception of type `Napi::Error` escapes from a Node-API C++
1345
- /// callback, then the Node-API wrapper automatically converts and throws it
1346
- /// as a JavaScript exception. Therefore, catching a C++ exception of type
1347
- /// `Napi::Error` prevents a JavaScript exception from being thrown.
1348
- ///
1349
- /// #### Example 1A - Throwing a C++ exception:
1350
- ///
1351
- /// Napi::Env env = ...
1352
- /// throw Napi::Error::New(env, "Example exception");
1353
- ///
1354
- /// Following C++ statements will not be executed. The exception will bubble
1355
- /// up as a C++ exception of type `Napi::Error`, until it is either caught
1356
- /// while still in C++, or else automatically propataged as a JavaScript
1357
- /// exception when the callback returns to JavaScript.
1358
- ///
1359
- /// #### Example 2A - Propagating a Node-API C++ exception:
1360
- ///
1361
- /// Napi::Function jsFunctionThatThrows = someObj.As<Napi::Function>();
1362
- /// Napi::Value result = jsFunctionThatThrows({ arg1, arg2 });
1363
- ///
1364
- /// Following C++ statements will not be executed. The exception will bubble
1365
- /// up as a C++ exception of type `Napi::Error`, until it is either caught
1366
- /// while still in C++, or else automatically propagated as a JavaScript
1367
- /// exception when the callback returns to JavaScript.
1368
- ///
1369
- /// #### Example 3A - Handling a Node-API C++ exception:
1370
- ///
1371
- /// Napi::Function jsFunctionThatThrows = someObj.As<Napi::Function>();
1372
- /// Napi::Value result;
1373
- /// try {
1374
- /// result = jsFunctionThatThrows({ arg1, arg2 });
1375
- /// } catch (const Napi::Error& e) {
1376
- /// cerr << "Caught JavaScript exception: " + e.what();
1377
- /// }
1378
- ///
1379
- /// Since the exception was caught here, it will not be propagated as a
1380
- /// JavaScript exception.
1381
- ///
1382
- /// ### Handling Errors Without C++ Exceptions
1383
- ///
1384
- /// If C++ exceptions are disabled (by defining `NAPI_DISABLE_CPP_EXCEPTIONS`)
1385
- /// then this class does not extend `std::exception`, and APIs in the `Napi`
1386
- /// namespace do not throw C++ exceptions when they fail. Instead, they raise
1387
- /// _pending_ JavaScript exceptions and return _empty_ `Value`s. Calling code
1388
- /// should check `Value::IsEmpty()` before attempting to use a returned value,
1389
- /// and may use methods on the `Env` class to check for, get, and clear a
1390
- /// pending JavaScript exception. If the pending exception is not cleared, it
1391
- /// will be thrown when the native callback returns to JavaScript.
1392
- ///
1393
- /// #### Example 1B - Throwing a JS exception
1394
- ///
1395
- /// Napi::Env env = ...
1396
- /// Napi::Error::New(env, "Example
1397
- /// exception").ThrowAsJavaScriptException(); return;
1398
- ///
1399
- /// After throwing a JS exception, the code should generally return
1400
- /// immediately from the native callback, after performing any necessary
1401
- /// cleanup.
1402
- ///
1403
- /// #### Example 2B - Propagating a Node-API JS exception:
1404
- ///
1405
- /// Napi::Function jsFunctionThatThrows = someObj.As<Napi::Function>();
1406
- /// Napi::Value result = jsFunctionThatThrows({ arg1, arg2 });
1407
- /// if (result.IsEmpty()) return;
1408
- ///
1409
- /// An empty value result from a Node-API call indicates an error occurred,
1410
- /// and a JavaScript exception is pending. To let the exception propagate, the
1411
- /// code should generally return immediately from the native callback, after
1412
- /// performing any necessary cleanup.
1413
- ///
1414
- /// #### Example 3B - Handling a Node-API JS exception:
1415
- ///
1416
- /// Napi::Function jsFunctionThatThrows = someObj.As<Napi::Function>();
1417
- /// Napi::Value result = jsFunctionThatThrows({ arg1, arg2 });
1418
- /// if (result.IsEmpty()) {
1419
- /// Napi::Error e = env.GetAndClearPendingException();
1420
- /// cerr << "Caught JavaScript exception: " + e.Message();
1421
- /// }
1422
- ///
1423
- /// Since the exception was cleared here, it will not be propagated as a
1424
- /// JavaScript exception after the native callback returns.
1425
- class Error : public ObjectReference
1426
- #ifdef NAPI_CPP_EXCEPTIONS
1427
- , public std::exception
1428
- #endif // NAPI_CPP_EXCEPTIONS
1429
- {
1430
- public:
1431
- static Error New(napi_env env);
1432
- static Error New(napi_env env, const char* message);
1433
- static Error New(napi_env env, const std::string& message);
1434
-
1435
- static NAPI_NO_RETURN void Fatal(const char* location, const char* message);
1436
-
1437
- Error();
1438
- Error(napi_env env, napi_value value);
1439
-
1440
- // An error can be moved or copied.
1441
- Error(Error&& other);
1442
- Error& operator =(Error&& other);
1443
- Error(const Error&);
1444
- Error& operator =(const Error&);
1445
-
1446
- const std::string& Message() const NAPI_NOEXCEPT;
1447
- void ThrowAsJavaScriptException() const;
1448
-
1449
- #ifdef NAPI_CPP_EXCEPTIONS
1450
- const char* what() const NAPI_NOEXCEPT override;
1451
- #endif // NAPI_CPP_EXCEPTIONS
1452
-
1453
- protected:
1454
- /// !cond INTERNAL
1455
- using create_error_fn = napi_status (*)(napi_env envb,
1456
- napi_value code,
1457
- napi_value msg,
1458
- napi_value* result);
1459
-
1460
- template <typename TError>
1461
- static TError New(napi_env env,
1462
- const char* message,
1463
- size_t length,
1464
- create_error_fn create_error);
1465
- /// !endcond
1466
-
1467
- private:
1468
- mutable std::string _message;
1469
- };
1470
-
1471
- class TypeError : public Error {
1472
- public:
1473
- static TypeError New(napi_env env, const char* message);
1474
- static TypeError New(napi_env env, const std::string& message);
1475
-
1476
- TypeError();
1477
- TypeError(napi_env env, napi_value value);
1478
- };
1479
-
1480
- class RangeError : public Error {
1481
- public:
1482
- static RangeError New(napi_env env, const char* message);
1483
- static RangeError New(napi_env env, const std::string& message);
1484
-
1485
- RangeError();
1486
- RangeError(napi_env env, napi_value value);
1487
- };
1488
-
1489
- class CallbackInfo {
1490
- public:
1491
- CallbackInfo(napi_env env, napi_callback_info info);
1492
- ~CallbackInfo();
1493
-
1494
- // Disallow copying to prevent multiple free of _dynamicArgs
1495
- NAPI_DISALLOW_ASSIGN_COPY(CallbackInfo)
1496
-
1497
- Napi::Env Env() const;
1498
- Value NewTarget() const;
1499
- bool IsConstructCall() const;
1500
- size_t Length() const;
1501
- const Value operator [](size_t index) const;
1502
- Value This() const;
1503
- void* Data() const;
1504
- void SetData(void* data);
1505
-
1506
- private:
1507
- const size_t _staticArgCount = 6;
1508
- napi_env _env;
1509
- napi_callback_info _info;
1510
- napi_value _this;
1511
- size_t _argc;
1512
- napi_value* _argv;
1513
- napi_value _staticArgs[6];
1514
- napi_value* _dynamicArgs;
1515
- void* _data;
1516
- };
1517
-
1518
- class PropertyDescriptor {
1519
- public:
1520
- using GetterCallback = Napi::Value (*)(const Napi::CallbackInfo& info);
1521
- using SetterCallback = void (*)(const Napi::CallbackInfo& info);
1522
-
1523
- #ifndef NODE_ADDON_API_DISABLE_DEPRECATED
1524
- template <typename Getter>
1525
- static PropertyDescriptor Accessor(const char* utf8name,
1526
- Getter getter,
1527
- napi_property_attributes attributes = napi_default,
1528
- void* data = nullptr);
1529
- template <typename Getter>
1530
- static PropertyDescriptor Accessor(const std::string& utf8name,
1531
- Getter getter,
1532
- napi_property_attributes attributes = napi_default,
1533
- void* data = nullptr);
1534
- template <typename Getter>
1535
- static PropertyDescriptor Accessor(napi_value name,
1536
- Getter getter,
1537
- napi_property_attributes attributes = napi_default,
1538
- void* data = nullptr);
1539
- template <typename Getter>
1540
- static PropertyDescriptor Accessor(Name name,
1541
- Getter getter,
1542
- napi_property_attributes attributes = napi_default,
1543
- void* data = nullptr);
1544
- template <typename Getter, typename Setter>
1545
- static PropertyDescriptor Accessor(const char* utf8name,
1546
- Getter getter,
1547
- Setter setter,
1548
- napi_property_attributes attributes = napi_default,
1549
- void* data = nullptr);
1550
- template <typename Getter, typename Setter>
1551
- static PropertyDescriptor Accessor(const std::string& utf8name,
1552
- Getter getter,
1553
- Setter setter,
1554
- napi_property_attributes attributes = napi_default,
1555
- void* data = nullptr);
1556
- template <typename Getter, typename Setter>
1557
- static PropertyDescriptor Accessor(napi_value name,
1558
- Getter getter,
1559
- Setter setter,
1560
- napi_property_attributes attributes = napi_default,
1561
- void* data = nullptr);
1562
- template <typename Getter, typename Setter>
1563
- static PropertyDescriptor Accessor(Name name,
1564
- Getter getter,
1565
- Setter setter,
1566
- napi_property_attributes attributes = napi_default,
1567
- void* data = nullptr);
1568
- template <typename Callable>
1569
- static PropertyDescriptor Function(const char* utf8name,
1570
- Callable cb,
1571
- napi_property_attributes attributes = napi_default,
1572
- void* data = nullptr);
1573
- template <typename Callable>
1574
- static PropertyDescriptor Function(const std::string& utf8name,
1575
- Callable cb,
1576
- napi_property_attributes attributes = napi_default,
1577
- void* data = nullptr);
1578
- template <typename Callable>
1579
- static PropertyDescriptor Function(napi_value name,
1580
- Callable cb,
1581
- napi_property_attributes attributes = napi_default,
1582
- void* data = nullptr);
1583
- template <typename Callable>
1584
- static PropertyDescriptor Function(Name name,
1585
- Callable cb,
1586
- napi_property_attributes attributes = napi_default,
1587
- void* data = nullptr);
1588
- #endif // !NODE_ADDON_API_DISABLE_DEPRECATED
1589
-
1590
- template <GetterCallback Getter>
1591
- static PropertyDescriptor Accessor(const char* utf8name,
1592
- napi_property_attributes attributes = napi_default,
1593
- void* data = nullptr);
1594
-
1595
- template <GetterCallback Getter>
1596
- static PropertyDescriptor Accessor(const std::string& utf8name,
1597
- napi_property_attributes attributes = napi_default,
1598
- void* data = nullptr);
1599
-
1600
- template <GetterCallback Getter>
1601
- static PropertyDescriptor Accessor(Name name,
1602
- napi_property_attributes attributes = napi_default,
1603
- void* data = nullptr);
1604
-
1605
- template <GetterCallback Getter, SetterCallback Setter>
1606
- static PropertyDescriptor Accessor(const char* utf8name,
1607
- napi_property_attributes attributes = napi_default,
1608
- void* data = nullptr);
1609
-
1610
- template <GetterCallback Getter, SetterCallback Setter>
1611
- static PropertyDescriptor Accessor(const std::string& utf8name,
1612
- napi_property_attributes attributes = napi_default,
1613
- void* data = nullptr);
1614
-
1615
- template <GetterCallback Getter, SetterCallback Setter>
1616
- static PropertyDescriptor Accessor(Name name,
1617
- napi_property_attributes attributes = napi_default,
1618
- void* data = nullptr);
1619
-
1620
- template <typename Getter>
1621
- static PropertyDescriptor Accessor(Napi::Env env,
1622
- Napi::Object object,
1623
- const char* utf8name,
1624
- Getter getter,
1625
- napi_property_attributes attributes = napi_default,
1626
- void* data = nullptr);
1627
- template <typename Getter>
1628
- static PropertyDescriptor Accessor(Napi::Env env,
1629
- Napi::Object object,
1630
- const std::string& utf8name,
1631
- Getter getter,
1632
- napi_property_attributes attributes = napi_default,
1633
- void* data = nullptr);
1634
- template <typename Getter>
1635
- static PropertyDescriptor Accessor(Napi::Env env,
1636
- Napi::Object object,
1637
- Name name,
1638
- Getter getter,
1639
- napi_property_attributes attributes = napi_default,
1640
- void* data = nullptr);
1641
- template <typename Getter, typename Setter>
1642
- static PropertyDescriptor Accessor(Napi::Env env,
1643
- Napi::Object object,
1644
- const char* utf8name,
1645
- Getter getter,
1646
- Setter setter,
1647
- napi_property_attributes attributes = napi_default,
1648
- void* data = nullptr);
1649
- template <typename Getter, typename Setter>
1650
- static PropertyDescriptor Accessor(Napi::Env env,
1651
- Napi::Object object,
1652
- const std::string& utf8name,
1653
- Getter getter,
1654
- Setter setter,
1655
- napi_property_attributes attributes = napi_default,
1656
- void* data = nullptr);
1657
- template <typename Getter, typename Setter>
1658
- static PropertyDescriptor Accessor(Napi::Env env,
1659
- Napi::Object object,
1660
- Name name,
1661
- Getter getter,
1662
- Setter setter,
1663
- napi_property_attributes attributes = napi_default,
1664
- void* data = nullptr);
1665
- template <typename Callable>
1666
- static PropertyDescriptor Function(Napi::Env env,
1667
- Napi::Object object,
1668
- const char* utf8name,
1669
- Callable cb,
1670
- napi_property_attributes attributes = napi_default,
1671
- void* data = nullptr);
1672
- template <typename Callable>
1673
- static PropertyDescriptor Function(Napi::Env env,
1674
- Napi::Object object,
1675
- const std::string& utf8name,
1676
- Callable cb,
1677
- napi_property_attributes attributes = napi_default,
1678
- void* data = nullptr);
1679
- template <typename Callable>
1680
- static PropertyDescriptor Function(Napi::Env env,
1681
- Napi::Object object,
1682
- Name name,
1683
- Callable cb,
1684
- napi_property_attributes attributes = napi_default,
1685
- void* data = nullptr);
1686
- static PropertyDescriptor Value(const char* utf8name,
1687
- napi_value value,
1688
- napi_property_attributes attributes = napi_default);
1689
- static PropertyDescriptor Value(const std::string& utf8name,
1690
- napi_value value,
1691
- napi_property_attributes attributes = napi_default);
1692
- static PropertyDescriptor Value(napi_value name,
1693
- napi_value value,
1694
- napi_property_attributes attributes = napi_default);
1695
- static PropertyDescriptor Value(Name name,
1696
- Napi::Value value,
1697
- napi_property_attributes attributes = napi_default);
1698
-
1699
- PropertyDescriptor(napi_property_descriptor desc);
1700
-
1701
- operator napi_property_descriptor&();
1702
- operator const napi_property_descriptor&() const;
1703
-
1704
- private:
1705
- napi_property_descriptor _desc;
1706
- };
1707
-
1708
- /// Property descriptor for use with `ObjectWrap::DefineClass()`.
1709
- ///
1710
- /// This is different from the standalone `PropertyDescriptor` because it is specific to each
1711
- /// `ObjectWrap<T>` subclass. This prevents using descriptors from a different class when
1712
- /// defining a new class (preventing the callbacks from having incorrect `this` pointers).
1713
- template <typename T>
1714
- class ClassPropertyDescriptor {
1715
- public:
1716
- ClassPropertyDescriptor(napi_property_descriptor desc) : _desc(desc) {}
1717
-
1718
- operator napi_property_descriptor&() { return _desc; }
1719
- operator const napi_property_descriptor&() const { return _desc; }
1720
-
1721
- private:
1722
- napi_property_descriptor _desc;
1723
- };
1724
-
1725
- template <typename T, typename TCallback>
1726
- struct MethodCallbackData {
1727
- TCallback callback;
1728
- void* data;
1729
- };
1730
-
1731
- template <typename T, typename TGetterCallback, typename TSetterCallback>
1732
- struct AccessorCallbackData {
1733
- TGetterCallback getterCallback;
1734
- TSetterCallback setterCallback;
1735
- void* data;
1736
- };
1737
-
1738
- template <typename T>
1739
- class InstanceWrap {
1740
- public:
1741
- using InstanceVoidMethodCallback = void (T::*)(const CallbackInfo& info);
1742
- using InstanceMethodCallback = Napi::Value (T::*)(const CallbackInfo& info);
1743
- using InstanceGetterCallback = Napi::Value (T::*)(const CallbackInfo& info);
1744
- using InstanceSetterCallback = void (T::*)(const CallbackInfo& info,
1745
- const Napi::Value& value);
1746
-
1747
- using PropertyDescriptor = ClassPropertyDescriptor<T>;
1748
-
1749
- static PropertyDescriptor InstanceMethod(const char* utf8name,
1750
- InstanceVoidMethodCallback method,
1751
- napi_property_attributes attributes = napi_default,
1752
- void* data = nullptr);
1753
- static PropertyDescriptor InstanceMethod(const char* utf8name,
1754
- InstanceMethodCallback method,
1755
- napi_property_attributes attributes = napi_default,
1756
- void* data = nullptr);
1757
- static PropertyDescriptor InstanceMethod(Symbol name,
1758
- InstanceVoidMethodCallback method,
1759
- napi_property_attributes attributes = napi_default,
1760
- void* data = nullptr);
1761
- static PropertyDescriptor InstanceMethod(Symbol name,
1762
- InstanceMethodCallback method,
1763
- napi_property_attributes attributes = napi_default,
1764
- void* data = nullptr);
1765
- template <InstanceVoidMethodCallback method>
1766
- static PropertyDescriptor InstanceMethod(const char* utf8name,
1767
- napi_property_attributes attributes = napi_default,
1768
- void* data = nullptr);
1769
- template <InstanceMethodCallback method>
1770
- static PropertyDescriptor InstanceMethod(const char* utf8name,
1771
- napi_property_attributes attributes = napi_default,
1772
- void* data = nullptr);
1773
- template <InstanceVoidMethodCallback method>
1774
- static PropertyDescriptor InstanceMethod(Symbol name,
1775
- napi_property_attributes attributes = napi_default,
1776
- void* data = nullptr);
1777
- template <InstanceMethodCallback method>
1778
- static PropertyDescriptor InstanceMethod(Symbol name,
1779
- napi_property_attributes attributes = napi_default,
1780
- void* data = nullptr);
1781
- static PropertyDescriptor InstanceAccessor(const char* utf8name,
1782
- InstanceGetterCallback getter,
1783
- InstanceSetterCallback setter,
1784
- napi_property_attributes attributes = napi_default,
1785
- void* data = nullptr);
1786
- static PropertyDescriptor InstanceAccessor(Symbol name,
1787
- InstanceGetterCallback getter,
1788
- InstanceSetterCallback setter,
1789
- napi_property_attributes attributes = napi_default,
1790
- void* data = nullptr);
1791
- template <InstanceGetterCallback getter, InstanceSetterCallback setter=nullptr>
1792
- static PropertyDescriptor InstanceAccessor(const char* utf8name,
1793
- napi_property_attributes attributes = napi_default,
1794
- void* data = nullptr);
1795
- template <InstanceGetterCallback getter, InstanceSetterCallback setter=nullptr>
1796
- static PropertyDescriptor InstanceAccessor(Symbol name,
1797
- napi_property_attributes attributes = napi_default,
1798
- void* data = nullptr);
1799
- static PropertyDescriptor InstanceValue(const char* utf8name,
1800
- Napi::Value value,
1801
- napi_property_attributes attributes = napi_default);
1802
- static PropertyDescriptor InstanceValue(Symbol name,
1803
- Napi::Value value,
1804
- napi_property_attributes attributes = napi_default);
1805
-
1806
- protected:
1807
- static void AttachPropData(napi_env env, napi_value value, const napi_property_descriptor* prop);
1808
-
1809
- private:
1810
- using This = InstanceWrap<T>;
1811
-
1812
- using InstanceVoidMethodCallbackData =
1813
- MethodCallbackData<T, InstanceVoidMethodCallback>;
1814
- using InstanceMethodCallbackData =
1815
- MethodCallbackData<T, InstanceMethodCallback>;
1816
- using InstanceAccessorCallbackData =
1817
- AccessorCallbackData<T, InstanceGetterCallback, InstanceSetterCallback>;
1818
-
1819
- static napi_value InstanceVoidMethodCallbackWrapper(napi_env env, napi_callback_info info);
1820
- static napi_value InstanceMethodCallbackWrapper(napi_env env, napi_callback_info info);
1821
- static napi_value InstanceGetterCallbackWrapper(napi_env env, napi_callback_info info);
1822
- static napi_value InstanceSetterCallbackWrapper(napi_env env, napi_callback_info info);
1823
-
1824
- template <InstanceSetterCallback method>
1825
- static napi_value WrappedMethod(napi_env env,
1826
- napi_callback_info info) NAPI_NOEXCEPT;
1827
-
1828
- template <InstanceSetterCallback setter> struct SetterTag {};
1829
-
1830
- template <InstanceSetterCallback setter>
1831
- static napi_callback WrapSetter(SetterTag<setter>) NAPI_NOEXCEPT {
1832
- return &This::WrappedMethod<setter>;
1833
- }
1834
- static napi_callback WrapSetter(SetterTag<nullptr>) NAPI_NOEXCEPT {
1835
- return nullptr;
1836
- }
1837
- };
1838
-
1839
- /// Base class to be extended by C++ classes exposed to JavaScript; each C++ class instance gets
1840
- /// "wrapped" by a JavaScript object that is managed by this class.
1841
- ///
1842
- /// At initialization time, the `DefineClass()` method must be used to
1843
- /// hook up the accessor and method callbacks. It takes a list of
1844
- /// property descriptors, which can be constructed via the various
1845
- /// static methods on the base class.
1846
- ///
1847
- /// #### Example:
1848
- ///
1849
- /// class Example: public Napi::ObjectWrap<Example> {
1850
- /// public:
1851
- /// static void Initialize(Napi::Env& env, Napi::Object& target) {
1852
- /// Napi::Function constructor = DefineClass(env, "Example", {
1853
- /// InstanceAccessor<&Example::GetSomething, &Example::SetSomething>("value"),
1854
- /// InstanceMethod<&Example::DoSomething>("doSomething"),
1855
- /// });
1856
- /// target.Set("Example", constructor);
1857
- /// }
1858
- ///
1859
- /// Example(const Napi::CallbackInfo& info); // Constructor
1860
- /// Napi::Value GetSomething(const Napi::CallbackInfo& info);
1861
- /// void SetSomething(const Napi::CallbackInfo& info, const Napi::Value& value);
1862
- /// Napi::Value DoSomething(const Napi::CallbackInfo& info);
1863
- /// }
1864
- template <typename T>
1865
- class ObjectWrap : public InstanceWrap<T>, public Reference<Object> {
1866
- public:
1867
- ObjectWrap(const CallbackInfo& callbackInfo);
1868
- virtual ~ObjectWrap();
1869
-
1870
- static T* Unwrap(Object wrapper);
1871
-
1872
- // Methods exposed to JavaScript must conform to one of these callback signatures.
1873
- using StaticVoidMethodCallback = void (*)(const CallbackInfo& info);
1874
- using StaticMethodCallback = Napi::Value (*)(const CallbackInfo& info);
1875
- using StaticGetterCallback = Napi::Value (*)(const CallbackInfo& info);
1876
- using StaticSetterCallback = void (*)(const CallbackInfo& info,
1877
- const Napi::Value& value);
1878
-
1879
- using PropertyDescriptor = ClassPropertyDescriptor<T>;
1880
-
1881
- static Function DefineClass(Napi::Env env,
1882
- const char* utf8name,
1883
- const std::initializer_list<PropertyDescriptor>& properties,
1884
- void* data = nullptr);
1885
- static Function DefineClass(Napi::Env env,
1886
- const char* utf8name,
1887
- const std::vector<PropertyDescriptor>& properties,
1888
- void* data = nullptr);
1889
- static PropertyDescriptor StaticMethod(const char* utf8name,
1890
- StaticVoidMethodCallback method,
1891
- napi_property_attributes attributes = napi_default,
1892
- void* data = nullptr);
1893
- static PropertyDescriptor StaticMethod(const char* utf8name,
1894
- StaticMethodCallback method,
1895
- napi_property_attributes attributes = napi_default,
1896
- void* data = nullptr);
1897
- static PropertyDescriptor StaticMethod(Symbol name,
1898
- StaticVoidMethodCallback method,
1899
- napi_property_attributes attributes = napi_default,
1900
- void* data = nullptr);
1901
- static PropertyDescriptor StaticMethod(Symbol name,
1902
- StaticMethodCallback method,
1903
- napi_property_attributes attributes = napi_default,
1904
- void* data = nullptr);
1905
- template <StaticVoidMethodCallback method>
1906
- static PropertyDescriptor StaticMethod(const char* utf8name,
1907
- napi_property_attributes attributes = napi_default,
1908
- void* data = nullptr);
1909
- template <StaticVoidMethodCallback method>
1910
- static PropertyDescriptor StaticMethod(Symbol name,
1911
- napi_property_attributes attributes = napi_default,
1912
- void* data = nullptr);
1913
- template <StaticMethodCallback method>
1914
- static PropertyDescriptor StaticMethod(const char* utf8name,
1915
- napi_property_attributes attributes = napi_default,
1916
- void* data = nullptr);
1917
- template <StaticMethodCallback method>
1918
- static PropertyDescriptor StaticMethod(Symbol name,
1919
- napi_property_attributes attributes = napi_default,
1920
- void* data = nullptr);
1921
- static PropertyDescriptor StaticAccessor(const char* utf8name,
1922
- StaticGetterCallback getter,
1923
- StaticSetterCallback setter,
1924
- napi_property_attributes attributes = napi_default,
1925
- void* data = nullptr);
1926
- static PropertyDescriptor StaticAccessor(Symbol name,
1927
- StaticGetterCallback getter,
1928
- StaticSetterCallback setter,
1929
- napi_property_attributes attributes = napi_default,
1930
- void* data = nullptr);
1931
- template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
1932
- static PropertyDescriptor StaticAccessor(const char* utf8name,
1933
- napi_property_attributes attributes = napi_default,
1934
- void* data = nullptr);
1935
- template <StaticGetterCallback getter, StaticSetterCallback setter=nullptr>
1936
- static PropertyDescriptor StaticAccessor(Symbol name,
1937
- napi_property_attributes attributes = napi_default,
1938
- void* data = nullptr);
1939
- static PropertyDescriptor StaticValue(const char* utf8name,
1940
- Napi::Value value,
1941
- napi_property_attributes attributes = napi_default);
1942
- static PropertyDescriptor StaticValue(Symbol name,
1943
- Napi::Value value,
1944
- napi_property_attributes attributes = napi_default);
1945
- virtual void Finalize(Napi::Env env);
1946
-
1947
- private:
1948
- using This = ObjectWrap<T>;
1949
-
1950
- static napi_value ConstructorCallbackWrapper(napi_env env, napi_callback_info info);
1951
- static napi_value StaticVoidMethodCallbackWrapper(napi_env env, napi_callback_info info);
1952
- static napi_value StaticMethodCallbackWrapper(napi_env env, napi_callback_info info);
1953
- static napi_value StaticGetterCallbackWrapper(napi_env env, napi_callback_info info);
1954
- static napi_value StaticSetterCallbackWrapper(napi_env env, napi_callback_info info);
1955
- static void FinalizeCallback(napi_env env, void* data, void* hint);
1956
- static Function DefineClass(Napi::Env env,
1957
- const char* utf8name,
1958
- const size_t props_count,
1959
- const napi_property_descriptor* props,
1960
- void* data = nullptr);
1961
-
1962
- using StaticVoidMethodCallbackData =
1963
- MethodCallbackData<T, StaticVoidMethodCallback>;
1964
- using StaticMethodCallbackData =
1965
- MethodCallbackData<T, StaticMethodCallback>;
1966
-
1967
- using StaticAccessorCallbackData =
1968
- AccessorCallbackData<T, StaticGetterCallback, StaticSetterCallback>;
1969
-
1970
- template <StaticSetterCallback method>
1971
- static napi_value WrappedMethod(napi_env env,
1972
- napi_callback_info info) NAPI_NOEXCEPT;
1973
-
1974
- template <StaticSetterCallback setter> struct StaticSetterTag {};
1975
-
1976
- template <StaticSetterCallback setter>
1977
- static napi_callback WrapStaticSetter(StaticSetterTag<setter>)
1978
- NAPI_NOEXCEPT {
1979
- return &This::WrappedMethod<setter>;
1980
- }
1981
- static napi_callback WrapStaticSetter(StaticSetterTag<nullptr>)
1982
- NAPI_NOEXCEPT {
1983
- return nullptr;
1984
- }
1985
-
1986
- bool _construction_failed = true;
1987
- };
1988
-
1989
- class HandleScope {
1990
- public:
1991
- HandleScope(napi_env env, napi_handle_scope scope);
1992
- explicit HandleScope(Napi::Env env);
1993
- ~HandleScope();
1994
-
1995
- // Disallow copying to prevent double close of napi_handle_scope
1996
- NAPI_DISALLOW_ASSIGN_COPY(HandleScope)
1997
-
1998
- operator napi_handle_scope() const;
1999
-
2000
- Napi::Env Env() const;
2001
-
2002
- private:
2003
- napi_env _env;
2004
- napi_handle_scope _scope;
2005
- };
2006
-
2007
- class EscapableHandleScope {
2008
- public:
2009
- EscapableHandleScope(napi_env env, napi_escapable_handle_scope scope);
2010
- explicit EscapableHandleScope(Napi::Env env);
2011
- ~EscapableHandleScope();
2012
-
2013
- // Disallow copying to prevent double close of napi_escapable_handle_scope
2014
- NAPI_DISALLOW_ASSIGN_COPY(EscapableHandleScope)
2015
-
2016
- operator napi_escapable_handle_scope() const;
2017
-
2018
- Napi::Env Env() const;
2019
- Value Escape(napi_value escapee);
2020
-
2021
- private:
2022
- napi_env _env;
2023
- napi_escapable_handle_scope _scope;
2024
- };
2025
-
2026
- #if (NAPI_VERSION > 2)
2027
- class CallbackScope {
2028
- public:
2029
- CallbackScope(napi_env env, napi_callback_scope scope);
2030
- CallbackScope(napi_env env, napi_async_context context);
2031
- virtual ~CallbackScope();
2032
-
2033
- // Disallow copying to prevent double close of napi_callback_scope
2034
- NAPI_DISALLOW_ASSIGN_COPY(CallbackScope)
2035
-
2036
- operator napi_callback_scope() const;
2037
-
2038
- Napi::Env Env() const;
2039
-
2040
- private:
2041
- napi_env _env;
2042
- napi_callback_scope _scope;
2043
- };
2044
- #endif
2045
-
2046
- class AsyncContext {
2047
- public:
2048
- explicit AsyncContext(napi_env env, const char* resource_name);
2049
- explicit AsyncContext(napi_env env, const char* resource_name, const Object& resource);
2050
- virtual ~AsyncContext();
2051
-
2052
- AsyncContext(AsyncContext&& other);
2053
- AsyncContext& operator =(AsyncContext&& other);
2054
- NAPI_DISALLOW_ASSIGN_COPY(AsyncContext)
2055
-
2056
- operator napi_async_context() const;
2057
-
2058
- Napi::Env Env() const;
2059
-
2060
- private:
2061
- napi_env _env;
2062
- napi_async_context _context;
2063
- };
2064
-
2065
- class AsyncWorker {
2066
- public:
2067
- virtual ~AsyncWorker();
2068
-
2069
- // An async worker can be moved but cannot be copied.
2070
- AsyncWorker(AsyncWorker&& other);
2071
- AsyncWorker& operator =(AsyncWorker&& other);
2072
- NAPI_DISALLOW_ASSIGN_COPY(AsyncWorker)
2073
-
2074
- operator napi_async_work() const;
2075
-
2076
- Napi::Env Env() const;
2077
-
2078
- void Queue();
2079
- void Cancel();
2080
- void SuppressDestruct();
2081
-
2082
- ObjectReference& Receiver();
2083
- FunctionReference& Callback();
2084
-
2085
- virtual void OnExecute(Napi::Env env);
2086
- virtual void OnWorkComplete(Napi::Env env,
2087
- napi_status status);
2088
-
2089
- protected:
2090
- explicit AsyncWorker(const Function& callback);
2091
- explicit AsyncWorker(const Function& callback,
2092
- const char* resource_name);
2093
- explicit AsyncWorker(const Function& callback,
2094
- const char* resource_name,
2095
- const Object& resource);
2096
- explicit AsyncWorker(const Object& receiver,
2097
- const Function& callback);
2098
- explicit AsyncWorker(const Object& receiver,
2099
- const Function& callback,
2100
- const char* resource_name);
2101
- explicit AsyncWorker(const Object& receiver,
2102
- const Function& callback,
2103
- const char* resource_name,
2104
- const Object& resource);
2105
-
2106
- explicit AsyncWorker(Napi::Env env);
2107
- explicit AsyncWorker(Napi::Env env,
2108
- const char* resource_name);
2109
- explicit AsyncWorker(Napi::Env env,
2110
- const char* resource_name,
2111
- const Object& resource);
2112
-
2113
- virtual void Execute() = 0;
2114
- virtual void OnOK();
2115
- virtual void OnError(const Error& e);
2116
- virtual void Destroy();
2117
- virtual std::vector<napi_value> GetResult(Napi::Env env);
2118
-
2119
- void SetError(const std::string& error);
2120
-
2121
- private:
2122
- static inline void OnAsyncWorkExecute(napi_env env, void* asyncworker);
2123
- static inline void OnAsyncWorkComplete(napi_env env,
2124
- napi_status status,
2125
- void* asyncworker);
2126
-
2127
- napi_env _env;
2128
- napi_async_work _work;
2129
- ObjectReference _receiver;
2130
- FunctionReference _callback;
2131
- std::string _error;
2132
- bool _suppress_destruct;
2133
- };
2134
-
2135
- #if (NAPI_VERSION > 3 && !defined(__wasm32__))
2136
- class ThreadSafeFunction {
2137
- public:
2138
- // This API may only be called from the main thread.
2139
- template <typename ResourceString>
2140
- static ThreadSafeFunction New(napi_env env,
2141
- const Function& callback,
2142
- ResourceString resourceName,
2143
- size_t maxQueueSize,
2144
- size_t initialThreadCount);
2145
-
2146
- // This API may only be called from the main thread.
2147
- template <typename ResourceString, typename ContextType>
2148
- static ThreadSafeFunction New(napi_env env,
2149
- const Function& callback,
2150
- ResourceString resourceName,
2151
- size_t maxQueueSize,
2152
- size_t initialThreadCount,
2153
- ContextType* context);
2154
-
2155
- // This API may only be called from the main thread.
2156
- template <typename ResourceString, typename Finalizer>
2157
- static ThreadSafeFunction New(napi_env env,
2158
- const Function& callback,
2159
- ResourceString resourceName,
2160
- size_t maxQueueSize,
2161
- size_t initialThreadCount,
2162
- Finalizer finalizeCallback);
2163
-
2164
- // This API may only be called from the main thread.
2165
- template <typename ResourceString, typename Finalizer,
2166
- typename FinalizerDataType>
2167
- static ThreadSafeFunction New(napi_env env,
2168
- const Function& callback,
2169
- ResourceString resourceName,
2170
- size_t maxQueueSize,
2171
- size_t initialThreadCount,
2172
- Finalizer finalizeCallback,
2173
- FinalizerDataType* data);
2174
-
2175
- // This API may only be called from the main thread.
2176
- template <typename ResourceString, typename ContextType, typename Finalizer>
2177
- static ThreadSafeFunction New(napi_env env,
2178
- const Function& callback,
2179
- ResourceString resourceName,
2180
- size_t maxQueueSize,
2181
- size_t initialThreadCount,
2182
- ContextType* context,
2183
- Finalizer finalizeCallback);
2184
-
2185
- // This API may only be called from the main thread.
2186
- template <typename ResourceString, typename ContextType,
2187
- typename Finalizer, typename FinalizerDataType>
2188
- static ThreadSafeFunction New(napi_env env,
2189
- const Function& callback,
2190
- ResourceString resourceName,
2191
- size_t maxQueueSize,
2192
- size_t initialThreadCount,
2193
- ContextType* context,
2194
- Finalizer finalizeCallback,
2195
- FinalizerDataType* data);
2196
-
2197
- // This API may only be called from the main thread.
2198
- template <typename ResourceString>
2199
- static ThreadSafeFunction New(napi_env env,
2200
- const Function& callback,
2201
- const Object& resource,
2202
- ResourceString resourceName,
2203
- size_t maxQueueSize,
2204
- size_t initialThreadCount);
2205
-
2206
- // This API may only be called from the main thread.
2207
- template <typename ResourceString, typename ContextType>
2208
- static ThreadSafeFunction New(napi_env env,
2209
- const Function& callback,
2210
- const Object& resource,
2211
- ResourceString resourceName,
2212
- size_t maxQueueSize,
2213
- size_t initialThreadCount,
2214
- ContextType* context);
2215
-
2216
- // This API may only be called from the main thread.
2217
- template <typename ResourceString, typename Finalizer>
2218
- static ThreadSafeFunction New(napi_env env,
2219
- const Function& callback,
2220
- const Object& resource,
2221
- ResourceString resourceName,
2222
- size_t maxQueueSize,
2223
- size_t initialThreadCount,
2224
- Finalizer finalizeCallback);
2225
-
2226
- // This API may only be called from the main thread.
2227
- template <typename ResourceString, typename Finalizer,
2228
- typename FinalizerDataType>
2229
- static ThreadSafeFunction New(napi_env env,
2230
- const Function& callback,
2231
- const Object& resource,
2232
- ResourceString resourceName,
2233
- size_t maxQueueSize,
2234
- size_t initialThreadCount,
2235
- Finalizer finalizeCallback,
2236
- FinalizerDataType* data);
2237
-
2238
- // This API may only be called from the main thread.
2239
- template <typename ResourceString, typename ContextType, typename Finalizer>
2240
- static ThreadSafeFunction New(napi_env env,
2241
- const Function& callback,
2242
- const Object& resource,
2243
- ResourceString resourceName,
2244
- size_t maxQueueSize,
2245
- size_t initialThreadCount,
2246
- ContextType* context,
2247
- Finalizer finalizeCallback);
2248
-
2249
- // This API may only be called from the main thread.
2250
- template <typename ResourceString, typename ContextType,
2251
- typename Finalizer, typename FinalizerDataType>
2252
- static ThreadSafeFunction New(napi_env env,
2253
- const Function& callback,
2254
- const Object& resource,
2255
- ResourceString resourceName,
2256
- size_t maxQueueSize,
2257
- size_t initialThreadCount,
2258
- ContextType* context,
2259
- Finalizer finalizeCallback,
2260
- FinalizerDataType* data);
2261
-
2262
- ThreadSafeFunction();
2263
- ThreadSafeFunction(napi_threadsafe_function tsFunctionValue);
2264
-
2265
- operator napi_threadsafe_function() const;
2266
-
2267
- // This API may be called from any thread.
2268
- napi_status BlockingCall() const;
2269
-
2270
- // This API may be called from any thread.
2271
- template <typename Callback>
2272
- napi_status BlockingCall(Callback callback) const;
2273
-
2274
- // This API may be called from any thread.
2275
- template <typename DataType, typename Callback>
2276
- napi_status BlockingCall(DataType* data, Callback callback) const;
2277
-
2278
- // This API may be called from any thread.
2279
- napi_status NonBlockingCall() const;
2280
-
2281
- // This API may be called from any thread.
2282
- template <typename Callback>
2283
- napi_status NonBlockingCall(Callback callback) const;
2284
-
2285
- // This API may be called from any thread.
2286
- template <typename DataType, typename Callback>
2287
- napi_status NonBlockingCall(DataType* data, Callback callback) const;
2288
-
2289
- // This API may only be called from the main thread.
2290
- void Ref(napi_env env) const;
2291
-
2292
- // This API may only be called from the main thread.
2293
- void Unref(napi_env env) const;
2294
-
2295
- // This API may be called from any thread.
2296
- napi_status Acquire() const;
2297
-
2298
- // This API may be called from any thread.
2299
- napi_status Release();
2300
-
2301
- // This API may be called from any thread.
2302
- napi_status Abort();
2303
-
2304
- struct ConvertibleContext
2305
- {
2306
- template <class T>
2307
- operator T*() { return static_cast<T*>(context); }
2308
- void* context;
2309
- };
2310
-
2311
- // This API may be called from any thread.
2312
- ConvertibleContext GetContext() const;
2313
-
2314
- private:
2315
- using CallbackWrapper = std::function<void(Napi::Env, Napi::Function)>;
2316
-
2317
- template <typename ResourceString, typename ContextType,
2318
- typename Finalizer, typename FinalizerDataType>
2319
- static ThreadSafeFunction New(napi_env env,
2320
- const Function& callback,
2321
- const Object& resource,
2322
- ResourceString resourceName,
2323
- size_t maxQueueSize,
2324
- size_t initialThreadCount,
2325
- ContextType* context,
2326
- Finalizer finalizeCallback,
2327
- FinalizerDataType* data,
2328
- napi_finalize wrapper);
2329
-
2330
- napi_status CallInternal(CallbackWrapper* callbackWrapper,
2331
- napi_threadsafe_function_call_mode mode) const;
2332
-
2333
- static void CallJS(napi_env env,
2334
- napi_value jsCallback,
2335
- void* context,
2336
- void* data);
2337
-
2338
- napi_threadsafe_function _tsfn;
2339
- };
2340
-
2341
- // A TypedThreadSafeFunction by default has no context (nullptr) and can
2342
- // accept any type (void) to its CallJs.
2343
- template <typename ContextType = std::nullptr_t,
2344
- typename DataType = void,
2345
- void (*CallJs)(Napi::Env, Napi::Function, ContextType*, DataType*) =
2346
- nullptr>
2347
- class TypedThreadSafeFunction {
2348
- public:
2349
- // This API may only be called from the main thread.
2350
- // Helper function that returns nullptr if running Node-API 5+, otherwise a
2351
- // non-empty, no-op Function. This provides the ability to specify at
2352
- // compile-time a callback parameter to `New` that safely does no action
2353
- // when targeting _any_ Node-API version.
2354
- #if NAPI_VERSION > 4
2355
- static std::nullptr_t EmptyFunctionFactory(Napi::Env env);
2356
- #else
2357
- static Napi::Function EmptyFunctionFactory(Napi::Env env);
2358
- #endif
2359
- static Napi::Function FunctionOrEmpty(Napi::Env env,
2360
- Napi::Function& callback);
2361
-
2362
- #if NAPI_VERSION > 4
2363
- // This API may only be called from the main thread.
2364
- // Creates a new threadsafe function with:
2365
- // Callback [missing] Resource [missing] Finalizer [missing]
2366
- template <typename ResourceString>
2367
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2368
- napi_env env,
2369
- ResourceString resourceName,
2370
- size_t maxQueueSize,
2371
- size_t initialThreadCount,
2372
- ContextType* context = nullptr);
2373
-
2374
- // This API may only be called from the main thread.
2375
- // Creates a new threadsafe function with:
2376
- // Callback [missing] Resource [passed] Finalizer [missing]
2377
- template <typename ResourceString>
2378
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2379
- napi_env env,
2380
- const Object& resource,
2381
- ResourceString resourceName,
2382
- size_t maxQueueSize,
2383
- size_t initialThreadCount,
2384
- ContextType* context = nullptr);
2385
-
2386
- // This API may only be called from the main thread.
2387
- // Creates a new threadsafe function with:
2388
- // Callback [missing] Resource [missing] Finalizer [passed]
2389
- template <typename ResourceString,
2390
- typename Finalizer,
2391
- typename FinalizerDataType = void>
2392
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2393
- napi_env env,
2394
- ResourceString resourceName,
2395
- size_t maxQueueSize,
2396
- size_t initialThreadCount,
2397
- ContextType* context,
2398
- Finalizer finalizeCallback,
2399
- FinalizerDataType* data = nullptr);
2400
-
2401
- // This API may only be called from the main thread.
2402
- // Creates a new threadsafe function with:
2403
- // Callback [missing] Resource [passed] Finalizer [passed]
2404
- template <typename ResourceString,
2405
- typename Finalizer,
2406
- typename FinalizerDataType = void>
2407
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2408
- napi_env env,
2409
- const Object& resource,
2410
- ResourceString resourceName,
2411
- size_t maxQueueSize,
2412
- size_t initialThreadCount,
2413
- ContextType* context,
2414
- Finalizer finalizeCallback,
2415
- FinalizerDataType* data = nullptr);
2416
- #endif
2417
-
2418
- // This API may only be called from the main thread.
2419
- // Creates a new threadsafe function with:
2420
- // Callback [passed] Resource [missing] Finalizer [missing]
2421
- template <typename ResourceString>
2422
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2423
- napi_env env,
2424
- const Function& callback,
2425
- ResourceString resourceName,
2426
- size_t maxQueueSize,
2427
- size_t initialThreadCount,
2428
- ContextType* context = nullptr);
2429
-
2430
- // This API may only be called from the main thread.
2431
- // Creates a new threadsafe function with:
2432
- // Callback [passed] Resource [passed] Finalizer [missing]
2433
- template <typename ResourceString>
2434
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2435
- napi_env env,
2436
- const Function& callback,
2437
- const Object& resource,
2438
- ResourceString resourceName,
2439
- size_t maxQueueSize,
2440
- size_t initialThreadCount,
2441
- ContextType* context = nullptr);
2442
-
2443
- // This API may only be called from the main thread.
2444
- // Creates a new threadsafe function with:
2445
- // Callback [passed] Resource [missing] Finalizer [passed]
2446
- template <typename ResourceString,
2447
- typename Finalizer,
2448
- typename FinalizerDataType = void>
2449
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2450
- napi_env env,
2451
- const Function& callback,
2452
- ResourceString resourceName,
2453
- size_t maxQueueSize,
2454
- size_t initialThreadCount,
2455
- ContextType* context,
2456
- Finalizer finalizeCallback,
2457
- FinalizerDataType* data = nullptr);
2458
-
2459
- // This API may only be called from the main thread.
2460
- // Creates a new threadsafe function with:
2461
- // Callback [passed] Resource [passed] Finalizer [passed]
2462
- template <typename CallbackType,
2463
- typename ResourceString,
2464
- typename Finalizer,
2465
- typename FinalizerDataType>
2466
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2467
- napi_env env,
2468
- CallbackType callback,
2469
- const Object& resource,
2470
- ResourceString resourceName,
2471
- size_t maxQueueSize,
2472
- size_t initialThreadCount,
2473
- ContextType* context,
2474
- Finalizer finalizeCallback,
2475
- FinalizerDataType* data = nullptr);
2476
-
2477
- TypedThreadSafeFunction<ContextType, DataType, CallJs>();
2478
- TypedThreadSafeFunction<ContextType, DataType, CallJs>(
2479
- napi_threadsafe_function tsFunctionValue);
2480
-
2481
- operator napi_threadsafe_function() const;
2482
-
2483
- // This API may be called from any thread.
2484
- napi_status BlockingCall(DataType* data = nullptr) const;
2485
-
2486
- // This API may be called from any thread.
2487
- napi_status NonBlockingCall(DataType* data = nullptr) const;
2488
-
2489
- // This API may only be called from the main thread.
2490
- void Ref(napi_env env) const;
2491
-
2492
- // This API may only be called from the main thread.
2493
- void Unref(napi_env env) const;
2494
-
2495
- // This API may be called from any thread.
2496
- napi_status Acquire() const;
2497
-
2498
- // This API may be called from any thread.
2499
- napi_status Release();
2500
-
2501
- // This API may be called from any thread.
2502
- napi_status Abort();
2503
-
2504
- // This API may be called from any thread.
2505
- ContextType* GetContext() const;
2506
-
2507
- private:
2508
- template <typename ResourceString,
2509
- typename Finalizer,
2510
- typename FinalizerDataType>
2511
- static TypedThreadSafeFunction<ContextType, DataType, CallJs> New(
2512
- napi_env env,
2513
- const Function& callback,
2514
- const Object& resource,
2515
- ResourceString resourceName,
2516
- size_t maxQueueSize,
2517
- size_t initialThreadCount,
2518
- ContextType* context,
2519
- Finalizer finalizeCallback,
2520
- FinalizerDataType* data,
2521
- napi_finalize wrapper);
2522
-
2523
- static void CallJsInternal(napi_env env,
2524
- napi_value jsCallback,
2525
- void* context,
2526
- void* data);
2527
-
2528
- protected:
2529
- napi_threadsafe_function _tsfn;
2530
- };
2531
- template <typename DataType>
2532
- class AsyncProgressWorkerBase : public AsyncWorker {
2533
- public:
2534
- virtual void OnWorkProgress(DataType* data) = 0;
2535
- class ThreadSafeData {
2536
- public:
2537
- ThreadSafeData(AsyncProgressWorkerBase* asyncprogressworker, DataType* data)
2538
- : _asyncprogressworker(asyncprogressworker), _data(data) {}
2539
-
2540
- AsyncProgressWorkerBase* asyncprogressworker() { return _asyncprogressworker; };
2541
- DataType* data() { return _data; };
2542
-
2543
- private:
2544
- AsyncProgressWorkerBase* _asyncprogressworker;
2545
- DataType* _data;
2546
- };
2547
- void OnWorkComplete(Napi::Env env, napi_status status) override;
2548
- protected:
2549
- explicit AsyncProgressWorkerBase(const Object& receiver,
2550
- const Function& callback,
2551
- const char* resource_name,
2552
- const Object& resource,
2553
- size_t queue_size = 1);
2554
- virtual ~AsyncProgressWorkerBase();
2555
-
2556
- // Optional callback of Napi::ThreadSafeFunction only available after NAPI_VERSION 4.
2557
- // Refs: https://github.com/nodejs/node/pull/27791
2558
- #if NAPI_VERSION > 4
2559
- explicit AsyncProgressWorkerBase(Napi::Env env,
2560
- const char* resource_name,
2561
- const Object& resource,
2562
- size_t queue_size = 1);
2563
- #endif
2564
-
2565
- static inline void OnAsyncWorkProgress(Napi::Env env,
2566
- Napi::Function jsCallback,
2567
- void* data);
2568
-
2569
- napi_status NonBlockingCall(DataType* data);
2570
-
2571
- private:
2572
- ThreadSafeFunction _tsfn;
2573
- bool _work_completed = false;
2574
- napi_status _complete_status;
2575
- static inline void OnThreadSafeFunctionFinalize(Napi::Env env, void* data, AsyncProgressWorkerBase* context);
2576
- };
2577
-
2578
- template<class T>
2579
- class AsyncProgressWorker : public AsyncProgressWorkerBase<void> {
2580
- public:
2581
- virtual ~AsyncProgressWorker();
2582
-
2583
- class ExecutionProgress {
2584
- friend class AsyncProgressWorker;
2585
- public:
2586
- void Signal() const;
2587
- void Send(const T* data, size_t count) const;
2588
- private:
2589
- explicit ExecutionProgress(AsyncProgressWorker* worker) : _worker(worker) {}
2590
- AsyncProgressWorker* const _worker;
2591
- };
2592
-
2593
- void OnWorkProgress(void*) override;
2594
-
2595
- protected:
2596
- explicit AsyncProgressWorker(const Function& callback);
2597
- explicit AsyncProgressWorker(const Function& callback,
2598
- const char* resource_name);
2599
- explicit AsyncProgressWorker(const Function& callback,
2600
- const char* resource_name,
2601
- const Object& resource);
2602
- explicit AsyncProgressWorker(const Object& receiver,
2603
- const Function& callback);
2604
- explicit AsyncProgressWorker(const Object& receiver,
2605
- const Function& callback,
2606
- const char* resource_name);
2607
- explicit AsyncProgressWorker(const Object& receiver,
2608
- const Function& callback,
2609
- const char* resource_name,
2610
- const Object& resource);
2611
-
2612
- // Optional callback of Napi::ThreadSafeFunction only available after NAPI_VERSION 4.
2613
- // Refs: https://github.com/nodejs/node/pull/27791
2614
- #if NAPI_VERSION > 4
2615
- explicit AsyncProgressWorker(Napi::Env env);
2616
- explicit AsyncProgressWorker(Napi::Env env,
2617
- const char* resource_name);
2618
- explicit AsyncProgressWorker(Napi::Env env,
2619
- const char* resource_name,
2620
- const Object& resource);
2621
- #endif
2622
- virtual void Execute(const ExecutionProgress& progress) = 0;
2623
- virtual void OnProgress(const T* data, size_t count) = 0;
2624
-
2625
- private:
2626
- void Execute() override;
2627
- void Signal() const;
2628
- void SendProgress_(const T* data, size_t count);
2629
-
2630
- std::mutex _mutex;
2631
- T* _asyncdata;
2632
- size_t _asyncsize;
2633
- };
2634
-
2635
- template<class T>
2636
- class AsyncProgressQueueWorker : public AsyncProgressWorkerBase<std::pair<T*, size_t>> {
2637
- public:
2638
- virtual ~AsyncProgressQueueWorker() {};
2639
-
2640
- class ExecutionProgress {
2641
- friend class AsyncProgressQueueWorker;
2642
- public:
2643
- void Signal() const;
2644
- void Send(const T* data, size_t count) const;
2645
- private:
2646
- explicit ExecutionProgress(AsyncProgressQueueWorker* worker) : _worker(worker) {}
2647
- AsyncProgressQueueWorker* const _worker;
2648
- };
2649
-
2650
- void OnWorkComplete(Napi::Env env, napi_status status) override;
2651
- void OnWorkProgress(std::pair<T*, size_t>*) override;
2652
-
2653
- protected:
2654
- explicit AsyncProgressQueueWorker(const Function& callback);
2655
- explicit AsyncProgressQueueWorker(const Function& callback,
2656
- const char* resource_name);
2657
- explicit AsyncProgressQueueWorker(const Function& callback,
2658
- const char* resource_name,
2659
- const Object& resource);
2660
- explicit AsyncProgressQueueWorker(const Object& receiver,
2661
- const Function& callback);
2662
- explicit AsyncProgressQueueWorker(const Object& receiver,
2663
- const Function& callback,
2664
- const char* resource_name);
2665
- explicit AsyncProgressQueueWorker(const Object& receiver,
2666
- const Function& callback,
2667
- const char* resource_name,
2668
- const Object& resource);
2669
-
2670
- // Optional callback of Napi::ThreadSafeFunction only available after NAPI_VERSION 4.
2671
- // Refs: https://github.com/nodejs/node/pull/27791
2672
- #if NAPI_VERSION > 4
2673
- explicit AsyncProgressQueueWorker(Napi::Env env);
2674
- explicit AsyncProgressQueueWorker(Napi::Env env,
2675
- const char* resource_name);
2676
- explicit AsyncProgressQueueWorker(Napi::Env env,
2677
- const char* resource_name,
2678
- const Object& resource);
2679
- #endif
2680
- virtual void Execute(const ExecutionProgress& progress) = 0;
2681
- virtual void OnProgress(const T* data, size_t count) = 0;
2682
-
2683
- private:
2684
- void Execute() override;
2685
- void Signal() const;
2686
- void SendProgress_(const T* data, size_t count);
2687
- };
2688
- #endif // NAPI_VERSION > 3 && !defined(__wasm32__)
2689
-
2690
- // Memory management.
2691
- class MemoryManagement {
2692
- public:
2693
- static int64_t AdjustExternalMemory(Env env, int64_t change_in_bytes);
2694
- };
2695
-
2696
- // Version management
2697
- class VersionManagement {
2698
- public:
2699
- static uint32_t GetNapiVersion(Env env);
2700
- static const napi_node_version* GetNodeVersion(Env env);
2701
- };
2702
-
2703
- #if NAPI_VERSION > 5
2704
- template <typename T>
2705
- class Addon : public InstanceWrap<T> {
2706
- public:
2707
- static inline Object Init(Env env, Object exports);
2708
- static T* Unwrap(Object wrapper);
2709
-
2710
- protected:
2711
- using AddonProp = ClassPropertyDescriptor<T>;
2712
- void DefineAddon(Object exports,
2713
- const std::initializer_list<AddonProp>& props);
2714
- Napi::Object DefineProperties(Object object,
2715
- const std::initializer_list<AddonProp>& props);
2716
-
2717
- private:
2718
- Object entry_point_;
2719
- };
2720
- #endif // NAPI_VERSION > 5
2721
-
2722
- } // namespace Napi
2723
-
2724
- // Inline implementations of all the above class methods are included here.
2725
- #include "napi-inl.h"
2726
-
2727
- #endif // SRC_NAPI_H_