|
2 | 2 | #define NAPI_VERSION 6 |
3 | 3 | #include <assert.h> |
4 | 4 |
|
| 5 | +uint32_t buf[3]; |
| 6 | + |
| 7 | +napi_value set_buffer(napi_env env, napi_callback_info info) { |
| 8 | + napi_status status; |
| 9 | + |
| 10 | + size_t argc = 1; |
| 11 | + napi_value args[1]; |
| 12 | + status = napi_get_cb_info(env, info, &argc, args, NULL, NULL); |
| 13 | + assert(status == napi_ok); |
| 14 | + |
| 15 | + size_t len; |
| 16 | + status = napi_get_buffer_info(env, args[0], (void **)&buf, &len); |
| 17 | + assert(status == napi_ok); |
| 18 | + |
| 19 | + return NULL; |
| 20 | +} |
| 21 | + |
| 22 | +napi_value sb_add(napi_env env, napi_callback_info info) { |
| 23 | + buf[2] = test_add_uint32_t(buf[0], buf[1]); |
| 24 | + return NULL; |
| 25 | +} |
| 26 | + |
5 | 27 | napi_value add(napi_env env, napi_callback_info info) { |
6 | 28 | napi_status status; |
7 | 29 |
|
@@ -31,8 +53,13 @@ napi_value add(napi_env env, napi_callback_info info) { |
31 | 53 |
|
32 | 54 | napi_value Init(napi_env env, napi_value exports) { |
33 | 55 | napi_status status; |
34 | | - napi_property_descriptor addDescriptor = DECLARE_NAPI_METHOD("add", add); |
35 | | - status = napi_define_properties(env, exports, 1, &addDescriptor); |
| 56 | + napi_property_descriptor addDescriptor1 = DECLARE_NAPI_METHOD("add", add); |
| 57 | + status = napi_define_properties(env, exports, 1, &addDescriptor1); |
| 58 | + napi_property_descriptor addDescriptor2 = DECLARE_NAPI_METHOD("sb_add", sb_add); |
| 59 | + status = napi_define_properties(env, exports, 1, &addDescriptor2); |
| 60 | + napi_property_descriptor addDescriptor3 = DECLARE_NAPI_METHOD("set_buffer", set_buffer); |
| 61 | + status = napi_define_properties(env, exports, 1, &addDescriptor3); |
| 62 | + |
36 | 63 | assert(status == napi_ok); |
37 | 64 | return exports; |
38 | 65 | } |
|
0 commit comments