node-addon-api 3.0.1 → 3.2.1

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 (74) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/README.md +104 -60
  3. package/common.gypi +1 -1
  4. package/index.js +4 -3
  5. package/napi-inl.deprecated.h +8 -8
  6. package/napi-inl.h +1206 -540
  7. package/napi.h +821 -522
  8. package/package-support.json +21 -0
  9. package/package.json +80 -4
  10. package/tools/README.md +8 -2
  11. package/tools/clang-format.js +67 -0
  12. package/tools/conversion.js +4 -4
  13. package/.editorconfig +0 -8
  14. package/.travis.yml +0 -59
  15. package/CODE_OF_CONDUCT.md +0 -4
  16. package/CONTRIBUTING.md +0 -66
  17. package/appveyor.yml +0 -48
  18. package/benchmark/README.md +0 -47
  19. package/benchmark/binding.gyp +0 -25
  20. package/benchmark/function_args.cc +0 -153
  21. package/benchmark/function_args.js +0 -52
  22. package/benchmark/index.js +0 -34
  23. package/benchmark/property_descriptor.cc +0 -60
  24. package/benchmark/property_descriptor.js +0 -29
  25. package/doc/Doxyfile +0 -2450
  26. package/doc/array_buffer.md +0 -129
  27. package/doc/async_context.md +0 -86
  28. package/doc/async_operations.md +0 -31
  29. package/doc/async_worker.md +0 -427
  30. package/doc/async_worker_variants.md +0 -456
  31. package/doc/basic_types.md +0 -423
  32. package/doc/bigint.md +0 -93
  33. package/doc/boolean.md +0 -64
  34. package/doc/buffer.md +0 -140
  35. package/doc/callback_scope.md +0 -54
  36. package/doc/callbackinfo.md +0 -97
  37. package/doc/checker-tool.md +0 -32
  38. package/doc/class_property_descriptor.md +0 -117
  39. package/doc/cmake-js.md +0 -68
  40. package/doc/conversion-tool.md +0 -28
  41. package/doc/creating_a_release.md +0 -62
  42. package/doc/dataview.md +0 -244
  43. package/doc/date.md +0 -68
  44. package/doc/env.md +0 -132
  45. package/doc/error.md +0 -115
  46. package/doc/error_handling.md +0 -186
  47. package/doc/escapable_handle_scope.md +0 -82
  48. package/doc/external.md +0 -59
  49. package/doc/function.md +0 -401
  50. package/doc/function_reference.md +0 -238
  51. package/doc/generator.md +0 -13
  52. package/doc/handle_scope.md +0 -65
  53. package/doc/memory_management.md +0 -27
  54. package/doc/node-gyp.md +0 -82
  55. package/doc/number.md +0 -163
  56. package/doc/object.md +0 -275
  57. package/doc/object_lifetime_management.md +0 -83
  58. package/doc/object_reference.md +0 -117
  59. package/doc/object_wrap.md +0 -851
  60. package/doc/prebuild_tools.md +0 -16
  61. package/doc/promises.md +0 -74
  62. package/doc/property_descriptor.md +0 -286
  63. package/doc/range_error.md +0 -59
  64. package/doc/reference.md +0 -111
  65. package/doc/setup.md +0 -81
  66. package/doc/string.md +0 -89
  67. package/doc/symbol.md +0 -44
  68. package/doc/threadsafe_function.md +0 -320
  69. package/doc/type_error.md +0 -59
  70. package/doc/typed_array.md +0 -74
  71. package/doc/typed_array_of.md +0 -133
  72. package/doc/value.md +0 -278
  73. package/doc/version_management.md +0 -43
  74. package/doc/working_with_javascript_values.md +0 -14
@@ -1,153 +0,0 @@
1
- #include "napi.h"
2
-
3
- static napi_value NoArgFunction_Core(napi_env env, napi_callback_info info) {
4
- (void) env;
5
- (void) info;
6
- return nullptr;
7
- }
8
-
9
- static napi_value OneArgFunction_Core(napi_env env, napi_callback_info info) {
10
- size_t argc = 1;
11
- napi_value argv;
12
- if (napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr) != napi_ok) {
13
- return nullptr;
14
- }
15
- (void) argv;
16
- return nullptr;
17
- }
18
-
19
- static napi_value TwoArgFunction_Core(napi_env env, napi_callback_info info) {
20
- size_t argc = 2;
21
- napi_value argv[2];
22
- if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
23
- return nullptr;
24
- }
25
- (void) argv[0];
26
- (void) argv[1];
27
- return nullptr;
28
- }
29
-
30
- static napi_value ThreeArgFunction_Core(napi_env env, napi_callback_info info) {
31
- size_t argc = 3;
32
- napi_value argv[3];
33
- if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
34
- return nullptr;
35
- }
36
- (void) argv[0];
37
- (void) argv[1];
38
- (void) argv[2];
39
- return nullptr;
40
- }
41
-
42
- static napi_value FourArgFunction_Core(napi_env env, napi_callback_info info) {
43
- size_t argc = 4;
44
- napi_value argv[4];
45
- if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
46
- return nullptr;
47
- }
48
- (void) argv[0];
49
- (void) argv[1];
50
- (void) argv[2];
51
- (void) argv[3];
52
- return nullptr;
53
- }
54
-
55
- static void NoArgFunction(const Napi::CallbackInfo& info) {
56
- (void) info;
57
- }
58
-
59
- static void OneArgFunction(const Napi::CallbackInfo& info) {
60
- Napi::Value argv0 = info[0]; (void) argv0;
61
- }
62
-
63
- static void TwoArgFunction(const Napi::CallbackInfo& info) {
64
- Napi::Value argv0 = info[0]; (void) argv0;
65
- Napi::Value argv1 = info[1]; (void) argv1;
66
- }
67
-
68
- static void ThreeArgFunction(const Napi::CallbackInfo& info) {
69
- Napi::Value argv0 = info[0]; (void) argv0;
70
- Napi::Value argv1 = info[1]; (void) argv1;
71
- Napi::Value argv2 = info[2]; (void) argv2;
72
- }
73
-
74
- static void FourArgFunction(const Napi::CallbackInfo& info) {
75
- Napi::Value argv0 = info[0]; (void) argv0;
76
- Napi::Value argv1 = info[1]; (void) argv1;
77
- Napi::Value argv2 = info[2]; (void) argv2;
78
- Napi::Value argv3 = info[3]; (void) argv3;
79
- }
80
-
81
- static Napi::Object Init(Napi::Env env, Napi::Object exports) {
82
- napi_value no_arg_function, one_arg_function, two_arg_function,
83
- three_arg_function, four_arg_function;
84
- napi_status status;
85
-
86
- status = napi_create_function(env,
87
- "noArgFunction",
88
- NAPI_AUTO_LENGTH,
89
- NoArgFunction_Core,
90
- nullptr,
91
- &no_arg_function);
92
- NAPI_THROW_IF_FAILED(env, status, Napi::Object());
93
-
94
- status = napi_create_function(env,
95
- "oneArgFunction",
96
- NAPI_AUTO_LENGTH,
97
- OneArgFunction_Core,
98
- nullptr,
99
- &one_arg_function);
100
- NAPI_THROW_IF_FAILED(env, status, Napi::Object());
101
-
102
- status = napi_create_function(env,
103
- "twoArgFunction",
104
- NAPI_AUTO_LENGTH,
105
- TwoArgFunction_Core,
106
- nullptr,
107
- &two_arg_function);
108
- NAPI_THROW_IF_FAILED(env, status, Napi::Object());
109
-
110
- status = napi_create_function(env,
111
- "threeArgFunction",
112
- NAPI_AUTO_LENGTH,
113
- ThreeArgFunction_Core,
114
- nullptr,
115
- &three_arg_function);
116
- NAPI_THROW_IF_FAILED(env, status, Napi::Object());
117
-
118
- status = napi_create_function(env,
119
- "fourArgFunction",
120
- NAPI_AUTO_LENGTH,
121
- FourArgFunction_Core,
122
- nullptr,
123
- &four_arg_function);
124
- NAPI_THROW_IF_FAILED(env, status, Napi::Object());
125
-
126
- Napi::Object core = Napi::Object::New(env);
127
- core["noArgFunction"] = Napi::Value(env, no_arg_function);
128
- core["oneArgFunction"] = Napi::Value(env, one_arg_function);
129
- core["twoArgFunction"] = Napi::Value(env, two_arg_function);
130
- core["threeArgFunction"] = Napi::Value(env, three_arg_function);
131
- core["fourArgFunction"] = Napi::Value(env, four_arg_function);
132
- exports["core"] = core;
133
-
134
- Napi::Object cplusplus = Napi::Object::New(env);
135
- cplusplus["noArgFunction"] = Napi::Function::New(env, NoArgFunction);
136
- cplusplus["oneArgFunction"] = Napi::Function::New(env, OneArgFunction);
137
- cplusplus["twoArgFunction"] = Napi::Function::New(env, TwoArgFunction);
138
- cplusplus["threeArgFunction"] = Napi::Function::New(env, ThreeArgFunction);
139
- cplusplus["fourArgFunction"] = Napi::Function::New(env, FourArgFunction);
140
- exports["cplusplus"] = cplusplus;
141
-
142
- Napi::Object templated = Napi::Object::New(env);
143
- templated["noArgFunction"] = Napi::Function::New<NoArgFunction>(env);
144
- templated["oneArgFunction"] = Napi::Function::New<OneArgFunction>(env);
145
- templated["twoArgFunction"] = Napi::Function::New<TwoArgFunction>(env);
146
- templated["threeArgFunction"] = Napi::Function::New<ThreeArgFunction>(env);
147
- templated["fourArgFunction"] = Napi::Function::New<FourArgFunction>(env);
148
- exports["templated"] = templated;
149
-
150
- return exports;
151
- }
152
-
153
- NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
@@ -1,52 +0,0 @@
1
- const path = require('path');
2
- const Benchmark = require('benchmark');
3
- const addonName = path.basename(__filename, '.js');
4
-
5
- [ addonName, addonName + '_noexcept' ]
6
- .forEach((addonName) => {
7
- const rootAddon = require(`./build/Release/${addonName}`);
8
- const implems = Object.keys(rootAddon);
9
- const anObject = {};
10
-
11
- console.log(`${addonName}: `);
12
-
13
- console.log('no arguments:');
14
- implems.reduce((suite, implem) => {
15
- const fn = rootAddon[implem].noArgFunction;
16
- return suite.add(implem, () => fn());
17
- }, new Benchmark.Suite)
18
- .on('cycle', (event) => console.log(String(event.target)))
19
- .run();
20
-
21
- console.log('one argument:');
22
- implems.reduce((suite, implem) => {
23
- const fn = rootAddon[implem].oneArgFunction;
24
- return suite.add(implem, () => fn('x'));
25
- }, new Benchmark.Suite)
26
- .on('cycle', (event) => console.log(String(event.target)))
27
- .run();
28
-
29
- console.log('two arguments:');
30
- implems.reduce((suite, implem) => {
31
- const fn = rootAddon[implem].twoArgFunction;
32
- return suite.add(implem, () => fn('x', 12));
33
- }, new Benchmark.Suite)
34
- .on('cycle', (event) => console.log(String(event.target)))
35
- .run();
36
-
37
- console.log('three arguments:');
38
- implems.reduce((suite, implem) => {
39
- const fn = rootAddon[implem].threeArgFunction;
40
- return suite.add(implem, () => fn('x', 12, true));
41
- }, new Benchmark.Suite)
42
- .on('cycle', (event) => console.log(String(event.target)))
43
- .run();
44
-
45
- console.log('four arguments:');
46
- implems.reduce((suite, implem) => {
47
- const fn = rootAddon[implem].fourArgFunction;
48
- return suite.add(implem, () => fn('x', 12, true, anObject));
49
- }, new Benchmark.Suite)
50
- .on('cycle', (event) => console.log(String(event.target)))
51
- .run();
52
- });
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- const { readdirSync } = require('fs');
4
- const { spawnSync } = require('child_process');
5
- const path = require('path');
6
-
7
- let benchmarks = [];
8
-
9
- if (!!process.env.npm_config_benchmarks) {
10
- benchmarks = process.env.npm_config_benchmarks
11
- .split(';')
12
- .map((item) => (item + '.js'));
13
- }
14
-
15
- // Run each file in this directory or the list given on the command line except
16
- // index.js as a Node.js process.
17
- (benchmarks.length > 0 ? benchmarks : readdirSync(__dirname))
18
- .filter((item) => (item !== 'index.js' && item.match(/\.js$/)))
19
- .map((item) => path.join(__dirname, item))
20
- .forEach((item) => {
21
- const child = spawnSync(process.execPath, [
22
- '--expose-gc',
23
- item
24
- ], { stdio: 'inherit' });
25
- if (child.signal) {
26
- console.error(`Tests aborted with ${child.signal}`);
27
- process.exitCode = 1;
28
- } else {
29
- process.exitCode = child.status;
30
- }
31
- if (child.status !== 0) {
32
- process.exit(process.exitCode);
33
- }
34
- });
@@ -1,60 +0,0 @@
1
- #include "napi.h"
2
-
3
- static napi_value Getter_Core(napi_env env, napi_callback_info info) {
4
- (void) info;
5
- napi_value result;
6
- napi_status status = napi_create_uint32(env, 42, &result);
7
- NAPI_THROW_IF_FAILED(env, status, nullptr);
8
- return result;
9
- }
10
-
11
- static napi_value Setter_Core(napi_env env, napi_callback_info info) {
12
- size_t argc = 1;
13
- napi_value argv;
14
- napi_status status =
15
- napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr);
16
- NAPI_THROW_IF_FAILED(env, status, nullptr);
17
- (void) argv;
18
- return nullptr;
19
- }
20
-
21
- static Napi::Value Getter(const Napi::CallbackInfo& info) {
22
- return Napi::Number::New(info.Env(), 42);
23
- }
24
-
25
- static void Setter(const Napi::CallbackInfo& info) {
26
- (void) info[0];
27
- }
28
-
29
- static Napi::Object Init(Napi::Env env, Napi::Object exports) {
30
- napi_status status;
31
- napi_property_descriptor core_prop = {
32
- "core",
33
- nullptr,
34
- nullptr,
35
- Getter_Core,
36
- Setter_Core,
37
- nullptr,
38
- napi_enumerable,
39
- nullptr
40
- };
41
-
42
- status = napi_define_properties(env, exports, 1, &core_prop);
43
- NAPI_THROW_IF_FAILED(env, status, Napi::Object());
44
-
45
- exports.DefineProperty(
46
- Napi::PropertyDescriptor::Accessor(env,
47
- exports,
48
- "cplusplus",
49
- Getter,
50
- Setter,
51
- napi_enumerable));
52
-
53
- exports.DefineProperty(
54
- Napi::PropertyDescriptor::Accessor<Getter, Setter>("templated",
55
- napi_enumerable));
56
-
57
- return exports;
58
- }
59
-
60
- NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
@@ -1,29 +0,0 @@
1
- const path = require('path');
2
- const Benchmark = require('benchmark');
3
- const addonName = path.basename(__filename, '.js');
4
-
5
- [ addonName, addonName + '_noexcept' ]
6
- .forEach((addonName) => {
7
- const rootAddon = require(`./build/Release/${addonName}`);
8
- const getters = new Benchmark.Suite;
9
- const setters = new Benchmark.Suite;
10
-
11
- console.log(`${addonName}: `);
12
-
13
- Object.keys(rootAddon).forEach((key) => {
14
- getters.add(`${key} getter`, () => {
15
- const x = rootAddon[key];
16
- });
17
- setters.add(`${key} setter`, () => {
18
- rootAddon[key] = 5;
19
- })
20
- });
21
-
22
- getters
23
- .on('cycle', (event) => console.log(String(event.target)))
24
- .run();
25
-
26
- setters
27
- .on('cycle', (event) => console.log(String(event.target)))
28
- .run();
29
- });