mirror of
https://github.com/openharmony/js_util_module.git
synced 2026-07-19 18:23:35 -04:00
!116 master主干代码同步到release3.1分支
Merge pull request !116 from xllify/OpenHarmony-3.1-Release
This commit is contained in:
+34
-38
@@ -36,10 +36,9 @@ namespace OHOS::Util {
|
||||
121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47, 61
|
||||
};
|
||||
}
|
||||
Base64::Base64(napi_env env_) : env(env_) {}
|
||||
|
||||
/* base64 encode */
|
||||
napi_value Base64::EncodeSync(napi_value src)
|
||||
napi_value Base64::EncodeSync(napi_env env, napi_value src)
|
||||
{
|
||||
napi_typedarray_type type;
|
||||
size_t byteOffset = 0;
|
||||
@@ -68,7 +67,7 @@ namespace OHOS::Util {
|
||||
}
|
||||
|
||||
/* base64 encodeToString */
|
||||
napi_value Base64::EncodeToStringSync(napi_value src)
|
||||
napi_value Base64::EncodeToStringSync(napi_env env, napi_value src)
|
||||
{
|
||||
napi_typedarray_type type;
|
||||
size_t byteOffset = 0;
|
||||
@@ -79,11 +78,14 @@ namespace OHOS::Util {
|
||||
inputEncode_ = static_cast<const unsigned char*>(resultData) + byteOffset;
|
||||
unsigned char *ret = EncodeAchieve(inputEncode_, length);
|
||||
if (ret == nullptr) {
|
||||
FreeMemory(ret);
|
||||
napi_throw_error(env, "-1", "encodeToString input is null");
|
||||
}
|
||||
const char *encString = reinterpret_cast<const char*>(ret);
|
||||
napi_value resultStr = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, encString, strlen(encString), &resultStr));
|
||||
if (strlen(encString) != 0) {
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, encString, strlen(encString), &resultStr));
|
||||
}
|
||||
FreeMemory(ret);
|
||||
return resultStr;
|
||||
}
|
||||
@@ -138,7 +140,7 @@ namespace OHOS::Util {
|
||||
}
|
||||
|
||||
/* base64 decode */
|
||||
napi_value Base64::DecodeSync(napi_value src)
|
||||
napi_value Base64::DecodeSync(napi_env env, napi_value src)
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_typeof(env, src, &valuetype);
|
||||
@@ -165,11 +167,11 @@ namespace OHOS::Util {
|
||||
}
|
||||
if (inputString != nullptr) {
|
||||
napi_get_value_string_utf8(env, src, inputString, prolen + 1, &prolen);
|
||||
pret = DecodeAchieve(inputString, prolen);
|
||||
pret = DecodeAchieve(env, inputString, prolen);
|
||||
}
|
||||
} else if (type == napi_typedarray_type::napi_uint8_array) {
|
||||
inputDecode_ = static_cast<const char*>(resultData) + byteOffset;
|
||||
pret = DecodeAchieve(inputDecode_, length);
|
||||
pret = DecodeAchieve(env, inputDecode_, length);
|
||||
}
|
||||
void *data = nullptr;
|
||||
napi_value arrayBuffer = nullptr;
|
||||
@@ -188,7 +190,7 @@ namespace OHOS::Util {
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned char *Base64::DecodeAchieve(const char *input, size_t inputLen)
|
||||
unsigned char *Base64::DecodeAchieve(napi_env env, const char *input, size_t inputLen)
|
||||
{
|
||||
retLen = (inputLen / TRAGET_FOUR) * TRAGET_THREE;
|
||||
decodeOutLen = retLen;
|
||||
@@ -281,22 +283,7 @@ namespace OHOS::Util {
|
||||
return couts;
|
||||
}
|
||||
|
||||
/* Memory cleanup function */
|
||||
void Base64::FreeMemory(unsigned char *address)
|
||||
{
|
||||
if (address != nullptr) {
|
||||
delete[] address;
|
||||
address = nullptr;
|
||||
}
|
||||
}
|
||||
void Base64::FreeMemory(char *address)
|
||||
{
|
||||
if (address != nullptr) {
|
||||
delete[] address;
|
||||
address = nullptr;
|
||||
}
|
||||
}
|
||||
napi_value Base64::Encode(napi_value src)
|
||||
napi_value Base64::Encode(napi_env env, napi_value src)
|
||||
{
|
||||
napi_typedarray_type type;
|
||||
size_t byteOffset = 0;
|
||||
@@ -306,10 +293,10 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, src, &type, &length, &resultData, &resultBuffer, &byteOffset));
|
||||
unsigned char *inputEncode = nullptr;
|
||||
inputEncode = static_cast<unsigned char*>(resultData) + byteOffset;
|
||||
CreateEncodePromise(inputEncode, length);
|
||||
CreateEncodePromise(env, inputEncode, length);
|
||||
return stdEncodeInfo_->promise;
|
||||
}
|
||||
napi_value Base64::EncodeToString(napi_value src)
|
||||
napi_value Base64::EncodeToString(napi_env env, napi_value src)
|
||||
{
|
||||
napi_typedarray_type type;
|
||||
size_t byteOffset = 0;
|
||||
@@ -319,10 +306,10 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, src, &type, &length, &resultData, &resultBuffer, &byteOffset));
|
||||
unsigned char *inputEncode = nullptr;
|
||||
inputEncode = static_cast<unsigned char*>(resultData) + byteOffset;
|
||||
CreateEncodeToStringPromise(inputEncode, length);
|
||||
CreateEncodeToStringPromise(env, inputEncode, length);
|
||||
return stdEncodeInfo_->promise;
|
||||
}
|
||||
void Base64::CreateEncodePromise(unsigned char *inputDecode, size_t length)
|
||||
void Base64::CreateEncodePromise(napi_env env, unsigned char *inputDecode, size_t length)
|
||||
{
|
||||
napi_value resourceName = nullptr;
|
||||
stdEncodeInfo_ = new EncodeInfo();
|
||||
@@ -335,7 +322,7 @@ namespace OHOS::Util {
|
||||
reinterpret_cast<void*>(stdEncodeInfo_), &stdEncodeInfo_->worker);
|
||||
napi_queue_async_work(env, stdEncodeInfo_->worker);
|
||||
}
|
||||
void Base64::CreateEncodeToStringPromise(unsigned char *inputDecode, size_t length)
|
||||
void Base64::CreateEncodeToStringPromise(napi_env env, unsigned char *inputDecode, size_t length)
|
||||
{
|
||||
napi_value resourceName = nullptr;
|
||||
stdEncodeInfo_ = new EncodeInfo();
|
||||
@@ -347,7 +334,7 @@ namespace OHOS::Util {
|
||||
reinterpret_cast<void*>(stdEncodeInfo_), &stdEncodeInfo_->worker);
|
||||
napi_queue_async_work(env, stdEncodeInfo_->worker);
|
||||
}
|
||||
unsigned char *EncodeAchieves(EncodeInfo *encodeInfo)
|
||||
unsigned char *EncodeAchieves(napi_env env, EncodeInfo *encodeInfo)
|
||||
{
|
||||
const unsigned char *input = encodeInfo->sinputEncode;
|
||||
size_t inputLen = encodeInfo->slength;
|
||||
@@ -400,7 +387,7 @@ namespace OHOS::Util {
|
||||
void Base64::ReadStdEncode(napi_env env, void *data)
|
||||
{
|
||||
auto stdEncodeInfo = reinterpret_cast<EncodeInfo*>(data);
|
||||
unsigned char *rets = EncodeAchieves(stdEncodeInfo);
|
||||
unsigned char *rets = EncodeAchieves(env, stdEncodeInfo);
|
||||
stdEncodeInfo->sinputEncoding = rets;
|
||||
}
|
||||
void Base64::EndStdEncode(napi_env env, napi_status status, void *buffer)
|
||||
@@ -426,7 +413,7 @@ namespace OHOS::Util {
|
||||
void Base64::ReadStdEncodeToString(napi_env env, void *data)
|
||||
{
|
||||
auto stdEncodeInfo = reinterpret_cast<EncodeInfo*>(data);
|
||||
unsigned char *rets = EncodeAchieves(stdEncodeInfo);
|
||||
unsigned char *rets = EncodeAchieves(env, stdEncodeInfo);
|
||||
stdEncodeInfo->sinputEncoding = rets;
|
||||
}
|
||||
void Base64::EndStdEncodeToString(napi_env env, napi_status status, void *buffer)
|
||||
@@ -440,7 +427,7 @@ namespace OHOS::Util {
|
||||
delete[] stdEncodeInfo->sinputEncoding;
|
||||
delete stdEncodeInfo;
|
||||
}
|
||||
napi_value Base64::Decode(napi_value src)
|
||||
napi_value Base64::Decode(napi_env env, napi_value src)
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_typeof(env, src, &valuetype);
|
||||
@@ -466,15 +453,16 @@ namespace OHOS::Util {
|
||||
napi_throw_error(env, "-2", "prolen is error !");
|
||||
}
|
||||
napi_get_value_string_utf8(env, src, inputString, prolen + 1, &prolen);
|
||||
CreateDecodePromise(inputString, prolen);
|
||||
CreateDecodePromise(env, inputString, prolen);
|
||||
} else if (type == napi_typedarray_type::napi_uint8_array) {
|
||||
inputDecode = static_cast<char*>(resultData) + byteOffset;
|
||||
CreateDecodePromise(inputDecode, length);
|
||||
CreateDecodePromise(env, inputDecode, length);
|
||||
}
|
||||
delete[] inputString;
|
||||
inputString = nullptr;
|
||||
return stdDecodeInfo_->promise;
|
||||
}
|
||||
void Base64::CreateDecodePromise(char *inputDecode, size_t length)
|
||||
void Base64::CreateDecodePromise(napi_env env, char *inputDecode, size_t length)
|
||||
{
|
||||
napi_value resourceName = nullptr;
|
||||
stdDecodeInfo_ = new DecodeInfo();
|
||||
@@ -521,7 +509,7 @@ namespace OHOS::Util {
|
||||
}
|
||||
return retLen;
|
||||
}
|
||||
unsigned char *DecodeAchieves(DecodeInfo *decodeInfo)
|
||||
unsigned char *DecodeAchieves(napi_env env, DecodeInfo *decodeInfo)
|
||||
{
|
||||
const char *input = decodeInfo->sinputDecode;
|
||||
size_t inputLen = decodeInfo->slength;
|
||||
@@ -575,7 +563,7 @@ namespace OHOS::Util {
|
||||
void Base64::ReadStdDecode(napi_env env, void *data)
|
||||
{
|
||||
auto stdDecodeInfo = reinterpret_cast<DecodeInfo*>(data);
|
||||
unsigned char *rets = DecodeAchieves(stdDecodeInfo);
|
||||
unsigned char *rets = DecodeAchieves(env, stdDecodeInfo);
|
||||
stdDecodeInfo->sinputDecoding = rets;
|
||||
}
|
||||
void Base64::EndStdDecode(napi_env env, napi_status status, void *buffer)
|
||||
@@ -599,6 +587,14 @@ namespace OHOS::Util {
|
||||
delete stdDecodeInfo;
|
||||
}
|
||||
|
||||
/* Memory cleanup function */
|
||||
void FreeMemory(char *address)
|
||||
{
|
||||
if (address != nullptr) {
|
||||
delete[] address;
|
||||
address = nullptr;
|
||||
}
|
||||
}
|
||||
void FreeMemory(unsigned char *address)
|
||||
{
|
||||
if (address != nullptr) {
|
||||
|
||||
+67
-17
@@ -19,8 +19,8 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#ifndef BASE_COMPILERUNTIME_JS_UTIL_MODULE_BASE64_CLASS_H
|
||||
#define BASE_COMPILERUNTIME_JS_UTIL_MODULE_BASE64_CLASS_H
|
||||
#ifndef UTIL_JS_BASE64_H_
|
||||
#define UTIL_JS_BASE64_H_
|
||||
|
||||
namespace OHOS::Util {
|
||||
struct EncodeInfo {
|
||||
@@ -51,27 +51,77 @@ namespace OHOS::Util {
|
||||
SIXTEEN_FLG = 0x3F,
|
||||
XFF_FLG = 0xFF,
|
||||
};
|
||||
|
||||
void FreeMemory(unsigned char *address);
|
||||
void FreeMemory(char *address);
|
||||
unsigned char *EncodeAchieves(EncodeInfo *encodeInfo);
|
||||
unsigned char *DecodeAchieves(DecodeInfo *decodeInfo);
|
||||
|
||||
class Base64 {
|
||||
public:
|
||||
explicit Base64(napi_env env);
|
||||
/**
|
||||
* Constructor of Base64.
|
||||
*/
|
||||
explicit Base64() {}
|
||||
|
||||
/**
|
||||
* Destructor of Base64.
|
||||
*/
|
||||
virtual ~Base64() {}
|
||||
napi_value EncodeSync(napi_value src);
|
||||
napi_value EncodeToStringSync(napi_value src);
|
||||
napi_value DecodeSync(napi_value src);
|
||||
napi_value Encode(napi_value src);
|
||||
napi_value EncodeToString(napi_value src);
|
||||
napi_value Decode(napi_value src);
|
||||
|
||||
/**
|
||||
* Output the corresponding text after encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Encode the input uint8 array.
|
||||
*/
|
||||
napi_value EncodeSync(napi_env env, napi_value src);
|
||||
|
||||
/**
|
||||
* Output the corresponding text after encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Encode the input uint8 array.
|
||||
*/
|
||||
napi_value EncodeToStringSync(napi_env env, napi_value src);
|
||||
|
||||
/**
|
||||
* Output the corresponding text after encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Decode the input uint8 array or string.
|
||||
*/
|
||||
napi_value DecodeSync(napi_env env, napi_value src);
|
||||
|
||||
/**
|
||||
* Output the corresponding text after asynchronously encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Asynchronously encoded input uint8 array.
|
||||
*/
|
||||
napi_value Encode(napi_env env, napi_value src);
|
||||
|
||||
/**
|
||||
* Output the corresponding text after asynchronously encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Asynchronously encoded input uint8 array.
|
||||
*/
|
||||
napi_value EncodeToString(napi_env env, napi_value src);
|
||||
|
||||
/**
|
||||
* Output the corresponding text after asynchronously encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Asynchronously decode the input uint8 array or string.
|
||||
*/
|
||||
napi_value Decode(napi_env env, napi_value src);
|
||||
|
||||
private:
|
||||
napi_env env;
|
||||
unsigned char *DecodeAchieve(const char *input, size_t inputLen);
|
||||
unsigned char *DecodeAchieve(napi_env env, const char *input, size_t inputLen);
|
||||
unsigned char *EncodeAchieve(const unsigned char *input, size_t inputLen);
|
||||
size_t Finds(char ch);
|
||||
size_t DecodeOut(size_t equalCount, size_t retLen);
|
||||
void FreeMemory(unsigned char *address);
|
||||
void FreeMemory(char *address);
|
||||
size_t retLen = 0;
|
||||
size_t decodeOutLen = 0;
|
||||
size_t outputLen = 0;
|
||||
@@ -79,9 +129,9 @@ namespace OHOS::Util {
|
||||
const unsigned char *inputEncode_ = nullptr;
|
||||
const char *inputDecode_ = nullptr;
|
||||
unsigned char *retDecode = nullptr;
|
||||
void CreateEncodePromise(unsigned char *inputDecode, size_t length);
|
||||
void CreateEncodeToStringPromise(unsigned char *inputDecode, size_t length);
|
||||
void CreateDecodePromise(char *inputDecode, size_t length);
|
||||
void CreateEncodePromise(napi_env env, unsigned char *inputDecode, size_t length);
|
||||
void CreateEncodeToStringPromise(napi_env env, unsigned char *inputDecode, size_t length);
|
||||
void CreateDecodePromise(napi_env env, char *inputDecode, size_t length);
|
||||
EncodeInfo *stdEncodeInfo_ = nullptr;
|
||||
DecodeInfo *stdDecodeInfo_ = nullptr;
|
||||
static void ReadStdEncode(napi_env env, void *data);
|
||||
@@ -92,4 +142,4 @@ namespace OHOS::Util {
|
||||
static void EndStdDecode(napi_env env, napi_status status, void *buffer);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#endif // UTIL_JS_BASE64_H_
|
||||
|
||||
+16
-16
@@ -26,8 +26,8 @@
|
||||
#include "unicode/unistr.h"
|
||||
#include "utils/log.h"
|
||||
namespace OHOS::Util {
|
||||
TextDecoder::TextDecoder(napi_env env, std::string buff, std::vector<int> optionVec)
|
||||
: env_(env), label_(0), encStr_(buff), tranTool_(nullptr, nullptr)
|
||||
TextDecoder::TextDecoder(std::string buff, std::vector<int> optionVec)
|
||||
: label_(0), encStr_(buff), tranTool_(nullptr, nullptr)
|
||||
{
|
||||
uint32_t i32Flag = 0;
|
||||
if (optionVec.size() == 2) { // 2:Meaning of optionVec size 2
|
||||
@@ -59,18 +59,18 @@ namespace OHOS::Util {
|
||||
}
|
||||
|
||||
|
||||
napi_value TextDecoder::Decode(napi_value src, bool iflag)
|
||||
napi_value TextDecoder::Decode(napi_env env, napi_value src, bool iflag)
|
||||
{
|
||||
uint32_t flags = 0;
|
||||
flags |= (iflag ? 0 : static_cast<uint32_t>(ConverterFlags::FLUSH_FLG));
|
||||
UBool flush = ((flags & static_cast<uint32_t>(ConverterFlags::FLUSH_FLG))) ==
|
||||
static_cast<uint32_t>(ConverterFlags::FLUSH_FLG);
|
||||
uint8_t flags = 0;
|
||||
flags |= (iflag ? 0 : static_cast<uint8_t>(ConverterFlags::FLUSH_FLG));
|
||||
UBool flush = ((flags & static_cast<uint8_t>(ConverterFlags::FLUSH_FLG))) ==
|
||||
static_cast<uint8_t>(ConverterFlags::FLUSH_FLG);
|
||||
napi_typedarray_type type;
|
||||
size_t length = 0;
|
||||
void *data1 = nullptr;
|
||||
size_t byteOffset = 0;
|
||||
napi_value arrayBuffer = nullptr;
|
||||
NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &data1, &arrayBuffer, &byteOffset));
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, src, &type, &length, &data1, &arrayBuffer, &byteOffset));
|
||||
const char *source = static_cast<char*>(data1);
|
||||
UErrorCode codeFlag = U_ZERO_ERROR;
|
||||
size_t limit = GetMinByteSize() * length;
|
||||
@@ -101,7 +101,7 @@ namespace OHOS::Util {
|
||||
std::u16string tempStr16(arrDat);
|
||||
std::string tepStr = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(tempStr16);
|
||||
napi_value resultStr = nullptr;
|
||||
NAPI_CALL(env_, napi_create_string_utf8(env_, tepStr.c_str(), tepStr.size(), &resultStr));
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, tepStr.c_str(), tepStr.size(), &resultStr));
|
||||
FreedMemory(arr);
|
||||
if (flush) {
|
||||
label_ &= static_cast<uint32_t>(ConverterFlags::BOM_SEEN_FLG);
|
||||
@@ -110,15 +110,15 @@ namespace OHOS::Util {
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
napi_value TextDecoder::GetEncoding() const
|
||||
napi_value TextDecoder::GetEncoding(napi_env env) const
|
||||
{
|
||||
size_t length = strlen(encStr_.c_str());
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env_, napi_create_string_utf8(env_, encStr_.c_str(), length, &result));
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, encStr_.c_str(), length, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value TextDecoder::GetFatal() const
|
||||
napi_value TextDecoder::GetFatal(napi_env env) const
|
||||
{
|
||||
uint32_t temp = label_ & static_cast<uint32_t>(ConverterFlags::FATAL_FLG);
|
||||
bool comRst = false;
|
||||
@@ -128,11 +128,11 @@ namespace OHOS::Util {
|
||||
comRst = false;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env_, napi_get_boolean(env_, comRst, &result));
|
||||
NAPI_CALL(env, napi_get_boolean(env, comRst, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value TextDecoder::GetIgnoreBOM() const
|
||||
napi_value TextDecoder::GetIgnoreBOM(napi_env env) const
|
||||
{
|
||||
uint32_t temp = label_ & static_cast<uint32_t>(ConverterFlags::IGNORE_BOM_FLG);
|
||||
bool comRst = false;
|
||||
@@ -142,7 +142,7 @@ namespace OHOS::Util {
|
||||
comRst = false;
|
||||
}
|
||||
napi_value result;
|
||||
NAPI_CALL(env_, napi_get_boolean(env_, comRst, &result));
|
||||
NAPI_CALL(env, napi_get_boolean(env, comRst, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace OHOS::Util {
|
||||
if (tranTool_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
size_t res = ucnv_getMinCharSize(tranTool_.get());
|
||||
size_t res = static_cast<size_t>(ucnv_getMinCharSize(tranTool_.get()));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
+74
-9
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTDECODER_H
|
||||
#define FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTDECODER_H
|
||||
#ifndef UTIL_JS_TEXTDECODER_H_
|
||||
#define UTIL_JS_TEXTDECODER_H_
|
||||
|
||||
#include <memory.h>
|
||||
#include <string>
|
||||
@@ -46,19 +46,72 @@ namespace OHOS::Util {
|
||||
UNICODE_FLG = 0x8,
|
||||
BOM_SEEN_FLG = 0x10,
|
||||
};
|
||||
|
||||
public:
|
||||
TextDecoder(napi_env env, std::string buff, std::vector<int> optionVec);
|
||||
/**
|
||||
* Constructor of textdecoder
|
||||
*
|
||||
* @param buff Encoding format.
|
||||
* @param optionVec There are two attributes of code related option parameters: fatal and ignorebom.
|
||||
*/
|
||||
TextDecoder(std::string buff, std::vector<int> optionVec);
|
||||
|
||||
/**
|
||||
* Destructor of textencoder.
|
||||
*/
|
||||
virtual ~TextDecoder() {}
|
||||
napi_value Decode(napi_value src, bool iflag);
|
||||
napi_value GetEncoding() const;
|
||||
napi_value GetFatal() const;
|
||||
napi_value GetIgnoreBOM() const;
|
||||
|
||||
/**
|
||||
* Destructor of textencoder.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src An array that matches the format and needs to be decoded.
|
||||
* @param iflag Decoding related option parameters.
|
||||
*/
|
||||
napi_value Decode(napi_env env, napi_value src, bool iflag);
|
||||
|
||||
/**
|
||||
* Get encoding format.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetEncoding(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Gets the setting of the exception thrown.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetFatal(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Gets whether to ignore the setting of BOM flag.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetIgnoreBOM(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Gets the size of minimum byte.
|
||||
*/
|
||||
size_t GetMinByteSize() const;
|
||||
|
||||
/**
|
||||
* Reset function.
|
||||
*/
|
||||
void Reset() const;
|
||||
|
||||
/**
|
||||
* Gets the pointer to the converter.
|
||||
*/
|
||||
UConverter *GetConverterPtr() const
|
||||
{
|
||||
return tranTool_.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether it is the flag of BOM.
|
||||
*/
|
||||
bool IsBomFlag() const
|
||||
{
|
||||
uint32_t temp = label_ & static_cast<uint32_t>(ConverterFlags::BOM_SEEN_FLG);
|
||||
@@ -68,6 +121,10 @@ namespace OHOS::Util {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether it is Unicode.
|
||||
*/
|
||||
bool IsUnicode() const
|
||||
{
|
||||
uint32_t temp = label_ & static_cast<uint32_t>(ConverterFlags::UNICODE_FLG);
|
||||
@@ -77,6 +134,10 @@ namespace OHOS::Util {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether it is an ignored BOM.
|
||||
*/
|
||||
bool IsIgnoreBom() const
|
||||
{
|
||||
uint32_t temp = label_ & static_cast<uint32_t>(ConverterFlags::IGNORE_BOM_FLG);
|
||||
@@ -86,18 +147,22 @@ namespace OHOS::Util {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the pointer of converter.
|
||||
*/
|
||||
static void ConverterClose(UConverter *pointer)
|
||||
{
|
||||
ucnv_close(pointer);
|
||||
}
|
||||
|
||||
private:
|
||||
void SetBomFlag(const UChar *arr, const UErrorCode codeFlag, const DecodeArr decArr,
|
||||
size_t& rstLen, bool& bomFlag);
|
||||
void FreedMemory(UChar *pData);
|
||||
napi_env env_;
|
||||
uint32_t label_;
|
||||
std::string encStr_;
|
||||
TransformToolPointer tranTool_;
|
||||
};
|
||||
}
|
||||
#endif /* FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTDECODER_H */
|
||||
#endif // UTIL_JS_TEXTDECODER_H_
|
||||
|
||||
+23
-33
@@ -21,79 +21,69 @@
|
||||
#include "securec.h"
|
||||
#include "utils/log.h"
|
||||
namespace OHOS::Util {
|
||||
TextEncoder::TextEncoder(napi_env env) : env_(env), encoding_("utf-8")
|
||||
{
|
||||
}
|
||||
|
||||
napi_value TextEncoder::GetEncoding() const
|
||||
napi_value TextEncoder::GetEncoding(napi_env env) const
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env_, napi_create_string_utf8(env_, encoding_.c_str(), encoding_.length(), &result));
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, encoding_.c_str(), encoding_.length(), &result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value TextEncoder::Encode(napi_value src) const
|
||||
napi_value TextEncoder::Encode(napi_env env, napi_value src) const
|
||||
{
|
||||
char *buffer = nullptr;
|
||||
std::string buffer = "";
|
||||
size_t bufferSize = 0;
|
||||
|
||||
NAPI_CALL(env_, napi_get_value_string_utf8(env_, src, buffer, 0, &bufferSize));
|
||||
NAPI_ASSERT(env_, bufferSize > 0, "bufferSize == 0");
|
||||
buffer = new char[bufferSize + 1];
|
||||
if (memset_s(buffer, bufferSize + 1, 0, bufferSize + 1) != EOK) {
|
||||
HILOG_ERROR("buffer memset error");
|
||||
delete []buffer;
|
||||
if (napi_get_value_string_utf8(env, src, nullptr, 0, &bufferSize) != napi_ok) {
|
||||
HILOG_ERROR("can not get src size");
|
||||
return nullptr;
|
||||
}
|
||||
buffer.reserve(bufferSize + 1);
|
||||
buffer.resize(bufferSize);
|
||||
if (napi_get_value_string_utf8(env, src, buffer.data(), bufferSize + 1, &bufferSize) != napi_ok) {
|
||||
HILOG_ERROR("can not get src value");
|
||||
return nullptr;
|
||||
}
|
||||
napi_get_value_string_utf8(env_, src, buffer, bufferSize + 1, &bufferSize);
|
||||
|
||||
void *data = nullptr;
|
||||
napi_value arrayBuffer = nullptr;
|
||||
napi_create_arraybuffer(env_, bufferSize, &data, &arrayBuffer);
|
||||
if (memcpy_s(data, bufferSize, reinterpret_cast<void*>(buffer), bufferSize) != EOK) {
|
||||
napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer);
|
||||
if (memcpy_s(data, bufferSize, reinterpret_cast<void*>(buffer.data()), bufferSize) != EOK) {
|
||||
HILOG_ERROR("copy buffer to arraybuffer error");
|
||||
delete []buffer;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
delete []buffer;
|
||||
buffer = nullptr;
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env_, napi_create_typedarray(env_, napi_uint8_array, bufferSize, arrayBuffer, 0, &result));
|
||||
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, bufferSize, arrayBuffer, 0, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value TextEncoder::EncodeInto(napi_value src, napi_value dest) const
|
||||
napi_value TextEncoder::EncodeInto(napi_env env, napi_value src, napi_value dest) const
|
||||
{
|
||||
napi_typedarray_type type;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void *resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
NAPI_CALL(env_, napi_get_typedarray_info(env_, dest, &type, &length, &resultData, &resultBuffer, &byteOffset));
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, dest, &type, &length, &resultData, &resultBuffer, &byteOffset));
|
||||
|
||||
char *writeResult = static_cast<char*>(resultData) + byteOffset;
|
||||
|
||||
int32_t nchars = 0;
|
||||
int32_t written = 0;
|
||||
NativeEngine *engine = reinterpret_cast<NativeEngine*>(env_);
|
||||
NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
|
||||
NativeValue *nativeValue = reinterpret_cast<NativeValue*>(src);
|
||||
engine->EncodeToUtf8(nativeValue, writeResult, &written, length, &nchars);
|
||||
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env_, napi_create_object(env_, &result));
|
||||
NAPI_CALL(env, napi_create_object(env, &result));
|
||||
|
||||
napi_value read = nullptr;
|
||||
NAPI_CALL(env_, napi_create_int32(env_, nchars, &read));
|
||||
NAPI_CALL(env, napi_create_int32(env, nchars, &read));
|
||||
|
||||
NAPI_CALL(env_, napi_set_named_property(env_, result, "read", read));
|
||||
NAPI_CALL(env, napi_set_named_property(env, result, "read", read));
|
||||
|
||||
napi_value resWritten = nullptr;
|
||||
NAPI_CALL(env_, napi_create_int32(env_, written, &resWritten));
|
||||
NAPI_CALL(env, napi_create_int32(env, written, &resWritten));
|
||||
|
||||
NAPI_CALL(env_, napi_set_named_property(env_, result, "written", resWritten));
|
||||
NAPI_CALL(env, napi_set_named_property(env, result, "written", resWritten));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+34
-8
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTENCODER_H
|
||||
#define FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTENCODER_H
|
||||
#ifndef UTIL_JS_TEXTENCODER_H_
|
||||
#define UTIL_JS_TEXTENCODER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -23,17 +23,43 @@
|
||||
namespace OHOS::Util {
|
||||
class TextEncoder {
|
||||
public:
|
||||
explicit TextEncoder(napi_env env);
|
||||
/**
|
||||
* Constructor of textdecoder.
|
||||
*
|
||||
*/
|
||||
explicit TextEncoder() : encoding_("utf-8") {}
|
||||
|
||||
/**
|
||||
* Destructor of textencoder.
|
||||
*/
|
||||
virtual ~TextEncoder() {}
|
||||
|
||||
napi_value GetEncoding() const;
|
||||
napi_value Encode(napi_value src) const;
|
||||
napi_value EncodeInto(napi_value src, napi_value dest) const;
|
||||
/**
|
||||
* Get encoding format.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetEncoding(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Output the corresponding text after encoding the input parameters.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src A string that needs to be encoded.
|
||||
*/
|
||||
napi_value Encode(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Place the generated UTF-8 encoded text.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src A string that needs to be encoded.
|
||||
* @param dest Uint8array object instance, which is used to put the generated UTF-8 encoded text into it.
|
||||
*/
|
||||
napi_value EncodeInto(napi_env env, napi_value src, napi_value dest) const;
|
||||
|
||||
private:
|
||||
napi_env env_;
|
||||
std::string encoding_;
|
||||
};
|
||||
}
|
||||
#endif /* FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTENCODER_H */
|
||||
#endif // UTIL_JS_TEXTENCODER_H_
|
||||
|
||||
+139
-141
@@ -20,35 +20,33 @@
|
||||
#include "utils/log.h"
|
||||
|
||||
namespace OHOS::Util {
|
||||
Types::Types(napi_env env) : env_(env) {}
|
||||
|
||||
napi_value Types::IsAnyArrayBuffer(napi_value src) const
|
||||
napi_value Types::IsAnyArrayBuffer(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
bool rstFlag = false;
|
||||
napi_value rst = nullptr;
|
||||
napi_status napiRst = napi_is_arraybuffer(env_, src, &rstFlag);
|
||||
napi_status napiRst = napi_is_arraybuffer(env, src, &rstFlag);
|
||||
if (napiRst == napi_ok && rstFlag) {
|
||||
flag = true;
|
||||
}
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsArrayBufferView(napi_value src) const
|
||||
napi_value Types::IsArrayBufferView(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_value rst = nullptr;
|
||||
bool flag = false;
|
||||
napi_status rstStatus = napi_typeof(env_, src, &valuetype);
|
||||
napi_status rstStatus = napi_typeof(env, src, &valuetype);
|
||||
if ((valuetype != napi_valuetype::napi_object) || (rstStatus != napi_ok)) {
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
bool rstFlag = false;
|
||||
napi_status napiRst = napi_is_dataview(env_, src, &rstFlag);
|
||||
napi_status napiRst = napi_is_dataview(env, src, &rstFlag);
|
||||
if (napiRst == napi_ok && rstFlag) {
|
||||
napi_get_boolean(env_, rstFlag, &rst);
|
||||
napi_get_boolean(env, rstFlag, &rst);
|
||||
return rst;
|
||||
}
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
@@ -56,7 +54,7 @@ namespace OHOS::Util {
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_status rstSta = napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_status rstSta = napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (rstSta == napi_ok) {
|
||||
switch (type) {
|
||||
@@ -76,46 +74,46 @@ namespace OHOS::Util {
|
||||
break;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsArgumentsObject(napi_value src) const
|
||||
napi_value Types::IsArgumentsObject(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype result = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_typeof(env_, src, &result);
|
||||
napi_typeof(env, src, &result);
|
||||
if (result == napi_object) {
|
||||
NAPI_CALL(env_, napi_is_arguments_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_arguments_object(env, src, &flag));
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsArrayBuffer(napi_value src) const
|
||||
napi_value Types::IsArrayBuffer(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_arraybuffer(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_arraybuffer(env, src, &flag));
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsAsyncFunction(napi_value src) const
|
||||
napi_value Types::IsAsyncFunction(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype result = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_typeof(env_, src, &result);
|
||||
napi_typeof(env, src, &result);
|
||||
if (result == napi_function) {
|
||||
NAPI_CALL(env_, napi_is_async_function(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_async_function(env, src, &flag));
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsBigInt64Array(napi_value src) const
|
||||
napi_value Types::IsBigInt64Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
@@ -123,17 +121,17 @@ namespace OHOS::Util {
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
bool flag = false;
|
||||
napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset);
|
||||
napi_get_typedarray_info(env, src, &type, &length, &resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_bigint64_array) {
|
||||
flag = true;
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
HILOG_INFO("The type is not supported!");
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsBigUint64Array(napi_value src) const
|
||||
napi_value Types::IsBigUint64Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
@@ -141,453 +139,453 @@ namespace OHOS::Util {
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
bool flag = false;
|
||||
napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset);
|
||||
napi_get_typedarray_info(env, src, &type, &length, &resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_biguint64_array) {
|
||||
flag = true;
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
HILOG_INFO("The type is not supported!");
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsBooleanObject(napi_value src) const
|
||||
napi_value Types::IsBooleanObject(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype result = napi_undefined;
|
||||
napi_typeof(env_, src, &result);
|
||||
napi_typeof(env, src, &result);
|
||||
bool flag = false;
|
||||
if (result == napi_object) {
|
||||
NAPI_CALL(env_, napi_is_boolean_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_boolean_object(env, src, &flag));
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsBoxedPrimitive(napi_value src) const
|
||||
napi_value Types::IsBoxedPrimitive(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
bool rstNum = false;
|
||||
bool rstStr = false;
|
||||
bool rstBool = false;
|
||||
bool rstSym = false;
|
||||
NAPI_CALL(env_, napi_get_value_bool(env_, IsNumberObject(src), &rstNum));
|
||||
NAPI_CALL(env_, napi_get_value_bool(env_, IsStringObject(src), &rstStr));
|
||||
NAPI_CALL(env_, napi_get_value_bool(env_, IsBooleanObject(src), &rstBool));
|
||||
NAPI_CALL(env_, napi_get_value_bool(env_, IsSymbolObject(src), &rstSym));
|
||||
NAPI_CALL(env, napi_get_value_bool(env, IsNumberObject(env, src), &rstNum));
|
||||
NAPI_CALL(env, napi_get_value_bool(env, IsStringObject(env, src), &rstStr));
|
||||
NAPI_CALL(env, napi_get_value_bool(env, IsBooleanObject(env, src), &rstBool));
|
||||
NAPI_CALL(env, napi_get_value_bool(env, IsSymbolObject(env, src), &rstSym));
|
||||
if (rstNum || rstStr || rstBool || rstSym) {
|
||||
flag = true;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsDataView(napi_value src) const
|
||||
napi_value Types::IsDataView(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_dataview(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_dataview(env, src, &flag));
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsDate(napi_value src) const
|
||||
napi_value Types::IsDate(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_date(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_date(env, src, &flag));
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsExternal(napi_value src) const
|
||||
napi_value Types::IsExternal(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype type = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_typeof(env_, src, &type);
|
||||
napi_typeof(env, src, &type);
|
||||
if (type == napi_valuetype::napi_external) {
|
||||
flag = true;
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsFloat32Array(napi_value src) const
|
||||
napi_value Types::IsFloat32Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_float32_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsFloat64Array(napi_value src) const
|
||||
napi_value Types::IsFloat64Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_float64_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsGeneratorFunction(napi_value src) const
|
||||
napi_value Types::IsGeneratorFunction(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype result = napi_undefined;
|
||||
napi_typeof(env_, src, &result);
|
||||
napi_typeof(env, src, &result);
|
||||
bool flag = false;
|
||||
if (result == napi_function) {
|
||||
NAPI_CALL(env_, napi_is_generator_function(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_generator_function(env, src, &flag));
|
||||
}
|
||||
napi_value rst = nullptr;
|
||||
napi_get_boolean(env_, flag, &rst);
|
||||
napi_get_boolean(env, flag, &rst);
|
||||
return rst;
|
||||
}
|
||||
|
||||
napi_value Types::IsGeneratorObject(napi_value src) const
|
||||
napi_value Types::IsGeneratorObject(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_generator_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_generator_object(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsInt8Array(napi_value src) const
|
||||
napi_value Types::IsInt8Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_status rstSta = napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_status rstSta = napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if ((rstSta == napi_ok) && (type == napi_typedarray_type::napi_int8_array)) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsInt16Array(napi_value src) const
|
||||
napi_value Types::IsInt16Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_int16_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsInt32Array(napi_value src) const
|
||||
napi_value Types::IsInt32Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_int32_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsMap(napi_value src) const
|
||||
napi_value Types::IsMap(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_map(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_map(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsMapIterator(napi_value src) const
|
||||
napi_value Types::IsMapIterator(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_map_iterator(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_map_iterator(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsModuleNamespaceObject(napi_value src) const
|
||||
napi_value Types::IsModuleNamespaceObject(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_module_namespace_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_module_namespace_object(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
HILOG_INFO("The type is not supported!");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsNativeError(napi_value src) const
|
||||
napi_value Types::IsNativeError(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_error(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_error(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsNumberObject(napi_value src) const
|
||||
napi_value Types::IsNumberObject(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
NAPI_CALL(env_, napi_is_number_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_number_object(env, src, &flag));
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsPromise(napi_value src) const
|
||||
napi_value Types::IsPromise(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_promise(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_promise(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsProxy(napi_value src) const
|
||||
napi_value Types::IsProxy(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_proxy(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_proxy(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsRegExp(napi_value src) const
|
||||
napi_value Types::IsRegExp(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_reg_exp(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_reg_exp(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsSet(napi_value src) const
|
||||
napi_value Types::IsSet(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_set(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_set(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsSetIterator(napi_value src) const
|
||||
napi_value Types::IsSetIterator(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_set_iterator(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_set_iterator(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsSharedArrayBuffer(napi_value src) const
|
||||
napi_value Types::IsSharedArrayBuffer(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
HILOG_INFO("The type is not supported!");
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsStringObject(napi_value src) const
|
||||
napi_value Types::IsStringObject(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
NAPI_CALL(env_, napi_is_string_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_string_object(env, src, &flag));
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsSymbolObject(napi_value src) const
|
||||
napi_value Types::IsSymbolObject(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
NAPI_CALL(env_, napi_is_symbol_object(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_symbol_object(env, src, &flag));
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsTypedArray(napi_value src) const
|
||||
napi_value Types::IsTypedArray(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_typedarray(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_typedarray(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsUint8Array(napi_value src) const
|
||||
napi_value Types::IsUint8Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_uint8_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsUint8ClampedArray(napi_value src) const
|
||||
napi_value Types::IsUint8ClampedArray(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_uint8_clamped_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsUint16Array(napi_value src) const
|
||||
napi_value Types::IsUint16Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_uint16_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsUint32Array(napi_value src) const
|
||||
napi_value Types::IsUint32Array(napi_env env, napi_value src) const
|
||||
{
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
bool flag = false;
|
||||
napi_value result = nullptr;
|
||||
napi_typeof(env_, src, &valuetype);
|
||||
napi_typeof(env, src, &valuetype);
|
||||
if (valuetype == napi_valuetype::napi_object) {
|
||||
napi_typedarray_type type = napi_int8_array;
|
||||
size_t byteOffset = 0;
|
||||
size_t length = 0;
|
||||
void* resultData = nullptr;
|
||||
napi_value resultBuffer = nullptr;
|
||||
napi_get_typedarray_info(env_, src, &type, &length,
|
||||
napi_get_typedarray_info(env, src, &type, &length,
|
||||
&resultData, &resultBuffer, &byteOffset);
|
||||
if (type == napi_typedarray_type::napi_uint32_array) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsWeakMap(napi_value src) const
|
||||
napi_value Types::IsWeakMap(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_weak_map(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_weak_map(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Types::IsWeakSet(napi_value src) const
|
||||
napi_value Types::IsWeakSet(napi_env env, napi_value src) const
|
||||
{
|
||||
bool flag = false;
|
||||
NAPI_CALL(env_, napi_is_weak_set(env_, src, &flag));
|
||||
NAPI_CALL(env, napi_is_weak_set(env, src, &flag));
|
||||
napi_value result = nullptr;
|
||||
napi_get_boolean(env_, flag, &result);
|
||||
napi_get_boolean(env, flag, &result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+324
-45
@@ -21,55 +21,334 @@
|
||||
#include "napi/native_node_api.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
#ifndef BASE_COMPILERUNTIME_JS_UTIL_MODULE_TYPES_CLASS_H
|
||||
#define BASE_COMPILERUNTIME_JS_UTIL_MODULE_TYPES_CLASS_H
|
||||
#ifndef UTIL_JS_TYPES_H_
|
||||
#define UTIL_JS_TYPES_H_
|
||||
|
||||
namespace OHOS::Util {
|
||||
class Types {
|
||||
public:
|
||||
explicit Types(napi_env env);
|
||||
/**
|
||||
* Constructor of Types.
|
||||
*
|
||||
*/
|
||||
explicit Types() {}
|
||||
|
||||
/**
|
||||
* Destructor of Types.
|
||||
*/
|
||||
virtual ~Types() {}
|
||||
napi_value IsAnyArrayBuffer(napi_value src) const;
|
||||
napi_value IsArrayBufferView(napi_value src) const;
|
||||
napi_value IsArgumentsObject(napi_value src) const;
|
||||
napi_value IsArrayBuffer(napi_value src) const;
|
||||
napi_value IsAsyncFunction(napi_value src) const;
|
||||
napi_value IsBigInt64Array(napi_value src) const;
|
||||
napi_value IsBigUint64Array(napi_value src) const;
|
||||
napi_value IsBooleanObject(napi_value src) const;
|
||||
napi_value IsBoxedPrimitive(napi_value src) const;
|
||||
napi_value IsDataView(napi_value src) const;
|
||||
napi_value IsDate(napi_value src) const;
|
||||
napi_value IsExternal(napi_value src) const;
|
||||
napi_value IsFloat32Array(napi_value src) const;
|
||||
napi_value IsFloat64Array(napi_value src) const;
|
||||
napi_value IsGeneratorFunction(napi_value src) const;
|
||||
napi_value IsGeneratorObject(napi_value src) const;
|
||||
napi_value IsInt8Array(napi_value src) const;
|
||||
napi_value IsInt16Array(napi_value src) const;
|
||||
napi_value IsInt32Array(napi_value src) const;
|
||||
napi_value IsMap(napi_value src) const;
|
||||
napi_value IsMapIterator(napi_value src) const;
|
||||
napi_value IsModuleNamespaceObject(napi_value src) const;
|
||||
napi_value IsNativeError(napi_value src) const;
|
||||
napi_value IsNumberObject(napi_value src) const;
|
||||
napi_value IsPromise(napi_value src) const;
|
||||
napi_value IsProxy(napi_value src) const;
|
||||
napi_value IsRegExp(napi_value src) const;
|
||||
napi_value IsSet(napi_value src) const;
|
||||
napi_value IsSetIterator(napi_value src) const;
|
||||
napi_value IsSharedArrayBuffer(napi_value src) const;
|
||||
napi_value IsStringObject(napi_value src) const;
|
||||
napi_value IsSymbolObject(napi_value src) const;
|
||||
napi_value IsTypedArray(napi_value src) const;
|
||||
napi_value IsUint8Array(napi_value src) const;
|
||||
napi_value IsUint8ClampedArray(napi_value src) const;
|
||||
napi_value IsUint16Array(napi_value src) const;
|
||||
napi_value IsUint32Array(napi_value src) const;
|
||||
napi_value IsWeakMap(napi_value src) const;
|
||||
napi_value IsWeakSet(napi_value src) const;
|
||||
private:
|
||||
napi_env env_;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is of arraybuffer type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsAnyArrayBuffer(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is a built-in arraybufferview auxiliary type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsArrayBufferView(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is an arguments object type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsArgumentsObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is of arraybuffer type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsArrayBuffer(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the input value is an asynchronous function type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsAsyncFunction(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is a bigint64array type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsBigInt64Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is a biguint64array type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsBigUint64Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is a Boolean object type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsBooleanObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is Boolean or number or string or symbol object type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsBoxedPrimitive(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is of DataView type.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsDataView(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is of type date.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsDate(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is of type native external.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsExternal(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of float32array array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsFloat32Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of float64array array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsFloat64Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the value entered is the type of generator function.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsGeneratorFunction(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the value entered is the type of generator object.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsGeneratorObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the value entered is the type of int8 array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsInt8Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the value entered is the type of int16 array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsInt16Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the value entered is the type of int32 array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsInt32Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the value entered is the type of map.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsMap(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the iterator type of map.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsMapIterator(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the module name space type of object.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsModuleNamespaceObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is of type error.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsNativeError(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the number type of object.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsNumberObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of promise.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsPromise(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of proxy.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsProxy(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of regexp.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsRegExp(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of set.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsSet(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the iterator type of set.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsSetIterator(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of sharedarraybuffer.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsSharedArrayBuffer(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the string type of object.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsStringObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the symbol type of object.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsSymbolObject(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of typedarray.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsTypedArray(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of uint8array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsUint8Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of uint8clampedarray.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsUint8ClampedArray(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of uint16array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsUint16Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of uint32array.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsUint32Array(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of weakmap.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsWeakMap(napi_env env, napi_value src) const;
|
||||
|
||||
/**
|
||||
* Check whether the entered value is the type of weakset.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
* @param src Object to be tested.
|
||||
*/
|
||||
napi_value IsWeakSet(napi_env env, napi_value src) const;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#endif // UTIL_JS_TYPES_H_
|
||||
|
||||
+127
-130
@@ -37,7 +37,7 @@ namespace OHOS::Util {
|
||||
return nullptr;
|
||||
}
|
||||
char *type = new char[length + 1];
|
||||
if (memset_s(type, length + 1, '\0', length + 1) != 0) {
|
||||
if (memset_s(type, length + 1, '\0', length + 1) != EOK) {
|
||||
HILOG_ERROR("type memset_s failed");
|
||||
delete[] type;
|
||||
return nullptr;
|
||||
@@ -122,44 +122,32 @@ namespace OHOS::Util {
|
||||
return result;
|
||||
}
|
||||
|
||||
static void FreeMemory(napi_value *address)
|
||||
{
|
||||
delete[] address;
|
||||
address = nullptr;
|
||||
}
|
||||
|
||||
static napi_value DealWithFormatString(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 0;
|
||||
napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr);
|
||||
napi_value *argv = nullptr;
|
||||
if (argc > 0) {
|
||||
argv = new napi_value[argc + 1];
|
||||
if (memset_s(argv, argc + 1, 0, argc + 1) != 0) {
|
||||
HILOG_ERROR("argv memset error");
|
||||
delete []argv;
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
char *format = nullptr;
|
||||
size_t argc = 1;
|
||||
napi_value argv = nullptr;
|
||||
napi_get_cb_info(env, info, &argc, 0, nullptr, nullptr);
|
||||
|
||||
napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr);
|
||||
std::string format = "";
|
||||
size_t formatsize = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &formatsize);
|
||||
if (formatsize > 0) {
|
||||
format = new char[formatsize + 1];
|
||||
if (memset_s(format, formatsize + 1, 0, formatsize + 1) != 0) {
|
||||
HILOG_ERROR("format memset error");
|
||||
delete []format;
|
||||
delete []argv;
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
delete []argv;
|
||||
if (napi_get_value_string_utf8(env, argv, nullptr, 0, &formatsize) != napi_ok) {
|
||||
HILOG_ERROR("can not get argv size");
|
||||
return nullptr;
|
||||
}
|
||||
napi_get_value_string_utf8(env, argv[0], format, formatsize + 1, &formatsize);
|
||||
std::string str = format;
|
||||
delete []format;
|
||||
delete []argv;
|
||||
argv = nullptr;
|
||||
format = nullptr;
|
||||
return FormatString(env, str);
|
||||
format.reserve(formatsize + 1);
|
||||
format.resize(formatsize);
|
||||
if (napi_get_value_string_utf8(env, argv, format.data(), formatsize + 1, &formatsize) != napi_ok) {
|
||||
HILOG_ERROR("can not get argv value");
|
||||
return nullptr;
|
||||
}
|
||||
return FormatString(env, format);
|
||||
}
|
||||
|
||||
static std::string PrintfString(const std::string &format, const std::vector<std::string> &value)
|
||||
@@ -177,33 +165,42 @@ namespace OHOS::Util {
|
||||
if (argc > 0) {
|
||||
argv = new napi_value[argc];
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
char *format = nullptr;
|
||||
std::string format = "";
|
||||
size_t formatsize = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &formatsize);
|
||||
if (formatsize > 0) {
|
||||
format = new char[formatsize + 1];
|
||||
if (napi_get_value_string_utf8(env, argv[0], nullptr, 0, &formatsize) != napi_ok) {
|
||||
HILOG_ERROR("can not get argv[0] size");
|
||||
FreeMemory(argv);
|
||||
return nullptr;
|
||||
}
|
||||
format.reserve(formatsize);
|
||||
format.resize(formatsize);
|
||||
if (napi_get_value_string_utf8(env, argv[0], format.data(), formatsize + 1, &formatsize) != napi_ok) {
|
||||
HILOG_ERROR("can not get argv[0] value");
|
||||
FreeMemory(argv);
|
||||
return nullptr;
|
||||
}
|
||||
napi_get_value_string_utf8(env, argv[0], format, formatsize + 1, &formatsize);
|
||||
std::string printInfo;
|
||||
std::vector<std::string> value;
|
||||
for (size_t i = 1; i < argc; i++) {
|
||||
char *valueString = nullptr;
|
||||
std::string valueString = "";
|
||||
size_t valuesize = 0;
|
||||
napi_get_value_string_utf8(env, argv[i], nullptr, 0, &valuesize);
|
||||
if (valuesize > 0) {
|
||||
valueString = new char[valuesize + 1];
|
||||
if (napi_get_value_string_utf8(env, argv[i], nullptr, 0, &valuesize) != napi_ok) {
|
||||
HILOG_ERROR("can not get argv[i] size");
|
||||
FreeMemory(argv);
|
||||
return nullptr;
|
||||
}
|
||||
napi_get_value_string_utf8(env, argv[i], valueString, valuesize + 1, &valuesize);
|
||||
value.push_back(valueString);
|
||||
delete []valueString;
|
||||
valueString = nullptr;
|
||||
valueString.reserve(valuesize);
|
||||
valueString.resize(valuesize);
|
||||
if (napi_get_value_string_utf8(env, argv[i], valueString.data(),
|
||||
valuesize + 1, &valuesize) != napi_ok) {
|
||||
HILOG_ERROR("can not get argv[i] value");
|
||||
FreeMemory(argv);
|
||||
return nullptr;
|
||||
}
|
||||
value.push_back(valueString.data());
|
||||
}
|
||||
printInfo = PrintfString(format, value);
|
||||
std::string printInfo = PrintfString(format.data(), value);
|
||||
napi_create_string_utf8(env, printInfo.c_str(), printInfo.size(), &result);
|
||||
delete []format;
|
||||
delete []argv;
|
||||
argv = nullptr;
|
||||
format = nullptr;
|
||||
FreeMemory(argv);
|
||||
return result;
|
||||
}
|
||||
napi_value res = nullptr;
|
||||
@@ -292,16 +289,16 @@ namespace OHOS::Util {
|
||||
napi_get_value_string_utf8(env, argv, type, typeLen + 1, &typeLen);
|
||||
} else if (tempArgc == 2) { // 2: The number of parameters is 2.
|
||||
argc = 2; // 2: The number of parameters is 2.
|
||||
napi_value argv[2] = { 0 };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, &data));
|
||||
napi_value argvArr[2] = { 0 };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argvArr, nullptr, &data));
|
||||
// first para
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen));
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, argvArr[0], nullptr, 0, &typeLen));
|
||||
if (typeLen > 0) {
|
||||
type = ApplyMemory(typeLen);
|
||||
}
|
||||
napi_get_value_string_utf8(env, argv[0], type, typeLen + 1, &typeLen);
|
||||
napi_get_value_string_utf8(env, argvArr[0], type, typeLen + 1, &typeLen);
|
||||
// second para
|
||||
GetSecPara(env, argv[1], paraVec);
|
||||
GetSecPara(env, argvArr[1], paraVec);
|
||||
}
|
||||
std::string enconding = "utf-8";
|
||||
if (type != nullptr) {
|
||||
@@ -309,11 +306,11 @@ namespace OHOS::Util {
|
||||
}
|
||||
delete []type;
|
||||
type = nullptr;
|
||||
auto objectInfo = new TextDecoder(env, enconding, paraVec);
|
||||
auto objectInfo = new TextDecoder(enconding, paraVec);
|
||||
NAPI_CALL(env, napi_wrap(
|
||||
env, thisVar, objectInfo,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
auto objInfo = (TextDecoder*)data;
|
||||
[](napi_env environment, void *data, void *hint) {
|
||||
auto objInfo = reinterpret_cast<TextDecoder*>(data);
|
||||
if (objInfo != nullptr) {
|
||||
delete objInfo;
|
||||
}
|
||||
@@ -344,13 +341,13 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, nullptr, &dataPara));
|
||||
// first para
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, argv, &type, &length, &data, &arraybuffer, &byteOffset));
|
||||
valStr = textDecoder->Decode(argv, iStream);
|
||||
valStr = textDecoder->Decode(env, argv, iStream);
|
||||
} else if (tempArgc == 2) { // 2: The number of parameters is 2.
|
||||
argc = 2; // 2: The number of parameters is 2.
|
||||
napi_value argv[2] = { 0 };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, &dataPara));
|
||||
napi_value argvArr[2] = { 0 };
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argvArr, nullptr, &dataPara));
|
||||
// first para
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, argv[0], &type, &length, &data, &arraybuffer, &byteOffset));
|
||||
NAPI_CALL(env, napi_get_typedarray_info(env, argvArr[0], &type, &length, &data, &arraybuffer, &byteOffset));
|
||||
// second para
|
||||
napi_value messageKeyStream = nullptr;
|
||||
const char *messageKeyStrStream = "stream";
|
||||
@@ -358,9 +355,9 @@ namespace OHOS::Util {
|
||||
napi_value resultStream = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, messageKeyStrStream, strlen(messageKeyStrStream),
|
||||
&messageKeyStream));
|
||||
NAPI_CALL(env, napi_get_property(env, argv[1], messageKeyStream, &resultStream));
|
||||
NAPI_CALL(env, napi_get_property(env, argvArr[1], messageKeyStream, &resultStream));
|
||||
NAPI_CALL(env, napi_get_value_bool(env, resultStream, &iStream));
|
||||
valStr = textDecoder->Decode(argv[0], iStream);
|
||||
valStr = textDecoder->Decode(env, argvArr[0], iStream);
|
||||
}
|
||||
return valStr;
|
||||
}
|
||||
@@ -371,7 +368,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
TextDecoder *textDecoder = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&textDecoder));
|
||||
napi_value retVal = textDecoder->GetEncoding();
|
||||
napi_value retVal = textDecoder->GetEncoding(env);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -381,7 +378,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
TextDecoder *textDecoder = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&textDecoder));
|
||||
napi_value retVal = textDecoder->GetFatal();
|
||||
napi_value retVal = textDecoder->GetFatal(env);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -391,7 +388,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
TextDecoder *textDecoder = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&textDecoder));
|
||||
napi_value retVal = textDecoder->GetIgnoreBOM();
|
||||
napi_value retVal = textDecoder->GetIgnoreBOM(env);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -402,11 +399,11 @@ namespace OHOS::Util {
|
||||
void *data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data));
|
||||
|
||||
auto object = new TextEncoder(env);
|
||||
auto object = new TextEncoder();
|
||||
NAPI_CALL(env, napi_wrap(
|
||||
env, thisVar, object,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
auto obj = (TextEncoder*)data;
|
||||
[](napi_env environment, void *data, void *hint) {
|
||||
auto obj = reinterpret_cast<TextEncoder*>(data);
|
||||
if (obj != nullptr) {
|
||||
delete obj;
|
||||
}
|
||||
@@ -423,7 +420,7 @@ namespace OHOS::Util {
|
||||
TextEncoder *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
|
||||
return object->GetEncoding();
|
||||
return object->GetEncoding(env);
|
||||
}
|
||||
|
||||
static napi_value Encode(napi_env env, napi_callback_info info)
|
||||
@@ -444,7 +441,7 @@ namespace OHOS::Util {
|
||||
TextEncoder *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
|
||||
napi_value result = object->Encode(args);
|
||||
napi_value result = object->Encode(env, args);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -475,7 +472,7 @@ namespace OHOS::Util {
|
||||
TextEncoder *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
|
||||
napi_value result = object->EncodeInto(args[0], args[1]);
|
||||
napi_value result = object->EncodeInto(env, args[0], args[1]);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -520,11 +517,11 @@ namespace OHOS::Util {
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data));
|
||||
auto objectInfo = new Base64(env);
|
||||
auto objectInfo = new Base64();
|
||||
napi_wrap(
|
||||
env, thisVar, objectInfo,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
auto objInfo = (Base64*)data;
|
||||
[](napi_env environment, void *data, void *hint) {
|
||||
auto objInfo = reinterpret_cast<Base64*>(data);
|
||||
if (objInfo != nullptr) {
|
||||
delete objInfo;
|
||||
}
|
||||
@@ -550,7 +547,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected.");
|
||||
Base64 *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->EncodeSync(args[0]);
|
||||
napi_value result = object->EncodeSync(env, args[0]);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -571,7 +568,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected.");
|
||||
Base64 *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->EncodeToStringSync(args[0]);
|
||||
napi_value result = object->EncodeToStringSync(env, args[0]);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -599,7 +596,7 @@ namespace OHOS::Util {
|
||||
}
|
||||
Base64 *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->DecodeSync(args[0]);
|
||||
napi_value result = object->DecodeSync(env, args[0]);
|
||||
return result;
|
||||
}
|
||||
static napi_value EncodeAsync(napi_env env, napi_callback_info info)
|
||||
@@ -619,7 +616,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected.");
|
||||
Base64 *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->Encode(args[0]);
|
||||
napi_value result = object->Encode(env, args[0]);
|
||||
return result;
|
||||
}
|
||||
static napi_value EncodeToStringAsync(napi_env env, napi_callback_info info)
|
||||
@@ -639,7 +636,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected.");
|
||||
Base64 *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->EncodeToString(args[0]);
|
||||
napi_value result = object->EncodeToString(env, args[0]);
|
||||
return result;
|
||||
}
|
||||
static napi_value DecodeAsync(napi_env env, napi_callback_info info)
|
||||
@@ -666,7 +663,7 @@ namespace OHOS::Util {
|
||||
}
|
||||
Base64 *object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->Decode(args[0]);
|
||||
napi_value result = object->Decode(env, args[0]);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -677,7 +674,7 @@ namespace OHOS::Util {
|
||||
const char testStr[] = "test";
|
||||
napi_status status = napi_create_external(
|
||||
env, (void*)testStr,
|
||||
[](napi_env env, void* data, void* hint) {},
|
||||
[](napi_env environment, void* data, void* hint) {},
|
||||
(void*)testStr, &result);
|
||||
if (status != napi_ok) {
|
||||
return NULL;
|
||||
@@ -690,13 +687,13 @@ namespace OHOS::Util {
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data));
|
||||
auto objectInfo = new Types(env);
|
||||
auto objectInfo = new Types();
|
||||
napi_wrap(
|
||||
env, thisVar, objectInfo,
|
||||
[](napi_env env, void* data, void* hint) {
|
||||
auto objectInfo = (Types*)data;
|
||||
if (objectInfo != nullptr) {
|
||||
delete objectInfo;
|
||||
[](napi_env environment, void* data, void* hint) {
|
||||
auto objectInformation = reinterpret_cast<Types*>(data);
|
||||
if (objectInformation != nullptr) {
|
||||
delete objectInformation;
|
||||
}
|
||||
},
|
||||
nullptr, nullptr);
|
||||
@@ -711,7 +708,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsAnyArrayBuffer(args);
|
||||
napi_value rst = object->IsAnyArrayBuffer(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -723,7 +720,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsArrayBufferView(args);
|
||||
napi_value rst = object->IsArrayBufferView(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -735,7 +732,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsArgumentsObject(args);
|
||||
napi_value rst = object->IsArgumentsObject(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -747,7 +744,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsArrayBuffer(args);
|
||||
napi_value rst = object->IsArrayBuffer(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -759,7 +756,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsAsyncFunction(args);
|
||||
napi_value rst = object->IsAsyncFunction(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -771,7 +768,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsBigInt64Array(args);
|
||||
napi_value rst = object->IsBigInt64Array(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -783,7 +780,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsBigUint64Array(args);
|
||||
napi_value rst = object->IsBigUint64Array(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -795,7 +792,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsBooleanObject(args);
|
||||
napi_value rst = object->IsBooleanObject(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -807,7 +804,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsBoxedPrimitive(args);
|
||||
napi_value rst = object->IsBoxedPrimitive(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -819,7 +816,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsDataView(args);
|
||||
napi_value rst = object->IsDataView(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -831,7 +828,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsDate(args);
|
||||
napi_value rst = object->IsDate(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -843,7 +840,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsExternal(args);
|
||||
napi_value rst = object->IsExternal(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -855,7 +852,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsFloat32Array(args);
|
||||
napi_value rst = object->IsFloat32Array(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -867,7 +864,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsFloat64Array(args);
|
||||
napi_value rst = object->IsFloat64Array(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -879,7 +876,7 @@ namespace OHOS::Util {
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr));
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value rst = object->IsGeneratorFunction(args);
|
||||
napi_value rst = object->IsGeneratorFunction(env, args);
|
||||
return rst;
|
||||
}
|
||||
|
||||
@@ -893,7 +890,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsGeneratorObject(args);
|
||||
napi_value result = object->IsGeneratorObject(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -907,7 +904,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsInt8Array(args);
|
||||
napi_value result = object->IsInt8Array(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -921,7 +918,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsInt16Array(args);
|
||||
napi_value result = object->IsInt16Array(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -935,7 +932,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsInt32Array(args);
|
||||
napi_value result = object->IsInt32Array(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -949,7 +946,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsMap(args);
|
||||
napi_value result = object->IsMap(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -963,7 +960,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsMapIterator(args);
|
||||
napi_value result = object->IsMapIterator(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -977,7 +974,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsModuleNamespaceObject(args);
|
||||
napi_value result = object->IsModuleNamespaceObject(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -991,7 +988,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsNativeError(args);
|
||||
napi_value result = object->IsNativeError(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1005,7 +1002,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsNumberObject(args);
|
||||
napi_value result = object->IsNumberObject(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1019,7 +1016,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsPromise(args);
|
||||
napi_value result = object->IsPromise(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1033,7 +1030,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsProxy(args);
|
||||
napi_value result = object->IsProxy(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1047,7 +1044,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsRegExp(args);
|
||||
napi_value result = object->IsRegExp(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1061,7 +1058,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsSet(args);
|
||||
napi_value result = object->IsSet(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1075,7 +1072,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsSetIterator(args);
|
||||
napi_value result = object->IsSetIterator(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1089,7 +1086,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsSharedArrayBuffer(args);
|
||||
napi_value result = object->IsSharedArrayBuffer(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1103,7 +1100,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsStringObject(args);
|
||||
napi_value result = object->IsStringObject(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1117,7 +1114,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsSymbolObject(args);
|
||||
napi_value result = object->IsSymbolObject(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1131,7 +1128,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsTypedArray(args);
|
||||
napi_value result = object->IsTypedArray(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1145,7 +1142,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsUint8Array(args);
|
||||
napi_value result = object->IsUint8Array(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1159,7 +1156,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsUint8ClampedArray(args);
|
||||
napi_value result = object->IsUint8ClampedArray(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1173,7 +1170,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsUint16Array(args);
|
||||
napi_value result = object->IsUint16Array(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1187,7 +1184,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsUint32Array(args);
|
||||
napi_value result = object->IsUint32Array(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1201,7 +1198,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsWeakMap(args);
|
||||
napi_value result = object->IsWeakMap(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1215,7 +1212,7 @@ namespace OHOS::Util {
|
||||
NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments");
|
||||
Types* object = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object));
|
||||
napi_value result = object->IsWeakSet(args);
|
||||
napi_value result = object->IsWeakSet(env, args);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -472,7 +472,7 @@ class LruBuffer
|
||||
public constructor(capacity?: number)
|
||||
{
|
||||
if (capacity !== undefined) {
|
||||
if (capacity <= 0 || capacity%1 !== 0 || capacity > this.maxNumber) {
|
||||
if (capacity <= 0 || capacity % 1 !== 0 || capacity > this.maxNumber) {
|
||||
throw new Error('data error');
|
||||
}
|
||||
this.maxSize = capacity;
|
||||
@@ -1017,7 +1017,7 @@ export default {
|
||||
TextEncoder: TextEncoder,
|
||||
TextDecoder: TextDecoder,
|
||||
Base64: Base64,
|
||||
Types: Types,
|
||||
types: Types,
|
||||
LruBuffer: LruBuffer,
|
||||
RationalNumber : RationalNumber,
|
||||
Scope : Scope,
|
||||
|
||||
Reference in New Issue
Block a user