From 43f3e6b1028bcadc2428f221ed291e6983eca3ca Mon Sep 17 00:00:00 2001 From: xdmal Date: Wed, 20 Apr 2022 17:11:18 +0800 Subject: [PATCH] Resolve multithreaded use case crashes Fix the static napi_property_descriptor to napi_property_descriptor issue: https://gitee.com/openharmony/js_util_module/issues/I53PXU Signed-off-by: xdmal --- convertxml/native_module_convertxml.cpp | 4 ++-- uri/native_module_uri.cpp | 6 +++--- uri/src/js_uri.ts | 8 +++++--- url/native_module_url.cpp | 8 ++++---- xml/native_module_xml.cpp | 8 ++++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/convertxml/native_module_convertxml.cpp b/convertxml/native_module_convertxml.cpp index e1320a5..a642334 100755 --- a/convertxml/native_module_convertxml.cpp +++ b/convertxml/native_module_convertxml.cpp @@ -75,13 +75,13 @@ namespace OHOS::Xml { { const char *convertXmlClassName = "ConvertXml"; napi_value convertXmlClass = nullptr; - static napi_property_descriptor convertXmlDesc[] = { + napi_property_descriptor convertXmlDesc[] = { DECLARE_NAPI_FUNCTION("convert", Convert) }; NAPI_CALL(env, napi_define_class(env, convertXmlClassName, strlen(convertXmlClassName), ConvertXmlConstructor, nullptr, sizeof(convertXmlDesc) / sizeof(convertXmlDesc[0]), convertXmlDesc, &convertXmlClass)); - static napi_property_descriptor desc[] = { + napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("ConvertXml", convertXmlClass) }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index a9e39f0..277f50e 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -256,7 +256,7 @@ namespace OHOS::Uri { { const char *uriClassName = "uri"; napi_value uriClass = nullptr; - static napi_property_descriptor uriDesc[] = { + napi_property_descriptor uriDesc[] = { DECLARE_NAPI_FUNCTION("normalize", Normalize), DECLARE_NAPI_FUNCTION("equals", Equals), DECLARE_NAPI_FUNCTION("checkIsAbsolute", IsAbsolute), @@ -264,7 +264,7 @@ namespace OHOS::Uri { DECLARE_NAPI_GETTER("scheme", GetScheme), DECLARE_NAPI_GETTER("authority", GetAuthority), DECLARE_NAPI_GETTER("ssp", GetSsp), - DECLARE_NAPI_GETTER("userinfo", GetUserinfo), + DECLARE_NAPI_GETTER("userInfo", GetUserinfo), DECLARE_NAPI_GETTER("host", GetHost), DECLARE_NAPI_GETTER("port", GetPort), DECLARE_NAPI_GETTER("path", GetPath), @@ -274,7 +274,7 @@ namespace OHOS::Uri { }; NAPI_CALL(env, napi_define_class(env, uriClassName, strlen(uriClassName), UriConstructor, nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); - static napi_property_descriptor desc[] = { + napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Uri", uriClass) }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); diff --git a/uri/src/js_uri.ts b/uri/src/js_uri.ts index 4df2233..5004b1c 100644 --- a/uri/src/js_uri.ts +++ b/uri/src/js_uri.ts @@ -56,8 +56,8 @@ class URI { return this.uricalss.ssp; } - get userinfo() { - return this.uricalss.userinfo; + get userInfo() { + return this.uricalss.userInfo; } get host() { @@ -100,4 +100,6 @@ function createNewUri(uriStr : string) { return new URI(uriStr); } -export default URI \ No newline at end of file +export default { + URI : URI +} \ No newline at end of file diff --git a/url/native_module_url.cpp b/url/native_module_url.cpp index 890c477..7e25a24 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -892,7 +892,7 @@ namespace OHOS::Url { { const char *seachParamsClassName = "URLSearchParams"; napi_value seachParamsInitClass = nullptr; - static napi_property_descriptor UrlDesc[] = { + napi_property_descriptor UrlDesc[] = { DECLARE_NAPI_FUNCTION("has", IsHas), DECLARE_NAPI_FUNCTION("set", Set), DECLARE_NAPI_FUNCTION("sort", Sort), @@ -909,7 +909,7 @@ namespace OHOS::Url { NAPI_CALL(env, napi_define_class(env, seachParamsClassName, strlen(seachParamsClassName), SeachParamsConstructor, nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &seachParamsInitClass)); - static napi_property_descriptor desc[] = { + napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("URLSearchParams1", seachParamsInitClass) }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); @@ -920,7 +920,7 @@ namespace OHOS::Url { { const char *urlClassName = "Url"; napi_value urlClass = nullptr; - static napi_property_descriptor UrlDesc[] = { + napi_property_descriptor UrlDesc[] = { DECLARE_NAPI_GETTER_SETTER("hostname", GetHostname, SetHostname), DECLARE_NAPI_FUNCTION("href", SetHref), DECLARE_NAPI_GETTER_SETTER("search", GetSearch, SetSearch), @@ -936,7 +936,7 @@ namespace OHOS::Url { }; NAPI_CALL(env, napi_define_class(env, urlClassName, strlen(urlClassName), UrlConstructor, nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); - static napi_property_descriptor desc[] = { + napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Url", urlClass) }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); diff --git a/xml/native_module_xml.cpp b/xml/native_module_xml.cpp index d51aa62..d8933e7 100644 --- a/xml/native_module_xml.cpp +++ b/xml/native_module_xml.cpp @@ -349,7 +349,7 @@ namespace OHOS::xml { { const char *xmlSerializerClass = "XmlSerializer"; napi_value xmlClass = nullptr; - static napi_property_descriptor xmlDesc[] = { + napi_property_descriptor xmlDesc[] = { DECLARE_NAPI_FUNCTION("setAttributes", SetAttributes), DECLARE_NAPI_FUNCTION("addEmptyElement", AddEmptyElement), DECLARE_NAPI_FUNCTION("setDeclaration", SetDeclaration), @@ -364,7 +364,7 @@ namespace OHOS::xml { }; NAPI_CALL(env, napi_define_class(env, xmlSerializerClass, strlen(xmlSerializerClass), XmlSerializerConstructor, nullptr, sizeof(xmlDesc) / sizeof(xmlDesc[0]), xmlDesc, &xmlClass)); - static napi_property_descriptor desc[] = { + napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("XmlSerializer", xmlClass) }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); @@ -409,14 +409,14 @@ namespace OHOS::xml { { const char *xmlPullParserClass = "XmlPullParser"; napi_value xmlClass = nullptr; - static napi_property_descriptor xmlDesc[] = { + napi_property_descriptor xmlDesc[] = { DECLARE_NAPI_FUNCTION("parse", Parse), DECLARE_NAPI_FUNCTION("XmlPullParserError", XmlPullParserError) }; NAPI_CALL(env, napi_define_class(env, xmlPullParserClass, strlen(xmlPullParserClass), XmlPullParserConstructor, nullptr, sizeof(xmlDesc) / sizeof(xmlDesc[0]), xmlDesc, &xmlClass)); - static napi_property_descriptor desc[] = { + napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("XmlPullParser", xmlClass) }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);