You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

n-api: add support for abi stable module API Add support for abi stable module API (N-API) as "Experimental feature". The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag "--napi-modules". Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in "src/node_api.h" and "src/node_api_types.h". This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra <arunesh.chandra@microsoft.com> Author: Gabriel Schulhof <gabriel.schulhof@intel.com> Author: Hitesh Kanwathirtha <hiteshk@microsoft.com> Author: Ian Halliday <ianhall@microsoft.com> Author: Jason Ginchereau <jasongin@microsoft.com> Author: Michael Dawson <michael_dawson@ca.ibm.com> Author: Sampson Gao <sampsong@ca.ibm.com> Author: Taylor Woll <taylor.woll@microsoft.com> PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
8 years ago
#include <node_api.h>
#include "../common.h"
#include <string.h>
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
napi_value RunCallback(napi_env env, napi_callback_info info) {
size_t argc = 2;
napi_value args[2];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
NAPI_ASSERT(env, argc == 1,
"Wrong number of arguments. Expects a single argument.");
napi_valuetype valuetype0;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
NAPI_ASSERT(env, valuetype0 == napi_function,
"Wrong type of arguments. Expects a function as first argument.");
napi_valuetype valuetype1;
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
NAPI_ASSERT(env, valuetype1 == napi_undefined,
"Additional arguments should be undefined.");
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
napi_value argv[1];
const char* str = "hello world";
size_t str_len = strlen(str);
NAPI_CALL(env, napi_create_string_utf8(env, str, str_len, argv));
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
napi_value global;
NAPI_CALL(env, napi_get_global(env, &global));
napi_value cb = args[0];
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
NAPI_CALL(env, napi_call_function(env, global, cb, 1, argv, NULL));
return NULL;
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
}
napi_value RunCallbackWithRecv(napi_env env, napi_callback_info info) {
size_t argc = 2;
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
napi_value args[2];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
napi_value cb = args[0];
napi_value recv = args[1];
NAPI_CALL(env, napi_call_function(env, recv, cb, 0, NULL, NULL));
return NULL;
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
}
napi_value Init(napi_env env, napi_value exports) {
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
napi_property_descriptor desc[2] = {
DECLARE_NAPI_PROPERTY("RunCallback", RunCallback),
DECLARE_NAPI_PROPERTY("RunCallbackWithRecv", RunCallbackWithRecv),
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
};
NAPI_CALL(env, napi_define_properties(env, exports, 2, desc));
return exports;
n-api: add support for abi stable module API Add support for abi stable module API (N-API) as &#34;Experimental feature&#34;. The goal of this API is to provide a stable Node API for native module developers. N-API aims to provide ABI compatibility guarantees across different Node versions and also across different Node VMs - allowing N-API enabled native modules to just work across different versions and flavors of Node.js without recompilation. A more detailed introduction is provided in: https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf. The feature, during its experimental state, will be guarded by a runtime flag &#34;--napi-modules&#34;. Only when this flag is added to the command line will N-API modules along with regular non N-API modules be supported. The API is defined by the methods in &#34;src/node_api.h&#34; and &#34;src/node_api_types.h&#34;. This is the best starting point to review the API surface. More documentation will follow. In addition to the implementation of the API using V8, which is included in this PR, the API has also been validated against chakracore and that port is available in https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x. The current plan is to provide N-API support in versions 8.X and 6.X directly. For older versions, such as 4.X or pre N-API versions of 6.X, we plan to create an external npm module to provide a migration path that will allow modules targeting older Node.js versions to use the API, albeit without getting the advantage of not having to recompile. In addition, we also plan an external npm package with C++ sugar to simplify the use of the API. The sugar will be in-line only and will only use the exported N-API methods but is not part of the N-API itself. The current version is in: https://github.com/nodejs/node-api. This PR is a result of work in the abi-stable-node repo: https://github.com/nodejs/abi-stable-node/tree/doc, with this PR being the cumulative work on the api-prototype-8.x branch with the following contributors in alphabetical order: Author: Arunesh Chandra &lt;arunesh.chandra@microsoft.com&gt; Author: Gabriel Schulhof &lt;gabriel.schulhof@intel.com&gt; Author: Hitesh Kanwathirtha &lt;hiteshk@microsoft.com&gt; Author: Ian Halliday &lt;ianhall@microsoft.com&gt; Author: Jason Ginchereau &lt;jasongin@microsoft.com&gt; Author: Michael Dawson &lt;michael_dawson@ca.ibm.com&gt; Author: Sampson Gao &lt;sampsong@ca.ibm.com&gt; Author: Taylor Woll &lt;taylor.woll@microsoft.com&gt; PR-URL: https://github.com/nodejs/node/pull/11975 Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt;
8 years ago
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)