-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
represent
napi_callback_info
with non-zero number (#78)
* add cbinfo test * implement real napi_callback_info pointer
- Loading branch information
1 parent
9bc69c5
commit 9373df1
Showing
6 changed files
with
122 additions
and
13 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
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
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
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
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,69 @@ | ||
#include <js_native_api.h> | ||
#include "../common.h" | ||
|
||
static napi_value Test1(napi_env env, napi_callback_info info) { | ||
size_t argc = 1; | ||
napi_value args[1]; | ||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); | ||
|
||
NAPI_ASSERT(env, argc == 1, | ||
"Test1: 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, | ||
"Test1: Wrong type of arguments. Expects a function as first argument."); | ||
|
||
napi_value argv[1]; | ||
NAPI_CALL(env, napi_create_bigint_int64(env, (int64_t) info, argv)); | ||
|
||
napi_value global; | ||
NAPI_CALL(env, napi_get_global(env, &global)); | ||
|
||
napi_value cb = args[0]; | ||
NAPI_CALL(env, napi_call_function(env, global, cb, 1, argv, NULL)); | ||
|
||
return NULL; | ||
} | ||
|
||
static napi_value Test2(napi_env env, napi_callback_info info) { | ||
size_t argc = 1; | ||
napi_value args[1]; | ||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); | ||
|
||
NAPI_ASSERT(env, argc == 1, | ||
"Test2: 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_bigint, | ||
"Test2: Wrong type of arguments. Expects a bigint as first argument."); | ||
|
||
int64_t prev_info; | ||
bool lossless; | ||
NAPI_CALL(env, napi_get_value_bigint_int64(env, args[0], &prev_info, &lossless)); | ||
|
||
size_t prev_argc = 1; | ||
napi_value prev_args[1]; | ||
NAPI_CALL(env, napi_get_cb_info(env, (napi_callback_info) prev_info, &prev_argc, prev_args, NULL, NULL)); | ||
|
||
NAPI_ASSERT(env, prev_argc == 1, | ||
"Test2: Wrong number of arguments. Expects a single argument."); | ||
|
||
napi_valuetype t; | ||
NAPI_CALL(env, napi_typeof(env, prev_args[0], &t)); | ||
NAPI_ASSERT(env, t == napi_function, | ||
"Test2: Wrong type of arguments. Expects a function as first argument."); | ||
return NULL; | ||
} | ||
|
||
EXTERN_C_START | ||
napi_value Init(napi_env env, napi_value exports) { | ||
napi_property_descriptor desc[2] = { | ||
DECLARE_NAPI_PROPERTY("test1", Test1), | ||
DECLARE_NAPI_PROPERTY("test2", Test2), | ||
}; | ||
NAPI_CALL(env, napi_define_properties(env, exports, 2, desc)); | ||
return exports; | ||
} | ||
EXTERN_C_END |
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,6 @@ | ||
'use strict' | ||
const { load } = require('../util') | ||
|
||
module.exports = load('cbinfo').then(addon => { | ||
addon.test1(addon.test2) | ||
}) |