From c98b13542158168781b6cc089dcfdda55452e95c Mon Sep 17 00:00:00 2001 From: xdmal Date: Wed, 20 Apr 2022 10:01:51 +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/I53KX3 Signed-off-by: xdmal --- uri/native_module_uri.cpp | 6 +++--- uri/src/js_uri.ts | 10 ++++++---- url/native_module_url.cpp | 8 ++++---- xml/native_module_xml.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index 2d4fa32..b5f04c9 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -251,7 +251,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), @@ -259,7 +259,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), @@ -269,7 +269,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 3085f89..e9cd1d0 100644 --- a/uri/src/js_uri.ts +++ b/uri/src/js_uri.ts @@ -21,7 +21,7 @@ interface NativeUri{ scheme : string; authority : string; ssp : string; - userinfo : string; + userInfo : string; host : string; port : string; path : string; @@ -76,8 +76,8 @@ class URI { return this.uricalss.ssp; } - get userinfo() { - return this.uricalss.userinfo; + get userInfo() { + return this.uricalss.userInfo; } get host() { @@ -120,4 +120,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 1e732e1..b7c1c73 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -825,7 +825,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), @@ -842,7 +842,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); @@ -853,7 +853,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), @@ -869,7 +869,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 0344f6d..4b0a314 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);