node-addon-api 1.7.2 → 3.0.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 (53) hide show
  1. package/.travis.yml +3 -9
  2. package/CHANGELOG.md +154 -9
  3. package/README.md +58 -9
  4. package/benchmark/README.md +47 -0
  5. package/benchmark/binding.gyp +25 -0
  6. package/benchmark/function_args.cc +153 -0
  7. package/benchmark/function_args.js +52 -0
  8. package/benchmark/index.js +34 -0
  9. package/benchmark/property_descriptor.cc +60 -0
  10. package/benchmark/property_descriptor.js +29 -0
  11. package/common.gypi +21 -0
  12. package/doc/array_buffer.md +1 -1
  13. package/doc/async_context.md +10 -0
  14. package/doc/async_operations.md +1 -1
  15. package/doc/async_worker.md +56 -26
  16. package/doc/async_worker_variants.md +456 -0
  17. package/doc/basic_types.md +8 -0
  18. package/doc/bigint.md +2 -1
  19. package/doc/class_property_descriptor.md +5 -6
  20. package/doc/cmake-js.md +58 -9
  21. package/doc/creating_a_release.md +5 -5
  22. package/doc/date.md +68 -0
  23. package/doc/env.md +14 -0
  24. package/doc/function.md +108 -1
  25. package/doc/object.md +74 -1
  26. package/doc/object_lifetime_management.md +1 -1
  27. package/doc/object_wrap.md +291 -4
  28. package/doc/prebuild_tools.md +1 -1
  29. package/doc/property_descriptor.md +64 -9
  30. package/doc/setup.md +0 -1
  31. package/doc/string.md +1 -1
  32. package/doc/symbol.md +1 -1
  33. package/doc/threadsafe_function.md +18 -1
  34. package/doc/value.md +10 -1
  35. package/except.gypi +16 -0
  36. package/index.js +5 -42
  37. package/napi-inl.h +1048 -147
  38. package/napi.h +424 -49
  39. package/node_api.gyp +9 -0
  40. package/noexcept.gypi +16 -0
  41. package/{src/nothing.c → nothing.c} +0 -0
  42. package/package.json +244 -47
  43. package/tools/README.md +4 -4
  44. package/tools/conversion.js +0 -4
  45. package/external-napi/node_api.h +0 -7
  46. package/src/node_api.cc +0 -3655
  47. package/src/node_api.gyp +0 -21
  48. package/src/node_api.h +0 -588
  49. package/src/node_api_types.h +0 -115
  50. package/src/node_internals.cc +0 -142
  51. package/src/node_internals.h +0 -157
  52. package/src/util-inl.h +0 -38
  53. package/src/util.h +0 -7
@@ -26,15 +26,9 @@ Void Init(Env env) {
26
26
  Object obj = Object::New(env);
27
27
 
28
28
  // Accessor
29
- PropertyDescriptor pd1 = PropertyDescriptor::Accessor(env,
30
- obj,
31
- "pd1",
32
- TestGetter);
33
- PropertyDescriptor pd2 = PropertyDescriptor::Accessor(env,
34
- obj,
35
- "pd2",
36
- TestGetter,
37
- TestSetter);
29
+ PropertyDescriptor pd1 = PropertyDescriptor::Accessor<TestGetter>("pd1");
30
+ PropertyDescriptor pd2 =
31
+ PropertyDescriptor::Accessor<TestGetter, TestSetter>("pd2");
38
32
  // Function
39
33
  PropertyDescriptor pd3 = PropertyDescriptor::Function(env,
40
34
  "function",
@@ -51,6 +45,26 @@ Void Init(Env env) {
51
45
  }
52
46
  ```
53
47
 
48
+ ## Types
49
+
50
+ ### PropertyDescriptor::GetterCallback
51
+
52
+ ```cpp
53
+ typedef Napi::Value (*GetterCallback)(const Napi::CallbackInfo& info);
54
+ ```
55
+
56
+ This is the signature of a getter function to be passed as a template parameter
57
+ to `PropertyDescriptor::Accessor`.
58
+
59
+ ### PropertyDescriptor::SetterCallback
60
+
61
+ ```cpp
62
+ typedef void (*SetterCallback)(const Napi::CallbackInfo& info);
63
+ ```
64
+
65
+ This is the signature of a setter function to be passed as a template parameter
66
+ to `PropertyDescriptor::Accessor`.
67
+
54
68
  ## Methods
55
69
 
56
70
  ### Constructor
@@ -63,6 +77,47 @@ Napi::PropertyDescriptor::PropertyDescriptor (napi_property_descriptor desc);
63
77
 
64
78
  ### Accessor
65
79
 
80
+ ```cpp
81
+ template <Napi::PropertyDescriptor::GetterCallback Getter>
82
+ static Napi::PropertyDescriptor Napi::PropertyDescriptor::Accessor (___ name,
83
+ napi_property_attributes attributes = napi_default,
84
+ void* data = nullptr);
85
+ ```
86
+
87
+ * `[template] Getter`: A getter function.
88
+ * `[in] attributes`: Potential attributes for the getter function.
89
+ * `[in] data`: A pointer to data of any type, default is a null pointer.
90
+
91
+ Returns a PropertyDescriptor that contains a read-only property.
92
+
93
+ The name of the property can be any of the following types:
94
+ - `const char*`
95
+ - `const std::string &`
96
+ - `napi_value value`
97
+ - `Napi::Name`
98
+
99
+ ```cpp
100
+ template <
101
+ Napi::PropertyDescriptor::GetterCallback Getter,
102
+ Napi::PropertyDescriptor::SetterCallback Setter>
103
+ static Napi::PropertyDescriptor Napi::PropertyDescriptor::Accessor (___ name,
104
+ napi_property_attributes attributes = napi_default,
105
+ void* data = nullptr);
106
+ ```
107
+
108
+ * `[template] Getter`: A getter function.
109
+ * `[template] Setter`: A setter function.
110
+ * `[in] attributes`: Potential attributes for the getter function.
111
+ * `[in] data`: A pointer to data of any type, default is a null pointer.
112
+
113
+ Returns a PropertyDescriptor that contains a read-write property.
114
+
115
+ The name of the property can be any of the following types:
116
+ - `const char*`
117
+ - `const std::string &`
118
+ - `napi_value value`
119
+ - `Napi::Name`
120
+
66
121
  ```cpp
67
122
  static Napi::PropertyDescriptor Napi::PropertyDescriptor::Accessor (___ name,
68
123
  Getter getter,
package/doc/setup.md CHANGED
@@ -27,7 +27,6 @@ To use **N-API** in a native module:
27
27
 
28
28
  ```gyp
29
29
  'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
30
- 'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
31
30
  ```
32
31
 
33
32
  3. Decide whether the package will enable C++ exceptions in the N-API wrapper.
package/doc/string.md CHANGED
@@ -62,7 +62,7 @@ Napi::String::New(napi_env env, const char16_t* value, size_t length);
62
62
 
63
63
  - `[in] env`: The `napi_env` environment in which to construct the `Napi::Value` object.
64
64
  - `[in] value`: The C++ primitive from which to instantiate the `Napi::Value`. `value` may be any of:
65
- - `std::string&` - represents an ANSI string.
65
+ - `std::string&` - represents a UTF8 string.
66
66
  - `std::u16string&` - represents a UTF16-LE string.
67
67
  - `const char*` - represents a UTF8 string.
68
68
  - `const char16_t*` - represents a UTF16-LE string.
package/doc/symbol.md CHANGED
@@ -23,7 +23,7 @@ Napi::Symbol::New(napi_env env, napi_value description);
23
23
  - `[in] env`: The `napi_env` environment in which to construct the `Napi::Symbol` object.
24
24
  - `[in] value`: The C++ primitive which represents the description hint for the `Napi::Symbol`.
25
25
  `description` may be any of:
26
- - `std::string&` - ANSI string description.
26
+ - `std::string&` - UTF8 string description.
27
27
  - `const char*` - represents a UTF8 string description.
28
28
  - `String` - Node addon API String description.
29
29
  - `napi_value` - N-API `napi_value` description.
@@ -58,7 +58,10 @@ Napi::ThreadSafeFunction::ThreadSafeFunction(napi_threadsafe_function tsfn);
58
58
  - `tsfn`: The `napi_threadsafe_function` which is a handle for an existing
59
59
  thread-safe function.
60
60
 
61
- Returns a non-empty `Napi::ThreadSafeFunction` instance.
61
+ Returns a non-empty `Napi::ThreadSafeFunction` instance. When using this
62
+ constructor, only use the `Blocking(void*)` / `NonBlocking(void*)` overloads;
63
+ the `Callback` and templated `data*` overloads should _not_ be used. See below
64
+ for additional details.
62
65
 
63
66
  ### New
64
67
 
@@ -171,6 +174,9 @@ There are several overloaded implementations of `BlockingCall()` and
171
174
  `NonBlockingCall()` for use with optional parameters: skip the optional
172
175
  parameter for that specific overload.
173
176
 
177
+ **These specific function overloads should only be used on a `ThreadSafeFunction`
178
+ created via `ThreadSafeFunction::New`.**
179
+
174
180
  ```cpp
175
181
  napi_status Napi::ThreadSafeFunction::BlockingCall(DataType* data, Callback callback) const
176
182
 
@@ -186,6 +192,17 @@ napi_status Napi::ThreadSafeFunction::NonBlockingCall(DataType* data, Callback c
186
192
  necessary to call into JavaScript via `MakeCallback()` because N-API runs
187
193
  `callback` in a context appropriate for callbacks.
188
194
 
195
+ **These specific function overloads should only be used on a `ThreadSafeFunction`
196
+ created via `ThreadSafeFunction(napi_threadsafe_function)`.**
197
+
198
+ ```cpp
199
+ napi_status Napi::ThreadSafeFunction::BlockingCall(void* data) const
200
+
201
+ napi_status Napi::ThreadSafeFunction::NonBlockingCall(void* data) const
202
+ ```
203
+ - `data`: Data to pass to `call_js_cb` specified when creating the thread-safe
204
+ function via `napi_create_threadsafe_function`.
205
+
189
206
  Returns one of:
190
207
  - `napi_ok`: The call was successfully added to the queue.
191
208
  - `napi_queue_full`: The queue was full when trying to call in a non-blocking
package/doc/value.md CHANGED
@@ -6,10 +6,11 @@ Value is a the base class upon which other JavaScript values such as Number, Boo
6
6
 
7
7
  The following classes inherit, either directly or indirectly, from `Napi::Value`:
8
8
 
9
- - [`Napi::Array`](array.md)
9
+ - [`Napi::Array`](basic_types.md#array)
10
10
  - [`Napi::ArrayBuffer`](array_buffer.md)
11
11
  - [`Napi::Boolean`](boolean.md)
12
12
  - [`Napi::Buffer`](buffer.md)
13
+ - [`Napi::Date`](date.md)
13
14
  - [`Napi::External`](external.md)
14
15
  - [`Napi::Function`](function.md)
15
16
  - [`Napi::Name`](name.md)
@@ -226,6 +227,14 @@ bool Napi::Value::IsBuffer() const;
226
227
 
227
228
  Returns a `bool` indicating if this `Napi::Value` is a Node buffer.
228
229
 
230
+ ### IsDate
231
+
232
+ ```cpp
233
+ bool Napi::Value::IsDate() const;
234
+ ```
235
+
236
+ Returns a `bool` indicating if this `Napi::Value` is a JavaScript date.
237
+
229
238
  ### As
230
239
 
231
240
  ```cpp
package/except.gypi ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ 'defines': [ 'NAPI_CPP_EXCEPTIONS' ],
3
+ 'cflags!': [ '-fno-exceptions' ],
4
+ 'cflags_cc!': [ '-fno-exceptions' ],
5
+ 'msvs_settings': {
6
+ 'VCCLCompilerTool': {
7
+ 'ExceptionHandling': 1,
8
+ 'EnablePREfast': 'true',
9
+ },
10
+ },
11
+ 'xcode_settings': {
12
+ 'CLANG_CXX_LIBRARY': 'libc++',
13
+ 'MACOSX_DEPLOYMENT_TARGET': '10.7',
14
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
15
+ },
16
+ }
package/index.js CHANGED
@@ -1,45 +1,8 @@
1
- var path = require('path');
2
-
3
- var versionArray = process.version
4
- .substr(1)
5
- .replace(/-.*$/, '')
6
- .split('.')
7
- .map(function(item) {
8
- return +item;
9
- });
10
-
11
- // TODO: Check if the main node semantic version is within multiple ranges,
12
- // or detect presence of built-in N-API by some other mechanism TBD.
13
-
14
- // We know which version of Node.js first shipped the incarnation of the API
15
- // available in *this* package. So, if we find that the Node.js version is below
16
- // that, we indicate that the API is missing from Node.js.
17
- var isNodeApiBuiltin = (
18
- versionArray[0] > 8 ||
19
- (versionArray[0] == 8 && versionArray[1] >= 6) ||
20
- (versionArray[0] == 6 && versionArray[1] >= 15) ||
21
- (versionArray[0] == 6 && versionArray[1] >= 14 && versionArray[2] >= 2));
22
-
23
- // The flag is not needed when the Node version is not 8, nor if the API is
24
- // built-in, because we removed the flag at the same time as creating the final
25
- // incarnation of the built-in API.
26
- var needsFlag = (!isNodeApiBuiltin && versionArray[0] == 8);
27
-
28
- var include = [__dirname];
29
- var gyp = path.join(__dirname, 'src', 'node_api.gyp');
30
-
31
- if (isNodeApiBuiltin) {
32
- gyp += ':nothing';
33
- } else {
34
- gyp += ':node-api';
35
- include.unshift(path.join(__dirname, 'external-napi'));
36
- }
1
+ const path = require('path');
37
2
 
38
3
  module.exports = {
39
- include: include.map(function(item) {
40
- return '"' + item + '"';
41
- }).join(' '),
42
- gyp: gyp,
43
- isNodeApiBuiltin: isNodeApiBuiltin,
44
- needsFlag: needsFlag
4
+ include: `"${__dirname}"`,
5
+ gyp: path.join(__dirname, 'node_api.gyp:nothing'),
6
+ isNodeApiBuiltin: true,
7
+ needsFlag: false
45
8
  };