diff --git a/util/js_base64.cpp b/util/js_base64.cpp index d31cfb0773727eea6748650b3214a801e04c1ba0..7ec89cc85a3c38291998ebe1ac635415326195b1 100755 --- a/util/js_base64.cpp +++ b/util/js_base64.cpp @@ -460,6 +460,7 @@ namespace OHOS::Util { CreateDecodePromise(inputDecode, length); } delete[] inputString; + inputString = nullptr; return stdDecodeInfo_->promise; } void Base64::CreateDecodePromise(char *inputDecode, size_t length) @@ -602,4 +603,4 @@ namespace OHOS::Util { address = nullptr; } } -} \ No newline at end of file +} diff --git a/util/js_base64.h b/util/js_base64.h index d497e4726d716c012ec9a9de53725cb98cfd2c3e..70bf6250f4fe18f06d5b20919ea15ca57e580072 100755 --- a/util/js_base64.h +++ b/util/js_base64.h @@ -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 { @@ -59,14 +59,60 @@ namespace OHOS::Util { class Base64 { public: + /** + * Constructor of Base64. + * + * @param env NAPI environment parameters. + */ explicit Base64(napi_env env); + + /** + * Destructor of Base64. + */ virtual ~Base64() {} + + /** + * Output the corresponding text after encoding the input parameters. + * + * @param src Encode the input uint8 array. + */ napi_value EncodeSync(napi_value src); + + /** + * Output the corresponding text after encoding the input parameters. + * + * @param src Encode the input uint8 array. + */ napi_value EncodeToStringSync(napi_value src); + + /** + * Output the corresponding text after encoding the input parameters. + * + * @param src Decode the input uint8 array or string. + */ napi_value DecodeSync(napi_value src); + + /** + * Output the corresponding text after asynchronously encoding the input parameters. + * + * @param src Asynchronously encoded input uint8 array. + */ napi_value Encode(napi_value src); + + /** + * Output the corresponding text after asynchronously encoding the input parameters. + * + * @param src Asynchronously encoded input uint8 array. + */ napi_value EncodeToString(napi_value src); + + /** + * Output the corresponding text after asynchronously encoding the input parameters. + * + * @param src Asynchronously decode the input uint8 array or string. + */ napi_value Decode(napi_value src); + private: napi_env env; unsigned char *DecodeAchieve(const char *input, size_t inputLen); @@ -93,4 +139,4 @@ namespace OHOS::Util { static void EndStdDecode(napi_env env, napi_status status, void *buffer); }; } -#endif \ No newline at end of file +#endif // UTIL_JS_BASE64_H_ diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index afc8d02bf0d6b5cb01e054fe66c373ae29552e6a..16d113b3db2d89cbe0d021b9dea2b6b17e9ff2ae 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -187,4 +187,4 @@ namespace OHOS::Util { } } } -} \ No newline at end of file +} diff --git a/util/js_textdecoder.h b/util/js_textdecoder.h index 1753e1dcc855efede1a9b7de51ca9c2bc333e8b0..7862c5da84f1ed216d9074f8159727bb2ea46e3e 100755 --- a/util/js_textdecoder.h +++ b/util/js_textdecoder.h @@ -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 #include @@ -46,19 +46,66 @@ namespace OHOS::Util { UNICODE_FLG = 0x8, BOM_SEEN_FLG = 0x10, }; + public: + /** + * Constructor of textdecoder + * + * @param env NAPI environment parameters. + * @param buff Encoding format. + * @param optionVec There are two attributes of code related option parameters: fatal and ignorebom. + */ TextDecoder(napi_env env, std::string buff, std::vector optionVec); + + /** + * Destructor of textencoder. + */ virtual ~TextDecoder() {} + + /** + * Destructor of textencoder. + * + * @param src An array that matches the format and needs to be decoded. + * @param iflag Decoding related option parameters. + */ napi_value Decode(napi_value src, bool iflag); + + /** + * Get encoding format. + */ napi_value GetEncoding() const; + + /** + * Gets the setting of the exception thrown. + */ napi_value GetFatal() const; + + /** + * Gets whether to ignore the setting of BOM flag. + */ napi_value GetIgnoreBOM() 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(ConverterFlags::BOM_SEEN_FLG); @@ -68,6 +115,10 @@ namespace OHOS::Util { return false; } } + + /** + * Determine whether it is Unicode. + */ bool IsUnicode() const { uint32_t temp = label_ & static_cast(ConverterFlags::UNICODE_FLG); @@ -77,6 +128,10 @@ namespace OHOS::Util { return false; } } + + /** + * Determine whether it is an ignored BOM. + */ bool IsIgnoreBom() const { uint32_t temp = label_ & static_cast(ConverterFlags::IGNORE_BOM_FLG); @@ -86,10 +141,15 @@ 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); @@ -100,4 +160,4 @@ namespace OHOS::Util { TransformToolPointer tranTool_; }; } -#endif /* FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTDECODER_H */ +#endif // UTIL_JS_TEXTDECODER_H_ diff --git a/util/js_textencoder.cpp b/util/js_textencoder.cpp index 937785569cdb29e604f60c7e5ed77a0c2262a715..fc9e56a63289f476e124b9d055598d4b61b085a1 100755 --- a/util/js_textencoder.cpp +++ b/util/js_textencoder.cpp @@ -91,4 +91,4 @@ namespace OHOS::Util { return result; } -} \ No newline at end of file +} diff --git a/util/js_textencoder.h b/util/js_textencoder.h index 46deaae2fb25d4d85d4dbc1ce98be0d1bf171a3c..2668ad9324d4e17da3c96919ac9d7e66d65a7a7c 100755 --- a/util/js_textencoder.h +++ b/util/js_textencoder.h @@ -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 @@ -23,12 +23,36 @@ namespace OHOS::Util { class TextEncoder { public: + /** + * Constructor of textdecoder. + * + * @param env NAPI environment parameters. + */ explicit TextEncoder(napi_env env); + /** + * Destructor of textencoder. + */ virtual ~TextEncoder() {} + /** + * Get encoding format. + */ napi_value GetEncoding() const; + + /** + * Output the corresponding text after encoding the input parameters. + * + * @param src A string that needs to be encoded. + */ napi_value Encode(napi_value src) const; + + /** + * Place the generated UTF-8 encoded text. + * + * @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_value src, napi_value dest) const; private: @@ -36,4 +60,4 @@ namespace OHOS::Util { std::string encoding_; }; } -#endif /* FOUNDATION_CCRUNTIME_TEXTCODER_JS_TEXTENCODER_H */ \ No newline at end of file +#endif // UTIL_JS_TEXTENCODER_H_ diff --git a/util/js_types.cpp b/util/js_types.cpp index 842863ef248059c79bb735eb96d2052b77027545..f3a49bc7f31556c23fdfd1aac18286c0400a55c5 100644 --- a/util/js_types.cpp +++ b/util/js_types.cpp @@ -590,4 +590,4 @@ namespace OHOS::Util { napi_get_boolean(env_, flag, &result); return result; } -} \ No newline at end of file +} diff --git a/util/js_types.h b/util/js_types.h index 6c9725342b724ae9ba860621fe3c48412aef9cc8..dbdfdd034d3f2a96ad6a0c2426978ad4f8add485 100644 --- a/util/js_types.h +++ b/util/js_types.h @@ -21,55 +21,299 @@ #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: + /** + * Constructor of Types. + * + * @param env NAPI environment parameters. + */ explicit Types(napi_env env); + + /** + * Destructor of Types. + */ virtual ~Types() {} + + /** + * Check whether the entered value is of arraybuffer type. + * + * @param src Object to be tested. + */ napi_value IsAnyArrayBuffer(napi_value src) const; + + /** + * Check whether the entered value is a built-in arraybufferview auxiliary type. + * + * @param src Object to be tested. + */ napi_value IsArrayBufferView(napi_value src) const; + + /** + * Check whether the entered value is an arguments object type. + * + * @param src Object to be tested. + */ napi_value IsArgumentsObject(napi_value src) const; + + /** + * Check whether the entered value is of arraybuffer type. + * + * @param src Object to be tested. + */ napi_value IsArrayBuffer(napi_value src) const; + + /** + * Check whether the input value is an asynchronous function type. + * + * @param src Object to be tested. + */ napi_value IsAsyncFunction(napi_value src) const; + + /** + * Check whether the entered value is a bigint64array type. + * + * @param src Object to be tested. + */ napi_value IsBigInt64Array(napi_value src) const; + + /** + * Check whether the entered value is a biguint64array type. + * + * @param src Object to be tested. + */ napi_value IsBigUint64Array(napi_value src) const; + + /** + * Check whether the entered value is a Boolean object type. + * + * @param src Object to be tested. + */ napi_value IsBooleanObject(napi_value src) const; + + /** + * Check whether the entered value is Boolean or number or string or symbol object type. + * + * @param src Object to be tested. + */ napi_value IsBoxedPrimitive(napi_value src) const; + + /** + * Check whether the entered value is of DataView type. + * + * @param src Object to be tested. + */ napi_value IsDataView(napi_value src) const; + + /** + * Check whether the entered value is of type date. + * + * @param src Object to be tested. + */ napi_value IsDate(napi_value src) const; + + /** + * Check whether the entered value is of type native external. + * + * @param src Object to be tested. + */ napi_value IsExternal(napi_value src) const; + + /** + * Check whether the entered value is the type of float32array array. + * + * @param src Object to be tested. + */ napi_value IsFloat32Array(napi_value src) const; + + /** + * Check whether the entered value is the type of float64array array. + * + * @param src Object to be tested. + */ napi_value IsFloat64Array(napi_value src) const; + + /** + * Check whether the value entered is the type of generator function. + * + * @param src Object to be tested. + */ napi_value IsGeneratorFunction(napi_value src) const; + + /** + * Check whether the value entered is the type of generator object. + * + * @param src Object to be tested. + */ napi_value IsGeneratorObject(napi_value src) const; + + /** + * Check whether the value entered is the type of int8 array. + * + * @param src Object to be tested. + */ napi_value IsInt8Array(napi_value src) const; + + /** + * Check whether the value entered is the type of int16 array. + * + * @param src Object to be tested. + */ napi_value IsInt16Array(napi_value src) const; + + /** + * Check whether the value entered is the type of int32 array. + * + * @param src Object to be tested. + */ napi_value IsInt32Array(napi_value src) const; + + /** + * Check whether the value entered is the type of map. + * + * @param src Object to be tested. + */ napi_value IsMap(napi_value src) const; + + /** + * Check whether the entered value is the iterator type of map. + * + * @param src Object to be tested. + */ napi_value IsMapIterator(napi_value src) const; + + /** + * Check whether the entered value is the module name space type of object. + * + * @param src Object to be tested. + */ napi_value IsModuleNamespaceObject(napi_value src) const; + + /** + * Check whether the entered value is of type error. + * + * @param src Object to be tested. + */ napi_value IsNativeError(napi_value src) const; + + /** + * Check whether the entered value is the number type of object. + * + * @param src Object to be tested. + */ napi_value IsNumberObject(napi_value src) const; + + /** + * Check whether the entered value is the type of promise. + * + * @param src Object to be tested. + */ napi_value IsPromise(napi_value src) const; + + /** + * Check whether the entered value is the type of proxy. + * + * @param src Object to be tested. + */ napi_value IsProxy(napi_value src) const; + + /** + * Check whether the entered value is the type of regexp. + * + * @param src Object to be tested. + */ napi_value IsRegExp(napi_value src) const; + + /** + * Check whether the entered value is the type of set. + * + * @param src Object to be tested. + */ napi_value IsSet(napi_value src) const; + + /** + * Check whether the entered value is the iterator type of set. + * + * @param src Object to be tested. + */ napi_value IsSetIterator(napi_value src) const; + + /** + * Check whether the entered value is the type of sharedarraybuffer. + * + * @param src Object to be tested. + */ napi_value IsSharedArrayBuffer(napi_value src) const; + + /** + * Check whether the entered value is the string type of object. + * + * @param src Object to be tested. + */ napi_value IsStringObject(napi_value src) const; + + /** + * Check whether the entered value is the symbol type of object. + * + * @param src Object to be tested. + */ napi_value IsSymbolObject(napi_value src) const; + + /** + * Check whether the entered value is the type of typedarray. + * + * @param src Object to be tested. + */ napi_value IsTypedArray(napi_value src) const; + + /** + * Check whether the entered value is the type of uint8array. + * + * @param src Object to be tested. + */ napi_value IsUint8Array(napi_value src) const; + + /** + * Check whether the entered value is the type of uint8clampedarray. + * + * @param src Object to be tested. + */ napi_value IsUint8ClampedArray(napi_value src) const; + + /** + * Check whether the entered value is the type of uint16array. + * + * @param src Object to be tested. + */ napi_value IsUint16Array(napi_value src) const; + + /** + * Check whether the entered value is the type of uint32array. + * + * @param src Object to be tested. + */ napi_value IsUint32Array(napi_value src) const; + + /** + * Check whether the entered value is the type of weakmap. + * + * @param src Object to be tested. + */ napi_value IsWeakMap(napi_value src) const; + + /** + * Check whether the entered value is the type of weakset. + * + * @param src Object to be tested. + */ napi_value IsWeakSet(napi_value src) const; + private: napi_env env_; }; } -#endif \ No newline at end of file +#endif // UTIL_JS_TYPES_H_ diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index 90603f8d0da882fa56e1692c4356991fcfdff779..a33e5751f0b38a3e3725b916bb49fd1e569729ba 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -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 { + 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; + if (napi_get_value_string_utf8(env, argv, nullptr, 0, &formatsize) != napi_ok) { + HILOG_ERROR("can not get argv size"); return nullptr; } - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - char *format = nullptr; - 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; + 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; } - 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); + return FormatString(env, format); } static std::string PrintfString(const std::string &format, const std::vector &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 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; + } + 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; } - napi_get_value_string_utf8(env, argv[i], valueString, valuesize + 1, &valuesize); - value.push_back(valueString); - delete []valueString; - valueString = 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) { @@ -312,8 +309,8 @@ namespace OHOS::Util { auto objectInfo = new TextDecoder(env, 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(data); if (objInfo != nullptr) { delete objInfo; } @@ -347,10 +344,10 @@ namespace OHOS::Util { valStr = textDecoder->Decode(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(argvArr[0], iStream); } return valStr; } @@ -405,8 +402,8 @@ namespace OHOS::Util { auto object = new TextEncoder(env); 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(data); if (obj != nullptr) { delete obj; } @@ -523,8 +520,8 @@ namespace OHOS::Util { auto objectInfo = new Base64(env); 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(data); if (objInfo != nullptr) { delete objInfo; } @@ -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; @@ -693,10 +690,10 @@ namespace OHOS::Util { auto objectInfo = new Types(env); 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(data); + if (objectInformation != nullptr) { + delete objectInformation; } }, nullptr, nullptr); @@ -1348,4 +1345,4 @@ namespace OHOS::Util { *buflen = _binary_util_abc_end - _binary_util_abc_start; } } -} \ No newline at end of file +}