Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
975db6f3
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
975db6f3
编写于
11月 17, 2022
作者:
H
hekun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the code 5th
Signed-off-by:
N
hekun
<
hekun18@huawei.com
>
上级
1d8973f4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
69 addition
and
49 deletion
+69
-49
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
+69
-49
未找到文件。
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
浏览文件 @
975db6f3
...
...
@@ -1324,7 +1324,8 @@ static napi_value TestLatin1(napi_env env, napi_callback_info info) {
return
output
;
}
// test the napi function
static
napi_value
napCreateArrayBuffer
(
napi_env
env
,
napi_callback_info
info
)
{
static
napi_value
napCreateArrayBuffer
(
napi_env
env
,
napi_callback_info
info
)
{
napi_value
arrayBuffer
=
nullptr
;
void
*
arrayBufferPtr
=
nullptr
;
size_t
arrayBufferSize
=
1024
;
...
...
@@ -1335,7 +1336,8 @@ static napi_value napCreateArrayBuffer(napi_env env, napi_callback_info info) {
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
napi_value
arrayBuffer
;
napi_status
status
;
...
...
@@ -1356,7 +1358,8 @@ static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info) {
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
napi_value
global
,
constructor
,
arg
,
value
;
napi_status
status
=
napi_get_global
(
env
,
&
global
);
...
...
@@ -1372,7 +1375,8 @@ static napi_value napiNewInstance(napi_env env, napi_callback_info info) {
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_define_class
(
env
,
"TestWrapClass"
,
NAPI_AUTO_LENGTH
,
[](
napi_env
env
,
napi_callback_info
info
)
->
napi_value
{
napi_value
thisVar
=
nullptr
;
...
...
@@ -1389,7 +1393,8 @@ static napi_value napiDefineClass(napi_env env, napi_callback_info info) {
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
;
char
const
*
path
=
"/index/name"
;
napi_status
status
=
napi_run_script_path
(
env
,
path
,
&
value
);
...
...
@@ -1401,7 +1406,8 @@ static napi_value napiRunScriptPath(napi_env env, napi_callback_info info) {
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
;
const
napi_node_version
*
version
;
napi_get_node_version
(
env
,
&
version
);
...
...
@@ -1414,16 +1420,17 @@ static napi_value napiGetNodeVersion(napi_env env, napi_callback_info info) {
return
_value
;
}
static
napi_value
napiCallThreadsafeFunction
(
napi_env
env
,
napi_callback_info
info
)
{
void
*
data
=
nullptr
;
static
napi_value
napiCallThreadsafeFunction
(
napi_env
env
,
napi_callback_info
info
)
{
void
*
data
=
nullptr
;
napi_threadsafe_function
func
=
(
napi_threadsafe_function
)
data
;
napi_threadsafe_function_call_mode
blockMode
=
napi_tsfn_nonblocking
;
void
*
context
=
nullptr
;
napi_status
status
=
napi_get_threadsafe_function_context
(
func
,
&
context
);
NAPI_ASSERT
(
env
,
status
!=
napi_ok
,
"napi_get_threadsafe_function_context fail"
);
static
int32_t
g
_s
endData
=
0
;
napi_call_threadsafe_function
(
func
,
&
g
_s
endData
,
blockMode
);
status
=
napi_call_threadsafe_function
(
func
,
&
g
_s
endData
,
blockMode
);
static
int32_t
g
S
endData
=
0
;
napi_call_threadsafe_function
(
func
,
&
g
S
endData
,
blockMode
);
status
=
napi_call_threadsafe_function
(
func
,
&
g
S
endData
,
blockMode
);
NAPI_ASSERT
(
env
,
status
!=
napi_ok
,
"napi_call_threadsafe_function fail"
);
napi_release_threadsafe_function
(
func
,
napi_tsfn_release
);
napi_value
value
;
...
...
@@ -1432,24 +1439,27 @@ static napi_value napiCallThreadsafeFunction(napi_env env, napi_callback_info in
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
guvThreadTest7
;
uv_thread_join
(
&
guvThreadTest7
);
}
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
;
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_value
resourceName
=
0
;
napi_create_string_latin1
(
env
,
__func__
,
NAPI_AUTO_LENGTH
,
&
resourceName
);
int32_t
callJstCbDataTestId
=
101
;
int32_t
finalCbtDataTestID
=
1001
;
napi_status
status
=
napi_create_threadsafe_function
(
env
,
nullptr
,
nullptr
,
resourceName
,
0
,
1
,
&
callJstCbDataTestId
,
TsFuncFinalTotalFour
,
&
finalCbtDataTestID
,
TsFuncCallJsFour
,
&
tsFunc
);
napi_status
status
=
napi_create_threadsafe_function
(
env
,
nullptr
,
nullptr
,
resourceName
,
0
,
1
,
&
callJstCbDataTestId
,
TsFuncFinalTotalFour
,
&
finalCbtDataTestID
,
TsFuncCallJsFour
,
&
tsFunc
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"napi_create_threadsafe_function"
);
napi_acquire_threadsafe_function
(
tsFunc
);
...
...
@@ -1462,15 +1472,16 @@ static napi_value napiCreateThreadsafeFunction(napi_env env, napi_callback_info
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_value
resourceName
=
nullptr
;
napi_create_string_utf8
(
env
,
"AsyncWorkTest"
,
NAPI_AUTO_LENGTH
,
&
resourceName
);
napi_create_async_work
(
env
,
nullptr
,
resourceName
,
[](
napi_env
value
,
void
*
data
)
{},
[](
napi_env
env
,
napi_status
status
,
void
*
data
)
{
napi_async_work
workData
=
(
napi_async_work
)
data
;
napi_delete_async_work
(
env
,
workData
);
},
work
,
&
work
);
[](
napi_env
env
,
napi_status
status
,
void
*
data
)
{
napi_async_work
workData
=
(
napi_async_work
)
data
;
napi_delete_async_work
(
env
,
workData
);
},
work
,
&
work
);
napi_queue_async_work
(
env
,
work
);
napi_cancel_async_work
(
env
,
work
);
napi_value
value
;
...
...
@@ -1479,13 +1490,15 @@ static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info) {
return
value
;
}
static
napi_value
SayHello
(
napi_env
env
,
napi_callback_info
info
)
{
static
napi_value
SayHello
(
napi_env
env
,
napi_callback_info
info
)
{
printf
(
"Hello
\n
"
);
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_status
status
=
napi_create_function
(
env
,
NULL
,
0
,
SayHello
,
NULL
,
&
funcValue
);
NAPI_ASSERT
(
env
,
status
!=
napi_ok
,
"napi_create_function fail"
);
...
...
@@ -1495,7 +1508,8 @@ static napi_value napiCreateFunction(napi_env env, napi_callback_info info) {
return
value
;
}
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_value
resourceName
=
0
;
napi_create_string_latin1
(
env
,
__func__
,
NAPI_AUTO_LENGTH
,
&
resourceName
);
...
...
@@ -1513,7 +1527,8 @@ static napi_value napiRefthreadSafeFunction(napi_env env, napi_callback_info inf
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
;
double
time
=
202110181203150
;
napi_status
status
=
napi_create_date
(
env
,
time
,
&
createResult
);
...
...
@@ -1530,7 +1545,8 @@ static napi_value napiCreateDate(napi_env env, napi_callback_info info) {
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
;
napi_value
result
=
nullptr
;
napi_create_bigint_uint64
(
env
,
testValue
,
&
result
);
...
...
@@ -1544,7 +1560,8 @@ static napi_value napiCreateBigintUint64(napi_env env, napi_callback_info info)
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
;
napi_value
result
=
nullptr
;
napi_create_bigint_int64
(
env
,
testValue
,
&
result
);
...
...
@@ -1557,7 +1574,8 @@ static napi_value napiCreateBigintInt64(napi_env env, napi_callback_info info) {
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
;
size_t
wordCount
=
4
;
uint64_t
words
[]
=
{
0xFFFFFFFFFFFFFFFF
,
34ULL
,
56ULL
,
0xFFFFFFFFFFFFFFFF
};
...
...
@@ -1567,7 +1585,7 @@ static napi_value napiCreateBigintWords(napi_env env, napi_callback_info info) {
NAPI_CALL
(
env
,
napi_get_value_bigint_words
(
env
,
result
,
&
signBit
,
&
wordCount
,
wordsOut
));
bool
testResult
=
false
;
const
int
wCount
=
2
;
if
(
signBit
==
0
&&
wordCount
==
w
ord
Count
&&
words
[
0
]
==
wordsOut
[
0
]
&&
words
[
1
]
==
wordsOut
[
1
])
{
if
(
signBit
==
0
&&
wordCount
==
wCount
&&
words
[
0
]
==
wordsOut
[
0
]
&&
words
[
1
]
==
wordsOut
[
1
])
{
testResult
=
true
;
}
napi_value
value
;
...
...
@@ -1576,11 +1594,13 @@ static napi_value napiCreateBigintWords(napi_env env, napi_callback_info info) {
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
;
napi_threadsafe_function
tsfun
=
static_cast
<
napi_threadsafe_function
>
(
data
);
if
(
napi_release_threadsafe_function
(
tsfun
,
napi_tsfn_release
)
==
napi_ok
)
{
napi_fatal_error
(
"ReleaseThreadsafeFunction"
,
NAPI_AUTO_LENGTH
,
"napi_release_threadsafe_function failed"
,
NAPI_AUTO_LENGTH
);
napi_fatal_error
(
"ReleaseThreadsafeFunction"
,
NAPI_AUTO_LENGTH
,
"napi_release_threadsafe_function failed"
,
NAPI_AUTO_LENGTH
);
}
napi_value
_value
;
NAPI_CALL
(
env
,
napi_create_int32
(
env
,
0
,
&
_value
));
...
...
@@ -1590,8 +1610,8 @@ static napi_value napiFatalerror(napi_env env, napi_callback_info info) {
EXTERN_C_START
static
napi_value
Init
(
napi_env
env
,
napi_value
exports
)
{
static
napi_value
Init
(
napi_env
env
,
napi_value
exports
)
{
napi_property_descriptor
properties
[]
=
{
DECLARE_NAPI_FUNCTION
(
"getLastErrorInfo"
,
getLastErrorInfo
),
DECLARE_NAPI_FUNCTION
(
"cleanUpErrorInfo"
,
cleanUpErrorInfo
),
DECLARE_NAPI_FUNCTION
(
"throwExistingError"
,
throwExistingError
),
...
...
@@ -1664,22 +1684,22 @@ static napi_value Init(napi_env env, napi_value exports) {
DECLARE_NAPI_FUNCTION
(
"isPromise"
,
isPromise
),
DECLARE_NAPI_FUNCTION
(
"TestLatin1"
,
TestLatin1
),
DECLARE_NAPI_FUNCTION
(
"runScript"
,
runScript
),
DECLARE_NAPI_FUNCTION
(
"napCreateArrayBuffer"
,
napCreateArrayBuffer
),
DECLARE_NAPI_FUNCTION
(
"naiGetArrayBufferInfo"
,
naiGetArrayBufferInfo
),
DECLARE_NAPI_FUNCTION
(
"napiNewInstance"
,
napiNewInstance
),
DECLARE_NAPI_FUNCTION
(
"napiDefineClass"
,
napiDefineClass
),
DECLARE_NAPI_FUNCTION
(
"napiRunScriptPath"
,
napiRunScriptPath
),
DECLARE_NAPI_FUNCTION
(
"napiGetNodeVersion"
,
napiGetNodeVersion
),
DECLARE_NAPI_FUNCTION
(
"napiCallThreadsafeFunction"
,
napiCallThreadsafeFunction
),
DECLARE_NAPI_FUNCTION
(
"napiCreateThreadsafeFunction"
,
napiCreateThreadsafeFunction
),
DECLARE_NAPI_FUNCTION
(
"napiRefthreadSafeFunction"
,
napiRefthreadSafeFunction
),
DECLARE_NAPI_FUNCTION
(
"napiCreateDate"
,
napiCreateDate
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintUint64"
,
napiCreateBigintUint64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintInt64"
,
napiCreateBigintInt64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintWords"
,
napiCreateBigintWords
),
{
"napiCancelAsyncWork"
,
nullptr
,
napiCancelAsyncWork
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"napiCreateFunction"
,
nullptr
,
napiCreateFunction
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
DECLARE_NAPI_FUNCTION
(
"napiFatalerror"
,
napiFatalerror
),
};
DECLARE_NAPI_FUNCTION
(
"napCreateArrayBuffer"
,
napCreateArrayBuffer
),
DECLARE_NAPI_FUNCTION
(
"naiGetArrayBufferInfo"
,
naiGetArrayBufferInfo
),
DECLARE_NAPI_FUNCTION
(
"napiNewInstance"
,
napiNewInstance
),
DECLARE_NAPI_FUNCTION
(
"napiDefineClass"
,
napiDefineClass
),
DECLARE_NAPI_FUNCTION
(
"napiRunScriptPath"
,
napiRunScriptPath
),
DECLARE_NAPI_FUNCTION
(
"napiGetNodeVersion"
,
napiGetNodeVersion
),
DECLARE_NAPI_FUNCTION
(
"napiCallThreadsafeFunction"
,
napiCallThreadsafeFunction
),
DECLARE_NAPI_FUNCTION
(
"napiCreateThreadsafeFunction"
,
napiCreateThreadsafeFunction
),
DECLARE_NAPI_FUNCTION
(
"napiRefthreadSafeFunction"
,
napiRefthreadSafeFunction
),
DECLARE_NAPI_FUNCTION
(
"napiCreateDate"
,
napiCreateDate
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintUint64"
,
napiCreateBigintUint64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintInt64"
,
napiCreateBigintInt64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintWords"
,
napiCreateBigintWords
),
{
"napiCancelAsyncWork"
,
nullptr
,
napiCancelAsyncWork
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"napiCreateFunction"
,
nullptr
,
napiCreateFunction
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
DECLARE_NAPI_FUNCTION
(
"napiFatalerror"
,
napiFatalerror
),
};
NAPI_CALL
(
env
,
napi_define_properties
(
env
,
exports
,
sizeof
(
properties
)
/
sizeof
(
properties
[
0
]),
properties
));
return
exports
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录