node-addon-api 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.clang-format +111 -0
- package/.github/workflows/ci.yml +55 -0
- package/.github/workflows/linter.yml +24 -0
- package/.github/workflows/stale.yml +18 -0
- package/.travis.yml +0 -1
- package/CHANGELOG.md +76 -0
- package/README.md +23 -4
- package/doc/addon.md +5 -5
- package/doc/array_buffer.md +16 -0
- package/doc/async_context.md +1 -1
- package/doc/async_worker.md +1 -1
- package/doc/async_worker_variants.md +141 -40
- package/doc/boolean.md +1 -1
- package/doc/checker-tool.md +1 -1
- package/doc/creating_a_release.md +1 -1
- package/doc/error.md +1 -1
- package/doc/escapable_handle_scope.md +1 -1
- package/doc/function.md +2 -2
- package/doc/function_reference.md +1 -1
- package/doc/handle_scope.md +1 -1
- package/doc/hierarchy.md +1 -1
- package/doc/number.md +1 -1
- package/doc/object_lifetime_management.md +1 -1
- package/doc/object_reference.md +1 -1
- package/doc/object_wrap.md +1 -1
- package/doc/prebuild_tools.md +2 -2
- package/doc/property_descriptor.md +3 -3
- package/doc/threadsafe.md +121 -0
- package/doc/threadsafe_function.md +16 -46
- package/doc/typed_threadsafe_function.md +307 -0
- package/doc/version_management.md +2 -2
- package/napi-inl.h +550 -0
- package/napi.h +195 -0
- package/package-support.json +21 -0
- package/package.json +45 -3
- package/tools/README.md +8 -2
- package/tools/clang-format.js +47 -0
- package/doc/Doxyfile +0 -2450
package/.clang-format
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
Language: Cpp
|
|
3
|
+
# BasedOnStyle: Google
|
|
4
|
+
AccessModifierOffset: -1
|
|
5
|
+
AlignAfterOpenBracket: Align
|
|
6
|
+
AlignConsecutiveAssignments: false
|
|
7
|
+
AlignConsecutiveDeclarations: false
|
|
8
|
+
AlignEscapedNewlines: Right
|
|
9
|
+
AlignOperands: true
|
|
10
|
+
AlignTrailingComments: true
|
|
11
|
+
AllowAllParametersOfDeclarationOnNextLine: true
|
|
12
|
+
AllowShortBlocksOnASingleLine: false
|
|
13
|
+
AllowShortCaseLabelsOnASingleLine: false
|
|
14
|
+
AllowShortFunctionsOnASingleLine: Inline
|
|
15
|
+
AllowShortIfStatementsOnASingleLine: true
|
|
16
|
+
AllowShortLoopsOnASingleLine: true
|
|
17
|
+
AlwaysBreakAfterDefinitionReturnType: None
|
|
18
|
+
AlwaysBreakAfterReturnType: None
|
|
19
|
+
AlwaysBreakBeforeMultilineStrings: false
|
|
20
|
+
AlwaysBreakTemplateDeclarations: true
|
|
21
|
+
BinPackArguments: false
|
|
22
|
+
BinPackParameters: false
|
|
23
|
+
BraceWrapping:
|
|
24
|
+
AfterClass: false
|
|
25
|
+
AfterControlStatement: false
|
|
26
|
+
AfterEnum: false
|
|
27
|
+
AfterFunction: false
|
|
28
|
+
AfterNamespace: false
|
|
29
|
+
AfterObjCDeclaration: false
|
|
30
|
+
AfterStruct: false
|
|
31
|
+
AfterUnion: false
|
|
32
|
+
AfterExternBlock: false
|
|
33
|
+
BeforeCatch: false
|
|
34
|
+
BeforeElse: false
|
|
35
|
+
IndentBraces: false
|
|
36
|
+
SplitEmptyFunction: true
|
|
37
|
+
SplitEmptyRecord: true
|
|
38
|
+
SplitEmptyNamespace: true
|
|
39
|
+
BreakBeforeBinaryOperators: None
|
|
40
|
+
BreakBeforeBraces: Attach
|
|
41
|
+
BreakBeforeInheritanceComma: false
|
|
42
|
+
BreakBeforeTernaryOperators: true
|
|
43
|
+
BreakConstructorInitializersBeforeComma: false
|
|
44
|
+
BreakConstructorInitializers: BeforeColon
|
|
45
|
+
BreakAfterJavaFieldAnnotations: false
|
|
46
|
+
BreakStringLiterals: true
|
|
47
|
+
ColumnLimit: 80
|
|
48
|
+
CommentPragmas: '^ IWYU pragma:'
|
|
49
|
+
CompactNamespaces: false
|
|
50
|
+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
|
51
|
+
ConstructorInitializerIndentWidth: 4
|
|
52
|
+
ContinuationIndentWidth: 4
|
|
53
|
+
Cpp11BracedListStyle: true
|
|
54
|
+
DerivePointerAlignment: false
|
|
55
|
+
DisableFormat: false
|
|
56
|
+
ExperimentalAutoDetectBinPacking: false
|
|
57
|
+
FixNamespaceComments: true
|
|
58
|
+
ForEachMacros:
|
|
59
|
+
- foreach
|
|
60
|
+
- Q_FOREACH
|
|
61
|
+
- BOOST_FOREACH
|
|
62
|
+
IncludeBlocks: Preserve
|
|
63
|
+
IncludeCategories:
|
|
64
|
+
- Regex: '^<ext/.*\.h>'
|
|
65
|
+
Priority: 2
|
|
66
|
+
- Regex: '^<.*\.h>'
|
|
67
|
+
Priority: 1
|
|
68
|
+
- Regex: '^<.*'
|
|
69
|
+
Priority: 2
|
|
70
|
+
- Regex: '.*'
|
|
71
|
+
Priority: 3
|
|
72
|
+
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
|
73
|
+
IndentCaseLabels: true
|
|
74
|
+
IndentPPDirectives: None
|
|
75
|
+
IndentWidth: 2
|
|
76
|
+
IndentWrappedFunctionNames: false
|
|
77
|
+
JavaScriptQuotes: Leave
|
|
78
|
+
JavaScriptWrapImports: true
|
|
79
|
+
KeepEmptyLinesAtTheStartOfBlocks: false
|
|
80
|
+
MacroBlockBegin: ''
|
|
81
|
+
MacroBlockEnd: ''
|
|
82
|
+
MaxEmptyLinesToKeep: 1
|
|
83
|
+
NamespaceIndentation: None
|
|
84
|
+
ObjCBlockIndentWidth: 2
|
|
85
|
+
ObjCSpaceAfterProperty: false
|
|
86
|
+
ObjCSpaceBeforeProtocolList: false
|
|
87
|
+
PenaltyBreakAssignment: 2
|
|
88
|
+
PenaltyBreakBeforeFirstCallParameter: 1
|
|
89
|
+
PenaltyBreakComment: 300
|
|
90
|
+
PenaltyBreakFirstLessLess: 120
|
|
91
|
+
PenaltyBreakString: 1000
|
|
92
|
+
PenaltyExcessCharacter: 1000000
|
|
93
|
+
PenaltyReturnTypeOnItsOwnLine: 200
|
|
94
|
+
PointerAlignment: Left
|
|
95
|
+
ReflowComments: true
|
|
96
|
+
SortIncludes: true
|
|
97
|
+
SortUsingDeclarations: true
|
|
98
|
+
SpaceAfterCStyleCast: false
|
|
99
|
+
SpaceAfterTemplateKeyword: true
|
|
100
|
+
SpaceBeforeAssignmentOperators: true
|
|
101
|
+
SpaceBeforeParens: ControlStatements
|
|
102
|
+
SpaceInEmptyParentheses: false
|
|
103
|
+
SpacesBeforeTrailingComments: 2
|
|
104
|
+
SpacesInAngles: false
|
|
105
|
+
SpacesInContainerLiterals: true
|
|
106
|
+
SpacesInCStyleCastParentheses: false
|
|
107
|
+
SpacesInParentheses: false
|
|
108
|
+
SpacesInSquareBrackets: false
|
|
109
|
+
Standard: Auto
|
|
110
|
+
TabWidth: 8
|
|
111
|
+
UseTab: Never
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: Node.js CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
timeout-minutes: 30
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
node-version:
|
|
11
|
+
- node/10
|
|
12
|
+
- node/12
|
|
13
|
+
- node/14
|
|
14
|
+
- node/15
|
|
15
|
+
compiler:
|
|
16
|
+
- gcc
|
|
17
|
+
- clang
|
|
18
|
+
os:
|
|
19
|
+
- ubuntu-16.04 # ubuntu-18.04/ubuntu-latest missing package g++-4.9
|
|
20
|
+
- macos-latest
|
|
21
|
+
runs-on: ${{ matrix.os }}
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v2
|
|
24
|
+
- name: Install system dependencies
|
|
25
|
+
run: |
|
|
26
|
+
if [ "${{ matrix.compiler }}" = "gcc" -a "${{ matrix.os }}" = ubuntu-* ]; then
|
|
27
|
+
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
|
|
28
|
+
sudo apt-get update
|
|
29
|
+
sudo apt-get install g++-4.9
|
|
30
|
+
fi
|
|
31
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
32
|
+
run: |
|
|
33
|
+
git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs ~/.nvs
|
|
34
|
+
. ~/.nvs/nvs.sh
|
|
35
|
+
nvs --version
|
|
36
|
+
nvs add ${{ matrix.node-version }}
|
|
37
|
+
nvs use ${{ matrix.node-version }}
|
|
38
|
+
node --version
|
|
39
|
+
npm --version
|
|
40
|
+
npm install
|
|
41
|
+
- name: npm test
|
|
42
|
+
run: |
|
|
43
|
+
if [ "${{ matrix.compiler }}" = "gcc" ]; then
|
|
44
|
+
export CC="gcc" CXX="g++"
|
|
45
|
+
fi
|
|
46
|
+
if [ "${{ matrix.compiler }}" = "gcc" -a "${{ matrix.os }}" = ubuntu-* ]; then
|
|
47
|
+
export CC="gcc-4.9" CXX="g++-4.9" AR="gcc-ar-4.9" RANLIB="gcc-ranlib-4.9" NM="gcc-nm-4.9"
|
|
48
|
+
fi
|
|
49
|
+
if [ "${{ matrix.compiler }}" = "clang" ]; then
|
|
50
|
+
export CC="clang" CXX="clang++"
|
|
51
|
+
fi
|
|
52
|
+
export CFLAGS="$CFLAGS -O3 --coverage" LDFLAGS="$LDFLAGS --coverage"
|
|
53
|
+
echo "CFLAGS=\"$CFLAGS\" LDFLAGS=\"$LDFLAGS\""
|
|
54
|
+
npm run pretest -- --verbose
|
|
55
|
+
node test
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Style Checks
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
lint:
|
|
7
|
+
if: github.repository == 'nodejs/node-addon-api'
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
node-version: [14.x]
|
|
11
|
+
os: [ubuntu-latest]
|
|
12
|
+
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v2
|
|
16
|
+
with:
|
|
17
|
+
fetch-depth: 0
|
|
18
|
+
- run: git branch -a
|
|
19
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
20
|
+
uses: actions/setup-node@v1
|
|
21
|
+
with:
|
|
22
|
+
node-version: ${{ matrix.node-version }}
|
|
23
|
+
- run: npm install
|
|
24
|
+
- run: CLANG_FORMAT_START=refs/remotes/origin/master npm run lint
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: "Close stale issues"
|
|
2
|
+
on:
|
|
3
|
+
schedule:
|
|
4
|
+
- cron: "0 0 * * *"
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
stale:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/stale@v1
|
|
11
|
+
with:
|
|
12
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
13
|
+
stale-issue-message: 'This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.'
|
|
14
|
+
stale-issue-label: 'stale'
|
|
15
|
+
exempt-issue-label: 'never stale'
|
|
16
|
+
days-before-stale: 90
|
|
17
|
+
days-before-close: 30
|
|
18
|
+
|
package/.travis.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
# node-addon-api Changelog
|
|
2
2
|
|
|
3
|
+
## 2020-12-17 Version 3.1.0, @NickNaso
|
|
4
|
+
|
|
5
|
+
### Notable changes:
|
|
6
|
+
|
|
7
|
+
#### API
|
|
8
|
+
|
|
9
|
+
- Added `Napi::TypedThreadSafeFunction` class that is a new implementation for
|
|
10
|
+
thread-safe functions.
|
|
11
|
+
- Fixed leak on `Napi::AsyncProgressWorkerBase`.
|
|
12
|
+
- Fixed empty data on `Napi::AsyncProgressWorker::OnProgress` caused by race
|
|
13
|
+
conditions of `Napi::AsyncProgressWorker`.
|
|
14
|
+
- Added `Napi::ArrayBuffer::Detach()` and `Napi::ArrayBuffer::IsDetached()`.
|
|
15
|
+
- Fixed problem on `Napi::FinalizeCallback` it needs to create a
|
|
16
|
+
`Napi::HandleScope` when it calls `Napi::ObjectWrap::~ObjectWrap()`.
|
|
17
|
+
|
|
18
|
+
#### Documentation
|
|
19
|
+
|
|
20
|
+
- Added documentation for `Napi::TypedThreadSafeFunction`.
|
|
21
|
+
- Removed unsued Doxygen file.
|
|
22
|
+
- Clarified when to use N-API.
|
|
23
|
+
- Added support information.
|
|
24
|
+
- Some minor corrections all over the documentation.
|
|
25
|
+
|
|
26
|
+
#### TEST
|
|
27
|
+
|
|
28
|
+
- Added test for `Napi::TypedThreadSafeFunction`.
|
|
29
|
+
- Fixed testing for specific N-API version.
|
|
30
|
+
- Some minor corrections all over the test suite.
|
|
31
|
+
|
|
32
|
+
### TOOL
|
|
33
|
+
|
|
34
|
+
- Setup github actions for tests.
|
|
35
|
+
- Added stale action.
|
|
36
|
+
- Removed `sudo` tag from Travis CI.
|
|
37
|
+
- Added clang-format.
|
|
38
|
+
- Added pre-commit package for linting.
|
|
39
|
+
|
|
40
|
+
### Commits
|
|
41
|
+
|
|
42
|
+
* [[`ff642c5b85`](https://github.com/nodejs/node-addon-api/commit/ff642c5b85)] - **doc**: fix tsfn docs to reflect true implementation (#860) (Kevin Eady)
|
|
43
|
+
* [[`86feeebf54`](https://github.com/nodejs/node-addon-api/commit/86feeebf54)] - **src**: empty data OnProgress in AsyncProgressWorker (legendecas) [#853](https://github.com/nodejs/node-addon-api/pull/853)
|
|
44
|
+
* [[`a7fb5fb31c`](https://github.com/nodejs/node-addon-api/commit/a7fb5fb31c)] - **action**: add stale action (#856) (Michael Dawson)
|
|
45
|
+
* [[`fd44609885`](https://github.com/nodejs/node-addon-api/commit/fd44609885)] - **chore**: setup github actions for tests (#854) (legendecas) [#854](https://github.com/nodejs/node-addon-api/pull/854)
|
|
46
|
+
* [[`c52ace4813`](https://github.com/nodejs/node-addon-api/commit/c52ace4813)] - **script**: fix complains that js files are not supported on npm run lint:fix (#852) (legendecas)
|
|
47
|
+
* [[`b4a3364ad5`](https://github.com/nodejs/node-addon-api/commit/b4a3364ad5)] - **doc**: remove unused Doxygen file (#851) (Michael Dawson)
|
|
48
|
+
* [[`b810466ae2`](https://github.com/nodejs/node-addon-api/commit/b810466ae2)] - **doc**: clarify when to use N-API (#849) (Michael Dawson)
|
|
49
|
+
* [[`528b9f6832`](https://github.com/nodejs/node-addon-api/commit/528b9f6832)] - **test**: remove sudo from travis (#850) (Michael Dawson)
|
|
50
|
+
* [[`4bb680de4e`](https://github.com/nodejs/node-addon-api/commit/4bb680de4e)] - Remove misleading sentence (#847) (Nikolai Vavilov) [#847](https://github.com/nodejs/node-addon-api/pull/847)
|
|
51
|
+
* [[`48e6b584a3`](https://github.com/nodejs/node-addon-api/commit/48e6b584a3)] - Merge pull request #742 from KevinEady/contexted-tsfn-api-gcc-4 (Gabriel Schulhof)
|
|
52
|
+
* [[`d5e37210cc`](https://github.com/nodejs/node-addon-api/commit/d5e37210cc)] - **tools**: print more instructions on clang-format check failed (#846) (legendecas) [#846](https://github.com/nodejs/node-addon-api/pull/846)
|
|
53
|
+
* [[`d9e11ff2c9`](https://github.com/nodejs/node-addon-api/commit/d9e11ff2c9)] - **doc**: add support info (#843) (Michael Dawson) [#843](https://github.com/nodejs/node-addon-api/pull/843)
|
|
54
|
+
* [[`356e93d69a`](https://github.com/nodejs/node-addon-api/commit/356e93d69a)] - **test**: fixup testing for specific N-API version (#840) (Michael Dawson) [#840](https://github.com/nodejs/node-addon-api/pull/840)
|
|
55
|
+
* [[`5e5b9ce1b7`](https://github.com/nodejs/node-addon-api/commit/5e5b9ce1b7)] - Apply formatting changes (Kevin Eady)
|
|
56
|
+
* [[`559ad8c0c0`](https://github.com/nodejs/node-addon-api/commit/559ad8c0c0)] - Merge remote-tracking branch 'upstream/master' into contexted-tsfn-api-gcc-4 (Kevin Eady)
|
|
57
|
+
* [[`c24c455ced`](https://github.com/nodejs/node-addon-api/commit/c24c455ced)] - Rename to TypedThreadSafeFunction (Kevin Eady)
|
|
58
|
+
* [[`63b43f4125`](https://github.com/nodejs/node-addon-api/commit/63b43f4125)] - **test**: fix buildType bug objectwrap\_worker\_thread (raisinten) [#837](https://github.com/nodejs/node-addon-api/pull/837)
|
|
59
|
+
* [[`6321f2ba1a`](https://github.com/nodejs/node-addon-api/commit/6321f2ba1a)] - **test**: fix typos in addon\_build/index.js (raisinten) [#838](https://github.com/nodejs/node-addon-api/pull/838)
|
|
60
|
+
* [[`59c6a6aeb0`](https://github.com/nodejs/node-addon-api/commit/59c6a6aeb0)] - **fix**: git-clang-format doesn't recognize no changes requested on given files (#835) (legendecas)
|
|
61
|
+
* [[`1427b3ef78`](https://github.com/nodejs/node-addon-api/commit/1427b3ef78)] - **src**: create a HandleScope in FinalizeCallback (blagoev) [#832](https://github.com/nodejs/node-addon-api/pull/832)
|
|
62
|
+
* [[`8fb5820557`](https://github.com/nodejs/node-addon-api/commit/8fb5820557)] - **build**: add incremental clang-format checks (legendecas) [#819](https://github.com/nodejs/node-addon-api/pull/819)
|
|
63
|
+
* [[`2c02d317e5`](https://github.com/nodejs/node-addon-api/commit/2c02d317e5)] - **build**: add pre-commit package for linting (#823) (Kevin Eady)
|
|
64
|
+
* [[`1b52c28eb8`](https://github.com/nodejs/node-addon-api/commit/1b52c28eb8)] - Clean up AsyncProgressWorker documentation (#831) (mastergberry)
|
|
65
|
+
* [[`4abe7cfe30`](https://github.com/nodejs/node-addon-api/commit/4abe7cfe30)] - **test**: rename tsfnex test files (Kevin Eady)
|
|
66
|
+
* [[`c9563caa25`](https://github.com/nodejs/node-addon-api/commit/c9563caa25)] - **src**: add ArrayBuffer::Detach() and ::IsDetached() (Tobias Nießen) [#659](https://github.com/nodejs/node-addon-api/pull/659)
|
|
67
|
+
* [[`c79cabaed2`](https://github.com/nodejs/node-addon-api/commit/c79cabaed2)] - **doc**: avoid directing users to HTTP (#828) (Tobias Nießen)
|
|
68
|
+
* [[`7a13f861ab`](https://github.com/nodejs/node-addon-api/commit/7a13f861ab)] - **doc**: fix additional typo (Kevin Eady)
|
|
69
|
+
* [[`7ec9741dd2`](https://github.com/nodejs/node-addon-api/commit/7ec9741dd2)] - Merge remote-tracking branch 'upstream/master' into contexted-tsfn-api-gcc-4 (Kevin Eady)
|
|
70
|
+
* [[`f5fad239fa`](https://github.com/nodejs/node-addon-api/commit/f5fad239fa)] - Update object\_reference.md (#827) (kidneysolo)
|
|
71
|
+
* [[`35b65712c2`](https://github.com/nodejs/node-addon-api/commit/35b65712c2)] - **Fix**: some typos in documentation (#826) (Helio Frota)
|
|
72
|
+
* [[`8983383000`](https://github.com/nodejs/node-addon-api/commit/8983383000)] - **Fix**: some typos in the document (#825) (Ziqiu Zhao)
|
|
73
|
+
* [[`826e466ef6`](https://github.com/nodejs/node-addon-api/commit/826e466ef6)] - Fixed example in addon.md. (#820) (nempoBu4) [#820](https://github.com/nodejs/node-addon-api/pull/820)
|
|
74
|
+
* [[`b54f5eb788`](https://github.com/nodejs/node-addon-api/commit/b54f5eb788)] - Additional changes from review (Kevin Eady)
|
|
75
|
+
* [[`59f27dac9a`](https://github.com/nodejs/node-addon-api/commit/59f27dac9a)] - Fix common.gypi (Kevin Eady)
|
|
76
|
+
* [[`151a914c99`](https://github.com/nodejs/node-addon-api/commit/151a914c99)] - Apply documentation suggestions from code review (Kevin Eady)
|
|
77
|
+
* [[`ceb27d4949`](https://github.com/nodejs/node-addon-api/commit/ceb27d4949)] - **src**: fix leak in AsyncProgressWorkerBase\<DataType\> (Ferdinand Holzer) [#795](https://github.com/nodejs/node-addon-api/pull/795)
|
|
78
|
+
|
|
3
79
|
## 2020-09-18 Version 3.0.2, @NickNaso
|
|
4
80
|
|
|
5
81
|
### Notable changes:
|
package/README.md
CHANGED
|
@@ -4,6 +4,14 @@ the use of the C based [N-API](https://nodejs.org/dist/latest/docs/api/n-api.htm
|
|
|
4
4
|
provided by Node.js when using C++. It provides a C++ object model
|
|
5
5
|
and exception handling semantics with low overhead.
|
|
6
6
|
|
|
7
|
+
There are three options for implementing addons: N-API, nan, or direct
|
|
8
|
+
use of internal V8, libuv and Node.js libraries. Unless there is a need for
|
|
9
|
+
direct access to functionality which is not exposed by N-API as outlined
|
|
10
|
+
in [C/C++ addons](https://nodejs.org/dist/latest/docs/api/addons.html)
|
|
11
|
+
in Node.js core, use N-API. Refer to
|
|
12
|
+
[C/C++ addons with N-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
|
|
13
|
+
for more information on N-API.
|
|
14
|
+
|
|
7
15
|
N-API is an ABI stable C interface provided by Node.js for building native
|
|
8
16
|
addons. It is independent from the underlying JavaScript runtime (e.g. V8 or ChakraCore)
|
|
9
17
|
and is maintained as part of Node.js itself. It is intended to insulate
|
|
@@ -37,8 +45,8 @@ APIs exposed by node-addon-api are generally used to create and
|
|
|
37
45
|
manipulate JavaScript values. Concepts and operations generally map
|
|
38
46
|
to ideas specified in the **ECMA262 Language Specification**.
|
|
39
47
|
|
|
40
|
-
The [N-API Resource](
|
|
41
|
-
excellent orientation and tips for developers just getting started with N-API
|
|
48
|
+
The [N-API Resource](https://nodejs.github.io/node-addon-examples/) offers an
|
|
49
|
+
excellent orientation and tips for developers just getting started with N-API
|
|
42
50
|
and node-addon-api.
|
|
43
51
|
|
|
44
52
|
- **[Setup](#setup)**
|
|
@@ -51,7 +59,7 @@ and node-addon-api.
|
|
|
51
59
|
- **[Contributors](#contributors)**
|
|
52
60
|
- **[License](#license)**
|
|
53
61
|
|
|
54
|
-
## **Current version: 3.0
|
|
62
|
+
## **Current version: 3.1.0**
|
|
55
63
|
|
|
56
64
|
(See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
|
|
57
65
|
|
|
@@ -121,7 +129,9 @@ The following is the documentation for node-addon-api.
|
|
|
121
129
|
- [AsyncWorker](doc/async_worker.md)
|
|
122
130
|
- [AsyncContext](doc/async_context.md)
|
|
123
131
|
- [AsyncWorker Variants](doc/async_worker_variants.md)
|
|
124
|
-
- [Thread-safe Functions](doc/
|
|
132
|
+
- [Thread-safe Functions](doc/threadsafe.md)
|
|
133
|
+
- [ThreadSafeFunction](doc/threadsafe_function.md)
|
|
134
|
+
- [TypedThreadSafeFunction](doc/typed_threadsafe_function.md)
|
|
125
135
|
- [Promises](doc/promises.md)
|
|
126
136
|
- [Version management](doc/version_management.md)
|
|
127
137
|
|
|
@@ -157,6 +167,15 @@ npm install
|
|
|
157
167
|
npm test --disable-deprecated
|
|
158
168
|
```
|
|
159
169
|
|
|
170
|
+
To run the tests targetting a specific version of N-API run
|
|
171
|
+
```
|
|
172
|
+
npm install
|
|
173
|
+
export NAPI_VERSION=X
|
|
174
|
+
npm test --NAPI_VERSION=X
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
where X is the version of N-API you want to target.
|
|
178
|
+
|
|
160
179
|
### **Debug**
|
|
161
180
|
|
|
162
181
|
To run the **node-addon-api** tests with `--debug` option:
|
package/doc/addon.md
CHANGED
|
@@ -34,16 +34,16 @@ The `Napi::Addon<T>` class can be used together with the `NODE_API_ADDON()` and
|
|
|
34
34
|
class ExampleAddon : public Napi::Addon<ExampleAddon> {
|
|
35
35
|
public:
|
|
36
36
|
ExampleAddon(Napi::Env env, Napi::Object exports) {
|
|
37
|
-
// In the constructor we declare the functions the add-on makes
|
|
37
|
+
// In the constructor we declare the functions the add-on makes available
|
|
38
38
|
// to JavaScript.
|
|
39
39
|
DefineAddon(exports, {
|
|
40
40
|
InstanceMethod("increment", &ExampleAddon::Increment),
|
|
41
41
|
|
|
42
42
|
// We can also attach plain objects to `exports`, and instance methods as
|
|
43
43
|
// properties of those sub-objects.
|
|
44
|
-
InstanceValue("subObject", DefineProperties(Napi::Object::New(), {
|
|
45
|
-
InstanceMethod("decrement", &ExampleAddon::Decrement
|
|
46
|
-
})
|
|
44
|
+
InstanceValue("subObject", DefineProperties(Napi::Object::New(env), {
|
|
45
|
+
InstanceMethod("decrement", &ExampleAddon::Decrement)
|
|
46
|
+
}), napi_enumerable)
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
private:
|
|
@@ -80,7 +80,7 @@ The above code can be used from JavaScript as follows:
|
|
|
80
80
|
const exampleAddon = require('bindings')('example_addon');
|
|
81
81
|
console.log(exampleAddon.increment()); // prints 43
|
|
82
82
|
console.log(exampleAddon.increment()); // prints 44
|
|
83
|
-
|
|
83
|
+
console.log(exampleAddon.subObject.decrement()); // prints 43
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
When Node.js loads an instance of the add-on, a new instance of the class is
|
package/doc/array_buffer.md
CHANGED
|
@@ -130,4 +130,20 @@ void* Napi::ArrayBuffer::Data() const;
|
|
|
130
130
|
|
|
131
131
|
Returns a pointer the wrapped data.
|
|
132
132
|
|
|
133
|
+
### Detach
|
|
134
|
+
|
|
135
|
+
```cpp
|
|
136
|
+
void Napi::ArrayBuffer::Detach();
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Invokes the `ArrayBuffer` detach operation on a detachable `ArrayBuffer`.
|
|
140
|
+
|
|
141
|
+
### IsDetached
|
|
142
|
+
|
|
143
|
+
```cpp
|
|
144
|
+
bool Napi::ArrayBuffer::IsDetached() const;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Returns `true` if this `ArrayBuffer` has been detached.
|
|
148
|
+
|
|
133
149
|
[`Napi::Object`]: ./object.md
|
package/doc/async_context.md
CHANGED
|
@@ -73,7 +73,7 @@ void MakeCallbackWithAsyncContext(const Napi::CallbackInfo& info) {
|
|
|
73
73
|
Napi::Function callback = info[0].As<Napi::Function>();
|
|
74
74
|
Napi::Object resource = info[1].As<Napi::Object>();
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// Create a new async context instance.
|
|
77
77
|
Napi::AsyncContext context(info.Env(), "async_context_test", resource);
|
|
78
78
|
|
|
79
79
|
// Invoke the callback with the async context instance.
|
package/doc/async_worker.md
CHANGED
|
@@ -395,7 +395,7 @@ class EchoWorker : public AsyncWorker {
|
|
|
395
395
|
};
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
-
The `EchoWorker`'s
|
|
398
|
+
The `EchoWorker`'s constructor calls the base class' constructor to pass in the
|
|
399
399
|
callback that the `Napi::AsyncWorker` base class will store persistently. When
|
|
400
400
|
the work on the `Napi::AsyncWorker::Execute` method is done the
|
|
401
401
|
`Napi::AsyncWorker::OnOk` method is called and the results return back to
|