Browse Source

n-api: refactor napi_addon_register_func

As per discussion in abi-stable-node:
https://github.com/nodejs/abi-stable-node/issues/256,
take a refactor to napi_addon_register_func such that
the result from the register function is assigned to
the module exports property. By making this change,
native module can be agnostic about which type of
module the environment supports.

PR-URL: https://github.com/nodejs/node/pull/15088
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
canary-base
Taylor Woll 8 years ago
committed by Michael Dawson
parent
commit
92e5f5cc09
  1. 39
      doc/api/n-api.md
  2. 16
      src/node_api.cc
  3. 6
      src/node_api.h
  4. 5
      test/addons-napi/1_hello_world/binding.c
  5. 5
      test/addons-napi/2_function_arguments/binding.c
  6. 5
      test/addons-napi/3_callbacks/binding.c
  7. 8
      test/addons-napi/4_object_factory/binding.c
  8. 8
      test/addons-napi/5_function_factory/binding.c
  9. 4
      test/addons-napi/6_object_wrap/binding.cc
  10. 10
      test/addons-napi/7_factory_wrap/binding.cc
  11. 6
      test/addons-napi/8_passing_wrapped/binding.cc
  12. 6
      test/addons-napi/test_array/test_array.c
  13. 6
      test/addons-napi/test_async/test_async.cc
  14. 11
      test/addons-napi/test_buffer/test_buffer.c
  15. 12
      test/addons-napi/test_constructor/test_constructor.c
  16. 6
      test/addons-napi/test_conversions/test_conversions.c
  17. 6
      test/addons-napi/test_dataview/test_dataview.c
  18. 6
      test/addons-napi/test_env_sharing/compare_env.c
  19. 8
      test/addons-napi/test_env_sharing/store_env.c
  20. 6
      test/addons-napi/test_error/test_error.cc
  21. 6
      test/addons-napi/test_exception/test_exception.c
  22. 6
      test/addons-napi/test_fatal/test_fatal.c
  23. 7
      test/addons-napi/test_function/test_function.c
  24. 6
      test/addons-napi/test_general/test_general.c
  25. 6
      test/addons-napi/test_handle_scope/test_handle_scope.c
  26. 9
      test/addons-napi/test_make_callback/binding.cc
  27. 10
      test/addons-napi/test_make_callback_recurse/binding.cc
  28. 6
      test/addons-napi/test_number/test_number.c
  29. 6
      test/addons-napi/test_object/test_object.c
  30. 6
      test/addons-napi/test_promise/test_promise.c
  31. 14
      test/addons-napi/test_properties/test_properties.c
  32. 6
      test/addons-napi/test_reference/test_reference.c
  33. 6
      test/addons-napi/test_string/test_string.c
  34. 6
      test/addons-napi/test_symbol/test_symbol.c
  35. 9
      test/addons-napi/test_typedarray/test_typedarray.c

39
doc/api/n-api.md

@ -873,7 +873,7 @@ JavaScript Object associated with the `napi_ref`. Otherise, result
will be NULL.
## Module registration
N-API modules are registered in the same manner as other modules
N-API modules are registered in a manner similar to other modules
except that instead of using the `NODE_MODULE` macro the following
is used:
@ -885,32 +885,39 @@ The next difference is the signature for the `Init` method. For a N-API
module it is as follows:
```C
void Init(napi_env env, napi_value exports, napi_value module, void* priv);
napi_value Init(napi_env env, napi_value exports);
```
As with any other module, functions are exported by either adding them to
the `exports` or `module` objects passed to the `Init` method.
The return value from `Init` is treated as the `exports` object for the module.
The `Init` method is passed an empty object via the `exports` parameter as a
convenience. If `Init` returns NULL, the parameter passed as `exports` is
exported by the module. N-API modules cannot modify the `module` object but can
specify anything as the `exports` property of the module.
For example, to add the method `hello` as a function so that it can be called
as a method provided by the addon:
```C
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor desc =
{"hello", Method, 0, 0, 0, napi_default, 0};
if (status != napi_ok) return nullptr;
status = napi_define_properties(env, exports, 1, &desc);
if (status != napi_ok) return nullptr;
return exports;
}
```
For example, to set a function to be returned by the `require()` for the addon:
```C
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value method;
napi_status status;
napi_property_descriptor desc =
{"exports", Method, 0, 0, 0, napi_default, 0};
status = napi_define_properties(env, module, 1, &desc);
status = napi_create_function(env, "exports", Method, NULL, &method));
if (status != napi_ok) return nullptr;
return method;
}
```
@ -919,7 +926,7 @@ For example, to define a class so that new instances can be created
```C
// NOTE: partial example, not all referenced code is included
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor properties[] = {
{ "value", nullptr, GetValue, SetValue, 0, napi_default, 0 },
@ -930,17 +937,19 @@ napi_property_descriptor properties[] = {
napi_value cons;
status =
napi_define_class(env, "MyObject", New, nullptr, 3, properties, &cons);
if (status != napi_ok) return;
if (status != napi_ok) return nullptr;
status = napi_create_reference(env, cons, 1, &constructor);
if (status != napi_ok) return;
if (status != napi_ok) return nullptr;
status = napi_set_named_property(env, exports, "MyObject", cons);
if (status != napi_ok) return;
if (status != napi_ok) return nullptr;
return exports;
}
```
For more details on setting properties on either the `exports` or `module`
objects, see the section on
For more details on setting properties on objects, see the section on
[Working with JavaScript Properties][].
For more details on building addon modules in general, refer to the existing API

16
src/node_api.cc

@ -822,11 +822,17 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
// one is found.
napi_env env = v8impl::GetEnv(context);
mod->nm_register_func(
env,
v8impl::JsValueFromV8LocalValue(exports),
v8impl::JsValueFromV8LocalValue(module),
mod->nm_priv);
napi_value _exports =
mod->nm_register_func(env, v8impl::JsValueFromV8LocalValue(exports));
// If register function returned a non-null exports object different from
// the exports object we passed it, set that as the "exports" property of
// the module.
if (_exports != nullptr &&
_exports != v8impl::JsValueFromV8LocalValue(exports)) {
napi_value _module = v8impl::JsValueFromV8LocalValue(module);
napi_set_named_property(env, _module, "exports", _exports);
}
}
} // end of anonymous namespace

6
src/node_api.h

@ -44,10 +44,8 @@
#endif
typedef void (*napi_addon_register_func)(napi_env env,
napi_value exports,
napi_value module,
void* priv);
typedef napi_value (*napi_addon_register_func)(napi_env env,
napi_value exports);
typedef struct {
int nm_version;

5
test/addons-napi/1_hello_world/binding.c

@ -10,9 +10,10 @@ napi_value Method(napi_env env, napi_callback_info info) {
return world;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor desc = DECLARE_NAPI_PROPERTY("hello", Method);
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, exports, 1, &desc));
NAPI_CALL(env, napi_define_properties(env, exports, 1, &desc));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

5
test/addons-napi/2_function_arguments/binding.c

@ -29,9 +29,10 @@ napi_value Add(napi_env env, napi_callback_info info) {
return sum;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor desc = DECLARE_NAPI_PROPERTY("add", Add);
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, exports, 1, &desc));
NAPI_CALL(env, napi_define_properties(env, exports, 1, &desc));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

5
test/addons-napi/3_callbacks/binding.c

@ -45,12 +45,13 @@ napi_value RunCallbackWithRecv(napi_env env, napi_callback_info info) {
return NULL;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor desc[2] = {
DECLARE_NAPI_PROPERTY("RunCallback", RunCallback),
DECLARE_NAPI_PROPERTY("RunCallbackWithRecv", RunCallbackWithRecv),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, exports, 2, desc));
NAPI_CALL(env, napi_define_properties(env, exports, 2, desc));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

8
test/addons-napi/4_object_factory/binding.c

@ -14,10 +14,10 @@ napi_value CreateObject(napi_env env, napi_callback_info info) {
return obj;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_property_descriptor desc =
DECLARE_NAPI_PROPERTY("exports", CreateObject);
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, module, 1, &desc));
napi_value Init(napi_env env, napi_value exports) {
NAPI_CALL(env,
napi_create_function(env, "exports", CreateObject, NULL, &exports));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

8
test/addons-napi/5_function_factory/binding.c

@ -16,10 +16,10 @@ napi_value CreateFunction(napi_env env, napi_callback_info info) {
return fn;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_property_descriptor desc =
DECLARE_NAPI_PROPERTY("exports", CreateFunction);
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, module, 1, &desc));
napi_value Init(napi_env env, napi_value exports) {
NAPI_CALL(env,
napi_create_function(env, "exports", CreateFunction, NULL, &exports));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

4
test/addons-napi/6_object_wrap/binding.cc

@ -1,7 +1,9 @@
#include "myobject.h"
#include "../common.h"
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
MyObject::Init(env, exports);
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

10
test/addons-napi/7_factory_wrap/binding.cc

@ -12,12 +12,12 @@ napi_value CreateObject(napi_env env, napi_callback_info info) {
return instance;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
NAPI_CALL_RETURN_VOID(env, MyObject::Init(env));
napi_value Init(napi_env env, napi_value exports) {
NAPI_CALL(env, MyObject::Init(env));
napi_property_descriptor desc =
DECLARE_NAPI_PROPERTY("exports", CreateObject);
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, module, 1, &desc));
NAPI_CALL(env,
napi_create_function(env, "exports", CreateObject, NULL, &exports));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/8_passing_wrapped/binding.cc

@ -29,7 +29,7 @@ napi_value Add(napi_env env, napi_callback_info info) {
return sum;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
MyObject::Init(env);
napi_property_descriptor desc[] = {
@ -37,8 +37,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("add", Add),
};
NAPI_CALL_RETURN_VOID(env,
NAPI_CALL(env,
napi_define_properties(env, exports, sizeof(desc) / sizeof(*desc), desc));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_array/test_array.c

@ -169,7 +169,7 @@ napi_value NewWithLength(napi_env env, napi_callback_info info) {
return ret;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("TestGetElement", TestGetElement),
DECLARE_NAPI_PROPERTY("TestHasElement", TestHasElement),
@ -178,8 +178,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("NewWithLength", NewWithLength),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_async/test_async.cc

@ -173,14 +173,16 @@ napi_value TestCancel(napi_env env, napi_callback_info info) {
return nullptr;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("Test", Test),
DECLARE_NAPI_PROPERTY("TestCancel", TestCancel),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

11
test/addons-napi/test_buffer/test_buffer.c

@ -119,13 +119,12 @@ napi_value staticBuffer(napi_env env, napi_callback_info info) {
return theBuffer;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value theValue;
NAPI_CALL_RETURN_VOID(env,
NAPI_CALL(env,
napi_create_string_utf8(env, theText, sizeof(theText), &theValue));
NAPI_CALL_RETURN_VOID(env,
napi_set_named_property(env, exports, "theText", theValue));
NAPI_CALL(env, napi_set_named_property(env, exports, "theText", theValue));
napi_property_descriptor methods[] = {
DECLARE_NAPI_PROPERTY("newBuffer", newBuffer),
@ -137,8 +136,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("staticBuffer", staticBuffer),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(methods) / sizeof(methods[0]), methods));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

12
test/addons-napi/test_constructor/test_constructor.c

@ -59,9 +59,9 @@ napi_value GetStaticValue(napi_env env, napi_callback_info info) {
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value number;
NAPI_CALL_RETURN_VOID(env, napi_create_double(env, value_, &number));
NAPI_CALL(env, napi_create_double(env, value_, &number));
napi_property_descriptor properties[] = {
{ "echo", 0, Echo, 0, 0, 0, napi_enumerable, 0 },
@ -77,14 +77,12 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
};
napi_value cons;
NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "MyObject", New,
NAPI_CALL(env, napi_define_class(env, "MyObject", New,
NULL, sizeof(properties)/sizeof(*properties), properties, &cons));
NAPI_CALL_RETURN_VOID(env,
napi_set_named_property(env, module, "exports", cons));
NAPI_CALL(env, napi_create_reference(env, cons, 1, &constructor_));
NAPI_CALL_RETURN_VOID(env,
napi_create_reference(env, cons, 1, &constructor_));
return cons;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_conversions/test_conversions.c

@ -130,7 +130,7 @@ napi_value ToString(napi_env env, napi_callback_info info) {
return output;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("asBool", AsBool),
DECLARE_NAPI_PROPERTY("asInt32", AsInt32),
@ -144,8 +144,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("toString", ToString),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_dataview/test_dataview.c

@ -37,13 +37,15 @@ napi_value CreateDataView(napi_env env, napi_callback_info info) {
return output_dataview;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("CreateDataView", CreateDataView)
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_env_sharing/compare_env.c

@ -14,9 +14,9 @@ napi_value compare(napi_env env, napi_callback_info info) {
return return_value;
}
void Init(napi_env env, napi_value exports, napi_value module, void* context) {
napi_property_descriptor prop = DECLARE_NAPI_PROPERTY("exports", compare);
NAPI_CALL_RETURN_VOID(env, napi_define_properties(env, module, 1, &prop));
napi_value Init(napi_env env, napi_value exports) {
NAPI_CALL(env, napi_create_function(env, "exports", compare, NULL, &exports));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

8
test/addons-napi/test_env_sharing/store_env.c

@ -1,12 +1,10 @@
#include <node_api.h>
#include "../common.h"
void Init(napi_env env, napi_value exports, napi_value module, void* context) {
napi_value Init(napi_env env, napi_value exports) {
napi_value external;
NAPI_CALL_RETURN_VOID(env,
napi_create_external(env, env, NULL, NULL, &external));
NAPI_CALL_RETURN_VOID(env,
napi_set_named_property(env, module, "exports", external));
NAPI_CALL(env, napi_create_external(env, env, NULL, NULL, &external));
return external;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_error/test_error.cc

@ -119,7 +119,7 @@ napi_value createTypeErrorCode(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("checkError", checkError),
DECLARE_NAPI_PROPERTY("throwExistingError", throwExistingError),
@ -137,8 +137,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("createTypeErrorCode", createTypeErrorCode),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_exception/test_exception.c

@ -45,15 +45,17 @@ napi_value wasPending(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("returnException", returnException),
DECLARE_NAPI_PROPERTY("allowException", allowException),
DECLARE_NAPI_PROPERTY("wasPending", wasPending),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_fatal/test_fatal.c

@ -6,13 +6,15 @@ napi_value Test(napi_env env, napi_callback_info info) {
return NULL;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("Test", Test),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

7
test/addons-napi/test_function/test_function.c

@ -26,10 +26,11 @@ napi_value Test(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value fn;
NAPI_CALL_RETURN_VOID(env, napi_create_function(env, NULL, Test, NULL, &fn));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, exports, "Test", fn));
NAPI_CALL(env, napi_create_function(env, NULL, Test, NULL, &fn));
NAPI_CALL(env, napi_set_named_property(env, exports, "Test", fn));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_general/test_general.c

@ -224,7 +224,7 @@ napi_value testNapiRun(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("testStrictEquals", testStrictEquals),
DECLARE_NAPI_PROPERTY("testGetPrototype", testGetPrototype),
@ -245,8 +245,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("testAdjustExternalMemory", testAdjustExternalMemory)
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_handle_scope/test_handle_scope.c

@ -66,7 +66,7 @@ napi_value NewScopeWithException(napi_env env, napi_callback_info info) {
return NULL;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("NewScope", NewScope),
DECLARE_NAPI_PROPERTY("NewScopeEscape", NewScopeEscape),
@ -74,8 +74,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("NewScopeWithException", NewScopeWithException),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

9
test/addons-napi/test_make_callback/binding.cc

@ -35,12 +35,11 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value fn;
NAPI_CALL_RETURN_VOID(env,
napi_create_function(env, NULL, MakeCallback, NULL, &fn));
NAPI_CALL_RETURN_VOID(env,
napi_set_named_property(env, exports, "makeCallback", fn));
NAPI_CALL(env, napi_create_function(env, NULL, MakeCallback, NULL, &fn));
NAPI_CALL(env, napi_set_named_property(env, exports, "makeCallback", fn));
return exports;
}
} // namespace

10
test/addons-napi/test_make_callback_recurse/binding.cc

@ -18,15 +18,13 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
return recv;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value fn;
NAPI_CALL_RETURN_VOID(env,
napi_create_function(env, NULL, MakeCallback, NULL, &fn));
NAPI_CALL_RETURN_VOID(env,
napi_set_named_property(env, exports, "makeCallback", fn));
NAPI_CALL(env, napi_create_function(env, NULL, MakeCallback, NULL, &fn));
NAPI_CALL(env, napi_set_named_property(env, exports, "makeCallback", fn));
return exports;
}
} // namespace
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_number/test_number.c

@ -45,14 +45,16 @@ napi_value TestInt32Truncation(napi_env env, napi_callback_info info) {
return output;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("Test", Test),
DECLARE_NAPI_PROPERTY("TestInt32Truncation", TestInt32Truncation),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_object/test_object.c

@ -219,7 +219,7 @@ napi_value Unwrap(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("Get", Get),
DECLARE_NAPI_PROPERTY("Set", Set),
@ -232,8 +232,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("Unwrap", Unwrap),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_promise/test_promise.c

@ -46,15 +46,17 @@ napi_value isPromise(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("createPromise", createPromise),
DECLARE_NAPI_PROPERTY("concludeCurrentPromise", concludeCurrentPromise),
DECLARE_NAPI_PROPERTY("isPromise", isPromise),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

14
test/addons-napi/test_properties/test_properties.c

@ -59,23 +59,23 @@ napi_value HasNamedProperty(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_value number;
NAPI_CALL_RETURN_VOID(env, napi_create_double(env, value_, &number));
NAPI_CALL(env, napi_create_double(env, value_, &number));
napi_value name_value;
NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env,
NAPI_CALL(env, napi_create_string_utf8(env,
"NameKeyValue",
-1,
&name_value));
napi_value symbol_description;
napi_value name_symbol;
NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env,
NAPI_CALL(env, napi_create_string_utf8(env,
"NameKeySymbol",
-1,
&symbol_description));
NAPI_CALL_RETURN_VOID(env, napi_create_symbol(env,
NAPI_CALL(env, napi_create_symbol(env,
symbol_description,
&name_symbol));
@ -93,8 +93,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
{ "hasNamedProperty", 0, HasNamedProperty, 0, 0, 0, napi_default, 0 },
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_reference/test_reference.c

@ -132,7 +132,7 @@ napi_value GetReferenceValue(napi_env env, napi_callback_info info) {
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_GETTER("finalizeCount", GetFinalizeCount),
DECLARE_NAPI_PROPERTY("createExternal", CreateExternal),
@ -146,8 +146,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_GETTER("referenceValue", GetReferenceValue),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_string/test_string.c

@ -201,7 +201,7 @@ napi_value Utf8Length(napi_env env, napi_callback_info info) {
return output;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("TestLatin1", TestLatin1),
DECLARE_NAPI_PROPERTY("TestLatin1Insufficient", TestLatin1Insufficient),
@ -213,8 +213,10 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
DECLARE_NAPI_PROPERTY("Utf8Length", Utf8Length),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

6
test/addons-napi/test_symbol/test_symbol.c

@ -48,13 +48,15 @@ napi_value New(napi_env env, napi_callback_info info) {
return symbol;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NAPI_PROPERTY("New", New),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

9
test/addons-napi/test_typedarray/test_typedarray.c

@ -65,7 +65,8 @@ napi_value Multiply(napi_env env, napi_callback_info info) {
output_doubles[i] = input_doubles[i] * multiplier;
}
} else {
napi_throw_error(env, NULL, "Typed array was of a type not expected by test.");
napi_throw_error(env, NULL,
"Typed array was of a type not expected by test.");
return NULL;
}
@ -142,15 +143,17 @@ napi_value CreateTypedArray(napi_env env, napi_callback_info info) {
return output_array;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("Multiply", Multiply),
DECLARE_NAPI_PROPERTY("External", External),
DECLARE_NAPI_PROPERTY("CreateTypedArray", CreateTypedArray),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
NAPI_CALL(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

Loading…
Cancel
Save