提交 00ede221 编写于 作者: H hekun

fix the code check

Signed-off-by: Nhekun <hekun18@huawei.com>
上级 93a5b627
...@@ -1324,8 +1324,8 @@ static napi_value TestLatin1(napi_env env, napi_callback_info info) { ...@@ -1324,8 +1324,8 @@ static napi_value TestLatin1(napi_env env, napi_callback_info info) {
return output; return output;
} }
// test the napi function // test the napi function
static napi_value napiCreateArrayBuffer(napi_env env, napi_callback_info info) static napi_value napCreateArrayBuffer(napi_env env, napi_callback_info info) {
{
napi_value arrayBuffer = nullptr; napi_value arrayBuffer = nullptr;
void* arrayBufferPtr = nullptr; void* arrayBufferPtr = nullptr;
size_t arrayBufferSize = 1024; size_t arrayBufferSize = 1024;
...@@ -1336,8 +1336,8 @@ static napi_value napiCreateArrayBuffer(napi_env env, napi_callback_info info) ...@@ -1336,8 +1336,8 @@ static napi_value napiCreateArrayBuffer(napi_env env, napi_callback_info info)
return arrayBuffer; return arrayBuffer;
} }
static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info) static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info) {
{
// the value to return // the value to return
napi_value arrayBuffer; napi_value arrayBuffer;
napi_status status; napi_status status;
...@@ -1356,10 +1356,10 @@ static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info) ...@@ -1356,10 +1356,10 @@ static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info)
NAPI_CALL(env, napi_create_int32(env, arrayBufferLength, &arrayLength)); NAPI_CALL(env, napi_create_int32(env, arrayBufferLength, &arrayLength));
return arrayLength; return arrayLength;
} }
static napi_value napiNewInstance(napi_env env, napi_callback_info info) static napi_value napiNewInstance(napi_env env, napi_callback_info info) {
{
// the value to return // the value to return
napi_value global, constructor, arg, value; napi_value global, constructor, arg, value;
napi_status status = napi_get_global(env, &global); napi_status status = napi_get_global(env, &global);
...@@ -1375,18 +1375,14 @@ static napi_value napiNewInstance(napi_env env, napi_callback_info info) ...@@ -1375,18 +1375,14 @@ static napi_value napiNewInstance(napi_env env, napi_callback_info info)
return value; return value;
} }
static napi_value napiDefineClass(napi_env env, napi_callback_info info) static napi_value napiDefineClass(napi_env env, napi_callback_info info) {
{
napi_value testWrapClass = nullptr; napi_value testWrapClass = nullptr;
napi_define_class( napi_define_class(env, "TestWrapClass", NAPI_AUTO_LENGTH, [](napi_env env, napi_callback_info info) -> napi_value {
env, "TestWrapClass", NAPI_AUTO_LENGTH,
[](napi_env env, napi_callback_info info) -> napi_value {
napi_value thisVar = nullptr; napi_value thisVar = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
return thisVar; return thisVar;
}, }, nullptr, 0, nullptr, &testWrapClass);
nullptr, 0, nullptr, &testWrapClass);
napi_value instanceValue = nullptr; napi_value instanceValue = nullptr;
napi_new_instance(env, testWrapClass, 0, nullptr, &instanceValue); napi_new_instance(env, testWrapClass, 0, nullptr, &instanceValue);
...@@ -1397,23 +1393,23 @@ static napi_value napiDefineClass(napi_env env, napi_callback_info info) ...@@ -1397,23 +1393,23 @@ static napi_value napiDefineClass(napi_env env, napi_callback_info info)
return value; return value;
} }
static napi_value napiRunScriptPath(napi_env env, napi_callback_info info) static napi_value napiRunScriptPath(napi_env env, napi_callback_info info) {
{
napi_value value; napi_value value;
char const *path = "/index/name"; char const* path = "/index/name";
napi_status status = napi_run_script_path(env, path, &value); napi_status status = napi_run_script_path(env, path, &value);
NAPI_ASSERT(env, status == napi_ok, "napi_run_script_path ok"); NAPI_ASSERT(env, status == napi_ok, "napi_run_script_path ok");
napi_value _value; napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value)); NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value; return _value;
} }
static napi_value napiGetNodeVersion(napi_env env, napi_callback_info info) static napi_value napiGetNodeVersion(napi_env env, napi_callback_info info) {
{
napi_value value; napi_value value;
const napi_node_version* version ; const napi_node_version* version;
napi_get_node_version(env,&version); napi_get_node_version(env, &version);
const char* release = version->release; const char* release = version->release;
napi_status status = napi_create_string_utf8(env, release, strlen(release), &value); napi_status status = napi_create_string_utf8(env, release, strlen(release), &value);
NAPI_ASSERT(env, status == napi_ok, "napi_create_string_utf8 ok"); NAPI_ASSERT(env, status == napi_ok, "napi_create_string_utf8 ok");
...@@ -1423,8 +1419,8 @@ static napi_value napiGetNodeVersion(napi_env env, napi_callback_info info) ...@@ -1423,8 +1419,8 @@ static napi_value napiGetNodeVersion(napi_env env, napi_callback_info info)
return _value; return _value;
} }
static napi_value napiCallThreadsafeFunction(napi_env env, napi_callback_info info) static napi_value napiCallThreadsafeFunction(napi_env env, napi_callback_info info) {
{
void *data = nullptr; void *data = nullptr;
napi_threadsafe_function func = (napi_threadsafe_function)data; napi_threadsafe_function func = (napi_threadsafe_function)data;
napi_threadsafe_function_call_mode blockMode = napi_tsfn_nonblocking; napi_threadsafe_function_call_mode blockMode = napi_tsfn_nonblocking;
...@@ -1442,40 +1438,41 @@ static napi_value napiCallThreadsafeFunction(napi_env env, napi_callback_info in ...@@ -1442,40 +1438,41 @@ static napi_value napiCallThreadsafeFunction(napi_env env, napi_callback_info in
return value; return value;
} }
static void TsFuncFinalTotalFour(napi_env env, void* finalizeData, void* hint) static void TsFuncFinalTotalFour(napi_env env, void* finalizeData, void* hint) {
{
static uv_thread_t g_uvThreadTest7; static uv_thread_t g_uvThreadTest7;
uv_thread_join(&g_uvThreadTest7); uv_thread_join(&g_uvThreadTest7);
} }
static void TsFuncCallJsFour(napi_env env, napi_value tsfn_cb, void* context, void* data) static void TsFuncCallJsFour(napi_env env, napi_value tsfn_cb, void* context, void* data) {
{
int* pData = (int32_t*)data; int* pData = (int32_t*)data;
printf("TsFuncCallJsFour is %p \n", pData); printf("TsFuncCallJsFour is %p \n", pData);
} }
static napi_value napiCreateThreadsafeFunction(napi_env env, napi_callback_info info) static napi_value napiCreateThreadsafeFunction(napi_env env, napi_callback_info info) {
{
napi_threadsafe_function tsFunc = nullptr; napi_threadsafe_function tsFunc = nullptr;
napi_value resourceName = 0; napi_value resourceName = 0;
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
int32_t CALL_JS_CB_DATA_TEST_ID = 101; int32_t CALL_JST_CB_DATA_TEST_ID = 101;
int32_t FINAL_CB_DATA_TEST_ID = 1001; int32_t FINAL_CBT_DATA_TEST_ID = 1001;
napi_status status = napi_create_threadsafe_function(env, nullptr, nullptr, resourceName, napi_status status = napi_create_threadsafe_function(env, nullptr, nullptr, resourceName,
0, 1, &CALL_JS_CB_DATA_TEST_ID, TsFuncFinalTotalFour, &FINAL_CB_DATA_TEST_ID , TsFuncCallJsFour, &tsFunc); 0, 1, &CALL_JST_CB_DATA_TEST_ID, TsFuncFinalTotalFour, &FINAL_CBT_DATA_TEST_ID , TsFuncCallJsFour, &tsFunc);
NAPI_ASSERT(env, status == napi_ok, "napi_create_threadsafe_function"); NAPI_ASSERT(env, status == napi_ok, "napi_create_threadsafe_function");
napi_acquire_threadsafe_function(tsFunc); napi_acquire_threadsafe_function(tsFunc);
status = napi_unref_threadsafe_function(env, tsFunc); status = napi_unref_threadsafe_function(env, tsFunc);
NAPI_ASSERT(env, status == napi_ok, "napi_unref_threadsafe_function"); NAPI_ASSERT(env, status == napi_ok, "napi_unref_threadsafe_function");
napi_value _value; napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value)); NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value; return _value;
} }
static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info) static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info) {
{
napi_async_work work = nullptr; napi_async_work work = nullptr;
napi_value resourceName = nullptr; napi_value resourceName = nullptr;
napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName); napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
...@@ -1483,7 +1480,7 @@ static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info) ...@@ -1483,7 +1480,7 @@ static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info)
[](napi_env env, napi_status status, void* data) { [](napi_env env, napi_status status, void* data) {
napi_async_work workData = (napi_async_work)data; napi_async_work workData = (napi_async_work)data;
napi_delete_async_work(env, workData); napi_delete_async_work(env, workData);
},work, &work); }, work, &work);
napi_queue_async_work(env, work); napi_queue_async_work(env, work);
napi_cancel_async_work(env, work); napi_cancel_async_work(env, work);
napi_value value; napi_value value;
...@@ -1498,8 +1495,8 @@ static napi_value SayHello(napi_env env, napi_callback_info info) { ...@@ -1498,8 +1495,8 @@ static napi_value SayHello(napi_env env, napi_callback_info info) {
return NULL; return NULL;
} }
static napi_value napiCreateFunction(napi_env env, napi_callback_info info) static napi_value napiCreateFunction(napi_env env, napi_callback_info info) {
{
napi_value funcValue = nullptr; napi_value funcValue = nullptr;
napi_status status = napi_create_function(env, NULL, 0, SayHello, NULL, &funcValue); napi_status status = napi_create_function(env, NULL, 0, SayHello, NULL, &funcValue);
NAPI_ASSERT(env, status != napi_ok, "napi_create_function fail"); NAPI_ASSERT(env, status != napi_ok, "napi_create_function fail");
...@@ -1510,26 +1507,27 @@ static napi_value napiCreateFunction(napi_env env, napi_callback_info info) ...@@ -1510,26 +1507,27 @@ static napi_value napiCreateFunction(napi_env env, napi_callback_info info)
} }
static napi_value napiRefthreadSafeFunction(napi_env env, napi_callback_info info) static napi_value napiRefthreadSafeFunction(napi_env env, napi_callback_info info) {
{
napi_threadsafe_function tsFunc = nullptr; napi_threadsafe_function tsFunc = nullptr;
napi_value resourceName = 0; napi_value resourceName = 0;
napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
int32_t CALL_JS_CB_DATA_TEST_ID = 101; int32_t CALL_JS_CB_DATA_TEST_ID = 101;
int32_t FINAL_CB_DATA_TEST_ID = 1001; int32_t FINAL_CB_DATA_TEST_ID = 1001;
napi_status status = napi_create_threadsafe_function(env, nullptr, nullptr, resourceName, napi_status status = napi_create_threadsafe_function(env, nullptr, nullptr, resourceName,
0, 1, &CALL_JS_CB_DATA_TEST_ID, TsFuncFinalTotalFour, &FINAL_CB_DATA_TEST_ID , TsFuncCallJsFour, &tsFunc); 0, 1, &CALL_JS_CB_DATA_TEST_ID, TsFuncFinalTotalFour, &FINAL_CB_DATA_TEST_ID , TsFuncCallJsFour, &tsFunc);
NAPI_ASSERT(env, status == napi_ok, "napi_create_threadsafe_function"); NAPI_ASSERT(env, status == napi_ok, "napi_create_threadsafe_function");
status = napi_ref_threadsafe_function(env, tsFunc); status = napi_ref_threadsafe_function(env, tsFunc);
NAPI_ASSERT(env, status == napi_ok, "napi_ref_threadsafe_function"); NAPI_ASSERT(env, status == napi_ok, "napi_ref_threadsafe_function");
napi_value _value; napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value)); NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value; return _value;
} }
static napi_value napiCreateDate(napi_env env, napi_callback_info info) static napi_value napiCreateDate(napi_env env, napi_callback_info info) {
{
napi_value createResult = nullptr; napi_value createResult = nullptr;
double time = 202110181203150; double time = 202110181203150;
napi_status status = napi_create_date(env, time, &createResult); napi_status status = napi_create_date(env, time, &createResult);
...@@ -1542,11 +1540,12 @@ static napi_value napiCreateDate(napi_env env, napi_callback_info info) ...@@ -1542,11 +1540,12 @@ static napi_value napiCreateDate(napi_env env, napi_callback_info info)
} }
napi_value value; napi_value value;
NAPI_CALL(env, napi_create_int32(env, result, &value)); NAPI_CALL(env, napi_create_int32(env, result, &value));
return value; return value;
} }
static napi_value napiCreateBigintUint64(napi_env env, napi_callback_info info) static napi_value napiCreateBigintUint64(napi_env env, napi_callback_info info) {
{
uint64_t testValue = UINT64_MAX; uint64_t testValue = UINT64_MAX;
napi_value result = nullptr; napi_value result = nullptr;
napi_create_bigint_uint64(env, testValue, &result); napi_create_bigint_uint64(env, testValue, &result);
...@@ -1556,11 +1555,12 @@ static napi_value napiCreateBigintUint64(napi_env env, napi_callback_info info) ...@@ -1556,11 +1555,12 @@ static napi_value napiCreateBigintUint64(napi_env env, napi_callback_info info)
napi_get_value_bigint_uint64(env, result, &resultValue, &flag); napi_get_value_bigint_uint64(env, result, &resultValue, &flag);
napi_value value; napi_value value;
NAPI_CALL(env, napi_create_int32(env, flag, &value)); NAPI_CALL(env, napi_create_int32(env, flag, &value));
return value;
return value;
} }
static napi_value napiCreateBigintInt64(napi_env env, napi_callback_info info) static napi_value napiCreateBigintInt64(napi_env env, napi_callback_info info) {
{
int64_t testValue = INT64_MAX; int64_t testValue = INT64_MAX;
napi_value result = nullptr; napi_value result = nullptr;
napi_create_bigint_int64(env, testValue, &result); napi_create_bigint_int64(env, testValue, &result);
...@@ -1569,29 +1569,31 @@ static napi_value napiCreateBigintInt64(napi_env env, napi_callback_info info) ...@@ -1569,29 +1569,31 @@ static napi_value napiCreateBigintInt64(napi_env env, napi_callback_info info)
napi_get_value_bigint_int64(env, result, &resultValue, &flag); napi_get_value_bigint_int64(env, result, &resultValue, &flag);
napi_value value; napi_value value;
NAPI_CALL(env, napi_create_int32(env, flag, &value)); NAPI_CALL(env, napi_create_int32(env, flag, &value));
return value;
return value;
} }
static napi_value napiCreateBigintWords(napi_env env, napi_callback_info info) static napi_value napiCreateBigintWords(napi_env env, napi_callback_info info) {
{
int signBit = 0; int signBit = 0;
size_t wordCount = 4; size_t wordCount = 4;
uint64_t words[] = { 0xFFFFFFFFFFFFFFFF, 34ULL, 56ULL, 0xFFFFFFFFFFFFFFFF }; uint64_t words[] = { 0xFFFFFFFFFFFFFFFF, 34ULL, 56ULL, 0xFFFFFFFFFFFFFFFF };
uint64_t wordsOut[] = { 0ULL, 0ULL, 0ULL, 0ULL }; uint64_t wordsOut[] = { 0ULL, 0ULL, 0ULL, 0ULL };
napi_value result = nullptr; napi_value result = nullptr;
NAPI_CALL(env,napi_create_bigint_words(env, signBit, wordCount, words, &result)); NAPI_CALL(env, napi_create_bigint_words(env, signBit, wordCount, words, &result));
NAPI_CALL(env,napi_get_value_bigint_words(env, result, &signBit, &wordCount, wordsOut)); NAPI_CALL(env, napi_get_value_bigint_words(env, result, &signBit, &wordCount, wordsOut));
bool testResult = false; bool testResult = false;
if (signBit == 0 && wordCount == 2 && words[0] == wordsOut[0] && words[1] == wordsOut[1]) { if (signBit == 0 && wordCount == 2 && words[0] == wordsOut[0] && words[1] == wordsOut[1]) {
testResult = true; testResult = true;
} }
napi_value value; napi_value value;
NAPI_CALL(env, napi_create_int32(env, testResult, &value)); NAPI_CALL(env, napi_create_int32(env, testResult, &value));
return value; return value;
} }
static napi_value napiFatalerror(napi_env env, napi_callback_info info) static napi_value napiFatalerror(napi_env env, napi_callback_info info) {
{
void *data = nullptr; void *data = nullptr;
napi_threadsafe_function tsfun = static_cast<napi_threadsafe_function>(data); napi_threadsafe_function tsfun = static_cast<napi_threadsafe_function>(data);
if (napi_release_threadsafe_function(tsfun, napi_tsfn_release) == napi_ok) { if (napi_release_threadsafe_function(tsfun, napi_tsfn_release) == napi_ok) {
...@@ -1599,6 +1601,7 @@ static napi_value napiFatalerror(napi_env env, napi_callback_info info) ...@@ -1599,6 +1601,7 @@ static napi_value napiFatalerror(napi_env env, napi_callback_info info)
} }
napi_value _value; napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value)); NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value; return _value;
} }
...@@ -1682,7 +1685,7 @@ static napi_value Init(napi_env env, napi_value exports) { ...@@ -1682,7 +1685,7 @@ static napi_value Init(napi_env env, napi_value exports) {
DECLARE_NAPI_FUNCTION("isPromise", isPromise), DECLARE_NAPI_FUNCTION("isPromise", isPromise),
DECLARE_NAPI_FUNCTION("TestLatin1", TestLatin1), DECLARE_NAPI_FUNCTION("TestLatin1", TestLatin1),
DECLARE_NAPI_FUNCTION("runScript", runScript), DECLARE_NAPI_FUNCTION("runScript", runScript),
DECLARE_NAPI_FUNCTION("napiCreateArrayBuffer", napiCreateArrayBuffer), DECLARE_NAPI_FUNCTION("napCreateArrayBuffer", napCreateArrayBuffer),
DECLARE_NAPI_FUNCTION("naiGetArrayBufferInfo", naiGetArrayBufferInfo), DECLARE_NAPI_FUNCTION("naiGetArrayBufferInfo", naiGetArrayBufferInfo),
DECLARE_NAPI_FUNCTION("napiNewInstance", napiNewInstance), DECLARE_NAPI_FUNCTION("napiNewInstance", napiNewInstance),
DECLARE_NAPI_FUNCTION("napiDefineClass", napiDefineClass), DECLARE_NAPI_FUNCTION("napiDefineClass", napiDefineClass),
...@@ -1699,8 +1702,7 @@ static napi_value Init(napi_env env, napi_value exports) { ...@@ -1699,8 +1702,7 @@ static napi_value Init(napi_env env, napi_value exports) {
{ "napiCreateFunction", nullptr, napiCreateFunction, nullptr, nullptr, nullptr, napi_default, nullptr }, { "napiCreateFunction", nullptr, napiCreateFunction, nullptr, nullptr, nullptr, napi_default, nullptr },
DECLARE_NAPI_FUNCTION("napiFatalerror", napiFatalerror), }; DECLARE_NAPI_FUNCTION("napiFatalerror", napiFatalerror), };
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties)); NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties));
return exports; return exports;
} }
......
...@@ -58,12 +58,12 @@ export default function nativeApiStringJsunit() { ...@@ -58,12 +58,12 @@ export default function nativeApiStringJsunit() {
/** /**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0200 * @tc.number SUB_ACE_BASIC_ETS_NAPI_0200
* @tc.name napiCreateArrayBuffer * @tc.name napCreateArrayBuffer
* @tc.desc aceNapiEtsTest * @tc.desc aceNapiEtsTest
*/ */
it('napiCreateArrayBuffer002', 0, async function (done) { it('napCreateArrayBuffer002', 0, async function (done) {
console.info('napiCreateArrayBuffer002 START'); console.info('napiCreateArrayBuffer002 START');
value = napitest.napiCreateArrayBuffer(); value = napitest.napCreateArrayBuffer();
console.info('apiCreateArrayBuffer testString result is: ' + JSON.stringify(value)); console.info('apiCreateArrayBuffer testString result is: ' + JSON.stringify(value));
expect(value instanceof ArrayBuffer).assertTrue(); expect(value instanceof ArrayBuffer).assertTrue();
done(); done();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册