-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: nodejs/node-addon-api#168 Reviewed-By: Michael Dawson <[email protected]>
- Loading branch information
1 parent
938fde4
commit 33b7bf2
Showing
39 changed files
with
200 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Node.js API (N-API) Package Changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Conversion Tool | ||
|
||
To make the migration to node-addon-api easier, we have provided a script to help | ||
complete the steps listed above. To use the conversion script: | ||
|
||
1. Go to your module directory | ||
|
||
``` | ||
cd [module_path] | ||
``` | ||
|
||
2. Install node-addon-api module | ||
|
||
``` | ||
npm install node-addon-api | ||
``` | ||
|
||
3. Run node-addon-api conversion script | ||
|
||
``` | ||
node ./node_modules/node-addon-api/tools/conversion.js ./ | ||
``` | ||
|
||
4. While this script makes conversion easier, it still cannot fully convert | ||
|
||
the module. The next step is to try to build the module and complete the | ||
remaining conversions necessary to allow it to compile and pass all of the | ||
module's tests. |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Object Wrap | ||
|
||
The ```ObjectWrap``` class can be used to expose C++ code to JavaScript. To do | ||
this you need to extend the ObjectWrap class that contain all the plumbing to connect | ||
JavaScript code to a C++ object. | ||
Classes extending ```ObjectWrap``` can be instantiated from JavaScript using the | ||
**new** operator, and their methods can be directly invoked from JavaScript. | ||
The **wrap** word refers to a way to group methods and state of your class because it | ||
will be your responsibility write custom code to bridge each of your C++ class methods. |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## Setup | ||
|
||
To use N-API in a native module: | ||
|
||
1. Add a dependency on this package to `package.json`: | ||
|
||
```json | ||
"dependencies": { | ||
"node-addon-api": "1.0.0", | ||
} | ||
``` | ||
|
||
2. Reference this package's include directory and gyp file in `binding.gyp`: | ||
|
||
```gyp | ||
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"], | ||
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"], | ||
``` | ||
|
||
3. Decide whether the package will enable C++ exceptions in the N-API wrapper. | ||
The base ABI-stable C APIs do not throw or handle C++ exceptions, but the | ||
N-API C++ wrapper classes may _optionally_ | ||
[integrate C++ and JavaScript exception-handling | ||
](https://nodejs.github.io/node-addon-api/class_napi_1_1_error.html). | ||
To enable that capability, C++ exceptions must be enabled in `binding.gyp`: | ||
|
||
```gyp | ||
'cflags!': [ '-fno-exceptions' ], | ||
'cflags_cc!': [ '-fno-exceptions' ], | ||
'xcode_settings': { | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', | ||
'CLANG_CXX_LIBRARY': 'libc++', | ||
'MACOSX_DEPLOYMENT_TARGET': '10.7', | ||
}, | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { 'ExceptionHandling': 1 }, | ||
}, | ||
``` | ||
|
||
Alternatively, disable use of C++ exceptions in N-API: | ||
|
||
```gyp | ||
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ], | ||
``` | ||
|
||
4. Include `napi.h` in the native module code. | ||
To ensure only ABI-stable APIs are used, DO NOT include | ||
`node.h`, `nan.h`, or `v8.h`. | ||
|
||
```C++ | ||
#include "napi.h" | ||
``` | ||
|
||
At build time, the N-API back-compat library code will be used only when the | ||
targeted node version *does not* have N-API built-in. |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.