mirror of
https://github.com/openharmony/arkXtest.git
synced 2026-07-19 02:06:41 -04:00
check null input for get_string_value. Signed-off-by: <wanglongjin1@huawei.com>
This commit is contained in:
@@ -50,6 +50,14 @@ namespace OHOS::uitest {
|
||||
/** Convert js string to cpp string.*/
|
||||
static string JsStrToCppStr(napi_env env, napi_value jsStr)
|
||||
{
|
||||
if (jsStr == nullptr) {
|
||||
return "";
|
||||
}
|
||||
napi_valuetype type;
|
||||
NAPI_CALL_BASE(env, napi_typeof(env, jsStr, &type), "");
|
||||
if (type == napi_undefined || type == napi_null) {
|
||||
return "";
|
||||
}
|
||||
size_t bufSize = 0;
|
||||
char buf[NAPI_MAX_BUF_LEN] = {0};
|
||||
NAPI_CALL_BASE(env, napi_get_value_string_utf8(env, jsStr, buf, NAPI_MAX_BUF_LEN, &bufSize), "");
|
||||
|
||||
Reference in New Issue
Block a user