From 0797649d9a450fe4c900971409d567559b220158 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Fri, 24 Sep 2021 22:20:05 +0800 Subject: [PATCH 01/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/js_convertxml.cpp modified: convertxml/js_convertxml.h modified: convertxml/js_convertxml.js modified: convertxml/native_module_convertxml.cpp modified: uri/js_uri.cpp modified: uri/native_module_uri.cpp modified: url/js_url.cpp modified: url/native_module_url.cpp --- convertxml/js_convertxml.cpp | 161 +++++++++++++----------- convertxml/js_convertxml.h | 3 +- convertxml/js_convertxml.js | 53 ++++++++ convertxml/native_module_convertxml.cpp | 3 +- uri/js_uri.cpp | 16 +-- uri/native_module_uri.cpp | 2 +- url/js_url.cpp | 6 +- url/native_module_url.cpp | 2 +- 8 files changed, 161 insertions(+), 85 deletions(-) diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 727565fb..982a59ca 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -114,12 +114,16 @@ void ConvertXml::GetPrevNodeList(xmlNodePtr curNode) if (curNode->type == xmlElementType::XML_PI_NODE && !m_Options.ignoreInstruction) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); - SetKeyValue(elementsObject, m_Options.instruction, (const char*)xmlNodeGetContent(curNode)); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.instruction, (const char*)xmlNodeGetContent(curNode)); + } m_prevObj.push_back(elementsObject); } if (curNode->type == xmlElementType::XML_COMMENT_NODE && !m_Options.ignoreComment) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - SetKeyValue(elementsObject, m_Options.comment, (const char*)xmlNodeGetContent(curNode)); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.comment, (const char*)xmlNodeGetContent(curNode)); + } m_prevObj.push_back(elementsObject); } if (curNode->type == xmlElementType::XML_DTD_NODE && !m_Options.ignoreDoctype) { @@ -147,34 +151,44 @@ void ConvertXml::SetAttributes(xmlNodePtr curNode, napi_value &elementsObject) void ConvertXml::SetXmlElementType(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag) { if (curNode->type == xmlElementType::XML_PI_NODE && !m_Options.ignoreInstruction) { - SetKeyValue(elementsObject, m_Options.instruction.c_str(), (const char*)xmlNodeGetContent(curNode)); - bFlag = true; + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.instruction.c_str(), (const char*)xmlNodeGetContent(curNode)); + bFlag = true; + } } else if (curNode->type == xmlElementType::XML_COMMENT_NODE && !m_Options.ignoreComment) { - SetKeyValue(elementsObject, m_Options.comment.c_str(), (const char*)xmlNodeGetContent(curNode)); - bFlag = true; + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.comment.c_str(), (const char*)xmlNodeGetContent(curNode)); + bFlag = true; + } } else if (curNode->type == xmlElementType::XML_CDATA_SECTION_NODE && !m_Options.ignoreCdata) { - SetKeyValue(elementsObject, m_Options.cdata, (const char*)xmlNodeGetContent(curNode)); - bFlag = true; + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.cdata, (const char*)xmlNodeGetContent(curNode)); + bFlag = true; + } } } void ConvertXml::SetNodeInfo(xmlNodePtr curNode, napi_value &elementsObject) { - if (curNode->type == xmlElementType::XML_PI_NODE) { - if (!m_Options.ignoreInstruction) { - SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - } + if (curNode->type == xmlElementType::XML_TEXT_NODE) { + return; } else { - SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - } - if ((curNode->type != xmlElementType::XML_COMMENT_NODE) && - (curNode->type != xmlElementType::XML_CDATA_SECTION_NODE)) { - if (!(curNode->type == xmlElementType::XML_PI_NODE && m_Options.ignoreInstruction)) { - SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); + if (curNode->type == xmlElementType::XML_PI_NODE) { + if (!m_Options.ignoreInstruction) { + SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); + } + } else { + SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); + } + if ((curNode->type != xmlElementType::XML_COMMENT_NODE) && + (curNode->type != xmlElementType::XML_CDATA_SECTION_NODE)) { + if (!(curNode->type == xmlElementType::XML_PI_NODE && m_Options.ignoreInstruction)) { + SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); + } } } } -void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag, bool &bText, int32_t index) +void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); if (curNode->type == xmlElementType::XML_ELEMENT_NODE) { @@ -182,16 +196,17 @@ void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool bFlag = true; } else if (curNode->type == xmlElementType::XML_TEXT_NODE) { if (m_Options.trim) { - SetKeyValue(elementsObject, m_Options.text, Trim((const char*)xmlNodeGetContent(curNode))); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.text, Trim((const char*)xmlNodeGetContent(curNode))); + } } else { - SetKeyValue(elementsObject, m_Options.text, (const char*)xmlNodeGetContent(curNode)); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.text, (const char*)xmlNodeGetContent(curNode)); + } } if (!m_Options.ignoreText) { bFlag = true; } - if (index != 0) { - bText = false; - } } } @@ -208,21 +223,17 @@ void ConvertXml::GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag) { napi_value elements = nullptr; napi_create_array(env_, &elements); - napi_value recvElement; + napi_value recvElement = nullptr; napi_create_array(env_, &recvElement); xmlNodePtr pNode = curNode; int32_t index = 0; int32_t index1 = 0; bool bFlag = false; - bool bText = true; while (pNode != nullptr) { bFlag = false; - bText = true; napi_value elementsObject = nullptr; napi_create_object(env_, &elementsObject); - if (flag == 0 || (index % 2 != 0)) { // 2:pNode - SetNodeInfo(pNode, elementsObject); - } + SetNodeInfo(pNode, elementsObject); SetAttributes(pNode, elementsObject); napi_value tempElement = nullptr; napi_create_array(env_, &tempElement); @@ -233,16 +244,15 @@ void ConvertXml::GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag) curNode = pNode->children; GetXMLInfo(curNode, elementsObject, 1); bFlag = true; - } else if (index % 2 != 0) { // 2:pNode + } else { SetXmlElementType(pNode, elementsObject, bFlag); - } else if (pNode->next == nullptr) { - SetEndInfo(pNode, elementsObject, bFlag, bText, index); + SetEndInfo(pNode, elementsObject, bFlag); } } SetPrevInfo(recvElement, flag, index1); - if (elementsObject != nullptr && bFlag && bText) { - napi_set_element(env_, recvElement, index1++, elementsObject); - elementsObject = nullptr; + if (elementsObject != nullptr && bFlag) { + napi_set_element(env_, recvElement, index1++, elementsObject); + elementsObject = nullptr; } index++; pNode = pNode->next; @@ -252,52 +262,60 @@ void ConvertXml::GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag) } } +void ConvertXml::SetSpacesInfo(napi_value &object) +{ + napi_value iTemp = nullptr; + switch (m_SpaceType) { + case (SpaceType::T_INT32): + napi_create_int32(env_, m_iSpace, &iTemp); + napi_set_named_property(env_, object, "spaces", iTemp); + break; + case (SpaceType::T_STRING): + SetKeyValue(object, "spaces", m_strSpace); + break; + case (SpaceType::T_INIT): + SetKeyValue(object, "spaces", m_strSpace); + break; + default: + break; + } +} + napi_value ConvertXml::convert(std::string strXml) { xmlDocPtr doc = NULL; xmlNodePtr curNode = NULL; napi_status status = napi_ok; - size_t len = strXml.size(); - doc = xmlParseMemory(strXml.c_str(), len); - if (!doc) { - xmlFreeDoc(doc); - } napi_value object = nullptr; status = napi_create_object(env_, &object); if (status != napi_ok) { return NULL; } + size_t len = strXml.size(); + doc = xmlParseMemory(strXml.c_str(), len); + if (!doc) { + xmlFreeDoc(doc); + return object; + } napi_value subObject = nullptr; napi_value subSubObject = nullptr; - napi_value napiKey = nullptr; napi_create_object(env_, &subSubObject); napi_create_object(env_, &subObject); - napi_create_string_utf8(env_, (const char*)doc->version, NAPI_AUTO_LENGTH, &napiKey); - napi_set_named_property(env_, subSubObject, "version", napiKey); - napi_create_string_utf8(env_, (const char*)doc->encoding, NAPI_AUTO_LENGTH, &napiKey); - napi_set_named_property(env_, subSubObject, "encoding", napiKey); - if (!m_Options.ignoreDeclaration) { + if (doc->version != nullptr) { + SetKeyValue(subSubObject, "version", (const char*)doc->version); + } + if (doc->encoding != nullptr) { + SetKeyValue(subSubObject, "encoding", (const char*)doc->encoding); + } + + if (!m_Options.ignoreDeclaration && strXml.find("xml")!=std::string::npos) { napi_set_named_property(env_, subObject, m_Options.attributes.c_str(), subSubObject); napi_set_named_property(env_, object, m_Options.declaration.c_str(), subObject); } curNode = xmlDocGetRootElement(doc); GetPrevNodeList(curNode); GetXMLInfo(curNode, object, 0); - napi_value iTemp = nullptr; - switch (m_SpaceType) { - case (SpaceType::T_INT32): - napi_create_int32(env_, m_iSpace, &iTemp); - napi_set_named_property(env_, object, "spaces", iTemp); - break; - case (SpaceType::T_STRING): - SetKeyValue(object, "spaces", m_strSpace); - break; - case (SpaceType::T_INIT): - SetKeyValue(object, "spaces", m_strSpace); - break; - default: - break; - } + SetSpacesInfo(object); return object; } @@ -310,9 +328,10 @@ napi_status ConvertXml::DealNapiStrValue(napi_value napi_StrValue, std::string & if (status != napi_ok) { return status; } - buffer = new char[bufferSize + 1]; - napi_get_value_string_utf8(env_, napi_StrValue, buffer, bufferSize + 1, &bufferSize); - + if (bufferSize > 0) { + buffer = new char[bufferSize + 1]; + napi_get_value_string_utf8(env_, napi_StrValue, buffer, bufferSize + 1, &bufferSize); + } if (buffer != nullptr) { result = buffer; delete []buffer; @@ -341,8 +360,9 @@ void ConvertXml::DealSpaces(napi_value napi_obj) void ConvertXml::DealIgnore(napi_value napi_obj) { - std::vectorvctIgnore = { "compact", "trim", "ignoreDeclaration", "ignoreInstruction", - "ignoreAttributes", "ignoreComment", "ignoreCdata", "ignoreDoctype", "ignoreText" }; + std::vector vctIgnore = {"compact", "trim", "ignoreDeclaration", "ignoreInstruction", + "ignoreAttributes", "ignoreComment", "ignoreCdata", + "ignoreDoctype", "ignoreText"}; for (size_t i = 0; i < vctIgnore.size(); ++i) { napi_value recvTemp = nullptr; bool bRecv = false; @@ -426,8 +446,9 @@ void ConvertXml::SetDefaultKey(size_t i, std::string strRecv) void ConvertXml::DealOptions(napi_value napi_obj) { - std::vectorvctOptions = { "declarationKey", "instructionKey", "attributesKey", "textKey", - "cdataKey", "doctypeKey", "commentKey", "parentKey", "typeKey", "nameKey", "elementsKey" }; + std::vector vctOptions = {"declarationKey", "instructionKey", "attributesKey", "textKey", + "cdataKey", "doctypeKey", "commentKey", "parentKey", "typeKey", + "nameKey", "elementsKey"}; for (size_t i = 0; i < vctOptions.size(); ++i) { napi_value recvTemp = nullptr; std::string strRecv = ""; @@ -438,4 +459,4 @@ void ConvertXml::DealOptions(napi_value napi_obj) } DealIgnore(napi_obj); DealSpaces(napi_obj); -} +} \ No newline at end of file diff --git a/convertxml/js_convertxml.h b/convertxml/js_convertxml.h index bbe2381f..a44b731c 100755 --- a/convertxml/js_convertxml.h +++ b/convertxml/js_convertxml.h @@ -66,7 +66,7 @@ public: void SetAttributes(xmlNodePtr curNode, napi_value &elementsObject); void SetXmlElementType(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag); void SetNodeInfo(xmlNodePtr curNode, napi_value &elementsObject); - void SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag, bool &bText, int32_t index); + void SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag); void GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag = 0); napi_value convert(std::string strXml); std::string GetNodeType(xmlElementType enumType); @@ -79,6 +79,7 @@ public: void DealIgnore(napi_value napi_obj); void SetPrevInfo(napi_value &recvElement, int flag, int32_t &index1); void SetDefaultKey(size_t i, std::string strRecv); + void SetSpacesInfo(napi_value &object); private: napi_env env_; SpaceType m_SpaceType; diff --git a/convertxml/js_convertxml.js b/convertxml/js_convertxml.js index a0305b03..3b6b5ba2 100755 --- a/convertxml/js_convertxml.js +++ b/convertxml/js_convertxml.js @@ -21,6 +21,7 @@ class ConvertXml { this.convertxmlclass = new convertXml.ConvertXml(); } convert(strXml, options) { + strXml = DealXml(strXml); let converted = this.convertxmlclass.convert(strXml, options); let space = 0; if (converted.hasOwnProperty("spaces")) { @@ -31,6 +32,58 @@ class ConvertXml { } } +function DealXml(strXml) +{ + var idx = -1; + var idxSec = 0; + var idxThir = 0; + var idxCData = 0; + var idxCDataSec = 0; + while ((idx = strXml.indexOf('>', idxSec)) != -1) { + idxThir = strXml.indexOf('<', idx); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { + case '\n': + strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); + break; + case '\v': + strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); + break; + case '\t': + strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); + break; + } + } else { + strXml = strXml.substring(0, j) + strXml.substring(j + 1); + --j; + } + } + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf(' g_ruleAlpha; - std::bitset g_ruleScheme; - std::bitset g_ruleUrlc; - std::bitset g_rulePath; - std::bitset g_ruleUserInfo; - std::bitset g_ruleScope; - std::bitset g_ruleDigit; - std::bitset g_rulePort; + std::bitset g_ruleAlpha; + std::bitset g_ruleScheme; + std::bitset g_ruleUrlc; + std::bitset g_rulePath; + std::bitset g_ruleUserInfo; + std::bitset g_ruleScope; + std::bitset g_ruleDigit; + std::bitset g_rulePort; void Uri::PreliminaryWork() const { std::string digitAggregate = "0123456789"; diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index cb013be8..c0ee394a 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -264,7 +264,7 @@ namespace OHOS::Uri { DECLARE_NAPI_GETTER("isFailed", IsFailed), }; NAPI_CALL(env, napi_define_class(env, uriClassName, strlen(uriClassName), UriConstructor, - nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); + nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Uri", uriClass) }; diff --git a/url/js_url.cpp b/url/js_url.cpp index ba9f1b93..1b53b245 100755 --- a/url/js_url.cpp +++ b/url/js_url.cpp @@ -1705,7 +1705,7 @@ namespace OHOS::Url { (charaEncode & 0x0000003F)]; // Acquisition method of the second byte output += output1 + output2; } else if ((charaEncode >= 0x0000E000) || - (charaEncode <= 0x0000D7FF)) { // Convert the Unicode code into three bytes + (charaEncode <= 0x0000D7FF)) { // Convert the Unicode code into three bytes std::string output1 = reviseChar[0x000000E0 | (charaEncode / 4096)]; // 4096:Acquisition method of the first byte std::string output2 = reviseChar[numOfAscii | @@ -1935,7 +1935,7 @@ namespace OHOS::Url { sname = ToUSVString(name); } delete[] name; - for (std::vector::iterator iter = searchParams.begin(); iter != searchParams.end();) { + for (auto iter = searchParams.begin(); iter != searchParams.end();) { if (*iter == sname) { iter = searchParams.erase(iter, iter + 2); // 2:Searching for the number and number of keys and values } else { @@ -2032,7 +2032,7 @@ namespace OHOS::Url { delete[] buffer1; } bool flag = false; - for (std::vector::iterator it = searchParams.begin(); it < searchParams.end() - 1;) { + for (auto it = searchParams.begin(); it < (searchParams.end() - 1);) { if (*it == cppName) { if (!flag) { *(it + 1) = cppValue; diff --git a/url/native_module_url.cpp b/url/native_module_url.cpp index 279f4316..61497a76 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -884,7 +884,7 @@ namespace OHOS::Url { DECLARE_NAPI_GETTER("GetIsIpv6", GetIsIpv6), }; NAPI_CALL(env, napi_define_class(env, urlClassName, strlen(urlClassName), UrlConstructor, - nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); + nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Url", urlClass) }; -- Gitee From c42f40bfe78915c1493a65779a62093c1f8ae38f Mon Sep 17 00:00:00 2001 From: lifansheng Date: Fri, 24 Sep 2021 23:07:15 +0800 Subject: [PATCH 02/24] Signed-off-by: lifansheng Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/js_convertxml.cpp --- convertxml/js_convertxml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 982a59ca..f3c9d7b8 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -308,7 +308,7 @@ napi_value ConvertXml::convert(std::string strXml) SetKeyValue(subSubObject, "encoding", (const char*)doc->encoding); } - if (!m_Options.ignoreDeclaration && strXml.find("xml")!=std::string::npos) { + if (!m_Options.ignoreDeclaration && strXml.find("xml") != std::string::npos) { napi_set_named_property(env_, subObject, m_Options.attributes.c_str(), subSubObject); napi_set_named_property(env_, object, m_Options.declaration.c_str(), subObject); } -- Gitee From 1e7dcd6f0c02b653f3750c68afe90f90357f5c60 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sat, 25 Sep 2021 16:21:01 +0800 Subject: [PATCH 03/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: new file: 666.txt --- 666.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 666.txt diff --git a/666.txt b/666.txt new file mode 100644 index 00000000..e69de29b -- Gitee From e330741b93aea9b1cbc5a26ac2f7becedd7f50f0 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sat, 25 Sep 2021 16:24:11 +0800 Subject: [PATCH 04/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: deleted: 666.txt --- 666.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 666.txt diff --git a/666.txt b/666.txt deleted file mode 100644 index e69de29b..00000000 -- Gitee From 73fc532890480b2aed5a1e190411ff1b1578bdb1 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sat, 25 Sep 2021 16:35:44 +0800 Subject: [PATCH 05/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/js_convertxml.cpp --- convertxml/js_convertxml.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index f3c9d7b8..2261268a 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -301,10 +301,10 @@ napi_value ConvertXml::convert(std::string strXml) napi_value subSubObject = nullptr; napi_create_object(env_, &subSubObject); napi_create_object(env_, &subObject); - if (doc->version != nullptr) { + if (doc != nullptr && doc->version != nullptr) { SetKeyValue(subSubObject, "version", (const char*)doc->version); } - if (doc->encoding != nullptr) { + if (doc != nullptr && doc->encoding != nullptr) { SetKeyValue(subSubObject, "encoding", (const char*)doc->encoding); } -- Gitee From 8d751e14c801ae5ae40c5ae374734fb3c80cba32 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 15:49:24 +0800 Subject: [PATCH 06/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn new file: convertxml/build_ts_js.py modified: convertxml/js_convertxml.cpp modified: convertxml/js_convertxml.h modified: convertxml/js_convertxml.js new file: convertxml/src/js_convertxml.ts new file: convertxml/tsconfig.json --- convertxml/BUILD.gn | 10 ++- convertxml/build_ts_js.py | 21 +++++ convertxml/js_convertxml.cpp | 134 ++++++++++++++++++++++++++++++-- convertxml/js_convertxml.h | 67 +++++++++------- convertxml/js_convertxml.js | 95 +++++++++++++++------- convertxml/src/js_convertxml.ts | 130 +++++++++++++++++++++++++++++++ convertxml/tsconfig.json | 14 ++++ 7 files changed, 408 insertions(+), 63 deletions(-) create mode 100644 convertxml/build_ts_js.py create mode 100644 convertxml/src/js_convertxml.ts create mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index a2ac7c53..da283f8a 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -14,11 +14,19 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [target_out_dir + "/js_convertxml.js" + ] +} + base_output_path = get_label_info(":js_convertxml", "target_out_dir") js_xml_obj_path = base_output_path + "/convertxml.o" gen_js_obj("js_convertxml") { - input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" + input = "$target_out_dir/js_convertxml.js" output = js_xml_obj_path + dep = ":build_ts_js" } ohos_shared_library("convertxml") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py new file mode 100644 index 00000000..76b3fb1d --- /dev/null +++ b/convertxml/build_ts_js.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 2261268a..65a40944 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -283,18 +283,23 @@ void ConvertXml::SetSpacesInfo(napi_value &object) napi_value ConvertXml::convert(std::string strXml) { - xmlDocPtr doc = NULL; - xmlNodePtr curNode = NULL; + xmlDocPtr doc = nullptr; + xmlNodePtr curNode = nullptr; napi_status status = napi_ok; napi_value object = nullptr; status = napi_create_object(env_, &object); if (status != napi_ok) { - return NULL; + return nullptr; } + Replace(strXml, "\\r", "\r"); + Replace(strXml, "\\n", "\n"); + Replace(strXml, "\\v", "\v"); + Replace(strXml, "]]> encoding != nullptr) { SetKeyValue(subSubObject, "encoding", (const char*)doc->encoding); } - if (!m_Options.ignoreDeclaration && strXml.find("xml") != std::string::npos) { napi_set_named_property(env_, subObject, m_Options.attributes.c_str(), subSubObject); napi_set_named_property(env_, object, m_Options.declaration.c_str(), subObject); } - curNode = xmlDocGetRootElement(doc); - GetPrevNodeList(curNode); - GetXMLInfo(curNode, object, 0); + if (doc != nullptr) { + curNode = xmlDocGetRootElement(doc); + GetPrevNodeList(curNode); + GetXMLInfo(curNode, object, 0); + } SetSpacesInfo(object); return object; } @@ -459,4 +465,118 @@ void ConvertXml::DealOptions(napi_value napi_obj) } DealIgnore(napi_obj); DealSpaces(napi_obj); +} + +void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) +{ + size_t iXml = 0; + if ((iXml = strXml.find("xml")) != std::string::npos) { + m_XmlInfo.bXml = true; + napi_value declObj = nullptr; + napi_create_object(env_, &declObj); + napi_value attrObj = nullptr; + bool bFlag = false; + napi_create_object(env_, &attrObj); + if (strXml.find("version=") != std::string::npos) { + m_XmlInfo.bVersion = true; + SetKeyValue(attrObj, "version", "1.0"); + bFlag = true; + } + if (strXml.find("encoding=") != std::string::npos) { + m_XmlInfo.bEncoding = false; + SetKeyValue(attrObj, "encoding", "utf-8"); + bFlag = true; + } + if (bFlag) { + napi_set_named_property(env_, declObj, m_Options.attributes.c_str(), attrObj); + napi_set_named_property(env_, object, m_Options.declaration.c_str(), declObj); + } else { + napi_set_named_property(env_, object, m_Options.declaration.c_str(), declObj); + } + if (strXml.find(">", iXml) == strXml.size() - 1) { + strXml = ""; + } else { + strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); + } + } + size_t iCount = 0; + size_t iLen = strXml.size(); + for (; iCount < iLen; ++iCount) { + if (strXml[iCount] != ' ' && strXml[iCount] != '\v' && + strXml[iCount] != '\t' && strXml[iCount] != '\n') { + break; + } + } + if (iCount < iLen) { + DealComplex(strXml, object); + } +} + +void ConvertXml::DealComplex(std::string &strXml, napi_value &object) +{ + if (strXml.find(""; + } else { + strXml = "" + strXml + ""; + } + xmlDocPtr doc = nullptr; + xmlNodePtr curNode = nullptr; + size_t len = strXml.size(); + doc = xmlParseMemory(strXml.c_str(), len); + if (!doc) { + xmlFreeDoc(doc); + } + if (doc) { + curNode = xmlDocGetRootElement(doc); + curNode = curNode->children; + napi_value elements = nullptr; + napi_create_array(env_, &elements); + bool bHasEle = false; + int index = 0; + bool bCData = false; + if (strXml.find("type == xmlElementType::XML_CDATA_SECTION_NODE && + curNode->next && curNode->next->type == xmlElementType::XML_TEXT_NODE && + curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { + if (xmlNodeGetContent(curNode->next) != nullptr) { + std::string strTemp = (char*)xmlNodeGetContent(curNode->next); + Replace(strTemp, " ", ""); + Replace(strTemp, "\v", ""); + Replace(strTemp, "\t", ""); + Replace(strTemp, "\n", ""); + if (strTemp == "") { + curNode = curNode->next->next; + } + } + } else { + curNode = curNode->next; + } } \ No newline at end of file diff --git a/convertxml/js_convertxml.h b/convertxml/js_convertxml.h index a44b731c..380fab06 100755 --- a/convertxml/js_convertxml.h +++ b/convertxml/js_convertxml.h @@ -30,33 +30,41 @@ enum class SpaceType { }; struct Options { - std::string declaration = "_declaration"; - std::string instruction = "_instruction"; - std::string attributes = "_attributes"; - std::string text = "_text"; - std::string cdata = "_cdata"; - std::string doctype = "_doctype"; - std::string comment = "_comment"; - std::string parent = "_parent"; - std::string type = "_type"; - std::string name = "_name"; - std::string elements = "_elements"; - bool compact = false; - bool trim = false; - bool nativetype = false; - bool nativetypeattributes = false; - bool addparent = false; - bool alwaysArray = false; - bool alwaysChildren = false; - bool instructionHasAttributes = false; - bool ignoreDeclaration = false; - bool ignoreInstruction = false; - bool ignoreAttributes = false; - bool ignoreComment = false; - bool ignoreCdata = false; - bool ignoreDoctype = false; - bool ignoreText = false; - bool spaces = false; + std::string declaration = "_declaration"; + std::string instruction = "_instruction"; + std::string attributes = "_attributes"; + std::string text = "_text"; + std::string cdata = "_cdata"; + std::string doctype = "_doctype"; + std::string comment = "_comment"; + std::string parent = "_parent"; + std::string type = "_type"; + std::string name = "_name"; + std::string elements = "_elements"; + bool compact = false; + bool trim = false; + bool nativetype = false; + bool nativetypeattributes = false; + bool addparent = false; + bool alwaysArray = false; + bool alwaysChildren = false; + bool instructionHasAttributes = false; + bool ignoreDeclaration = false; + bool ignoreInstruction = false; + bool ignoreAttributes = false; + bool ignoreComment = false; + bool ignoreCdata = false; + bool ignoreDoctype = false; + bool ignoreText = false; + bool spaces = false; +}; + +struct XmlInfo { + bool bXml = false; + bool bVersion = false; + std::string strVersion = ""; + bool bEncoding = false; + std::string strEncoding = ""; }; class ConvertXml { @@ -80,6 +88,10 @@ public: void SetPrevInfo(napi_value &recvElement, int flag, int32_t &index1); void SetDefaultKey(size_t i, std::string strRecv); void SetSpacesInfo(napi_value &object); + void DealSingleLine(std::string &strXml, napi_value &object); + void DealComplex(std::string &strXml, napi_value &object); + void Replace(std::string &str, const std::string src, const std::string dst); + void DealCDataInfo(bool bCData, xmlNodePtr &curNode); private: napi_env env_; SpaceType m_SpaceType; @@ -87,5 +99,6 @@ private: std::string m_strSpace; Options m_Options; std::vector m_prevObj; + XmlInfo m_XmlInfo; }; #endif \ No newline at end of file diff --git a/convertxml/js_convertxml.js b/convertxml/js_convertxml.js index 3b6b5ba2..e045ea7a 100755 --- a/convertxml/js_convertxml.js +++ b/convertxml/js_convertxml.js @@ -28,32 +28,81 @@ class ConvertXml { space = converted.spaces; delete converted.spaces; } - return JSON.stringify(converted, null, space); + var strEnd = JSON.stringify(converted, null, space); + var idx = 0; + while ((idx = strEnd.indexOf('\\t')) != -1) { + strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\n')) != -1) { + strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\')) != -1) { + strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); + } + return strEnd; } } function DealXml(strXml) { - var idx = -1; + var idx = 0; var idxSec = 0; var idxThir = 0; var idxCData = 0; var idxCDataSec = 0; + while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { idxThir = strXml.indexOf('<', idx); - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i); - if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') - { - break; + strXml = DealReplace(strXml, idx, idxThir); + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf('', idxCData); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i) + switch (cXml) { + case '\n': + strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); + break; + case '\v': + strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); + break; + case '\t': + strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); + break; + default: + break; + } + } + idxCDataSec = idxSec; } } - var j = idx + 1; - for (; j < strXml.indexOf('<', idx) ; j++) { - var cXml = strXml.charAt(j); - if (i != idxThir) { - switch (cXml) { + else { + break; + } + } + return strXml; +} + +function DealReplace(strXml, idx, idxThir) +{ + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { case '\n': strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); break; @@ -63,22 +112,12 @@ function DealXml(strXml) case '\t': strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); break; - } - } else { - strXml = strXml.substring(0, j) + strXml.substring(j + 1); - --j; - } - } - if (strXml.indexOf('<', idx) != -1) { - idxCData = strXml.indexOf('', idxSec)) != -1) { + idxThir = strXml.indexOf('<', idx); + strXml = DealReplace(strXml, idx, idxThir); + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf('', idxCData); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i) + switch (cXml) { + case '\n': + strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); + break; + case '\v': + strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); + break; + case '\t': + strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); + break; + default: + break; + } + } + idxCDataSec = idxSec; + } + } + else { + break; + } + } + return strXml; +} + +function DealReplace(strXml : string, idx : any, idxThir : any) +{ + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { + case '\n': + strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); + break; + case '\v': + strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); + break; + case '\t': + strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); + break; + default: + break; + } + } else { + strXml = strXml.substring(0, j) + strXml.substring(j + 1); + --j; + } + } + return strXml; +} + +export default { + ConvertXml : ConvertXml +} + + diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json new file mode 100644 index 00000000..e61c432f --- /dev/null +++ b/convertxml/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} -- Gitee From 4079228e11559bef430c4a320175dcea41dbefd8 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 16:10:16 +0800 Subject: [PATCH 07/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn deleted: convertxml/build_ts_js.py modified: convertxml/js_convertxml.cpp deleted: convertxml/src/js_convertxml.ts deleted: convertxml/tsconfig.json --- convertxml/BUILD.gn | 10 +-- convertxml/build_ts_js.py | 21 ------ convertxml/js_convertxml.cpp | 16 ++-- convertxml/src/js_convertxml.ts | 130 -------------------------------- convertxml/tsconfig.json | 14 ---- 5 files changed, 10 insertions(+), 181 deletions(-) delete mode 100644 convertxml/build_ts_js.py delete mode 100644 convertxml/src/js_convertxml.ts delete mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index da283f8a..a2ac7c53 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -14,19 +14,11 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") -action("build_ts_js") { - script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" - depfile = "$target_gen_dir/$target_name.d" - outputs = [target_out_dir + "/js_convertxml.js" - ] -} - base_output_path = get_label_info(":js_convertxml", "target_out_dir") js_xml_obj_path = base_output_path + "/convertxml.o" gen_js_obj("js_convertxml") { - input = "$target_out_dir/js_convertxml.js" + input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" output = js_xml_obj_path - dep = ":build_ts_js" } ohos_shared_library("convertxml") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py deleted file mode 100644 index 76b3fb1d..00000000 --- a/convertxml/build_ts_js.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os - -if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) - os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 65a40944..2013decb 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -86,7 +86,7 @@ std::string ConvertXml::Trim(std::string strXmltrim) } size_t i = 0; size_t strlen = strXmltrim.size(); - for (; i < strlen;) { + for (; i < strlen; ) { if (strXmltrim[i] == ' ') { i++; } else { @@ -467,7 +467,7 @@ void ConvertXml::DealOptions(napi_value napi_obj) DealSpaces(napi_obj); } -void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) +void ConvertXml::DealSingleLine(std::string &strXml,napi_value &object) { size_t iXml = 0; if ((iXml = strXml.find("xml")) != std::string::npos) { @@ -499,6 +499,7 @@ void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); } } + size_t iCount = 0; size_t iLen = strXml.size(); for (; iCount < iLen; ++iCount) { @@ -568,11 +569,12 @@ void ConvertXml::DealCDataInfo(bool bCData, xmlNodePtr &curNode) curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { if (xmlNodeGetContent(curNode->next) != nullptr) { std::string strTemp = (char*)xmlNodeGetContent(curNode->next); - Replace(strTemp, " ", ""); - Replace(strTemp, "\v", ""); - Replace(strTemp, "\t", ""); - Replace(strTemp, "\n", ""); - if (strTemp == "") { + Replace(strTemp, " ",""); + Replace(strTemp, "\v",""); + Replace(strTemp, "\t",""); + Replace(strTemp, "\n",""); + if (strTemp == "") + { curNode = curNode->next->next; } } diff --git a/convertxml/src/js_convertxml.ts b/convertxml/src/js_convertxml.ts deleted file mode 100644 index 93ebb980..00000000 --- a/convertxml/src/js_convertxml.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -declare function requireInternal(s : string) : any; -const convertXml = requireInternal("ConvertXML"); -class ConvertXml { - convertxmlclass; - constructor() { - this.convertxmlclass = new convertXml.ConvertXml(); - } - convert(strXml : string, options : any) { - strXml = DealXml(strXml); - let converted = this.convertxmlclass.convert(strXml, options); - let space = 0; - if (converted.hasOwnProperty("spaces")) { - space = converted.spaces; - delete converted.spaces; - } - var strEnd = JSON.stringify(converted, null, space); - var idx = 0; - while ((idx = strEnd.indexOf('\\t')) != -1) { - strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); - } - while ((idx = strEnd.indexOf('\\n')) != -1) { - strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); - } - while ((idx = strEnd.indexOf('\\')) != -1) { - strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); - } - return strEnd; - } -} - -function DealXml(strXml : string) -{ - var idx = 0; - var idxSec = 0; - var idxThir = 0; - var idxCData = 0; - var idxCDataSec = 0; - while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { - idxThir = strXml.indexOf('<', idx); - strXml = DealReplace(strXml, idx, idxThir); - if (strXml.indexOf('<', idx) != -1) { - idxCData = strXml.indexOf('', idxCData); - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i) - switch (cXml) { - case '\n': - strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); - break; - case '\v': - strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); - break; - case '\t': - strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); - break; - default: - break; - } - } - idxCDataSec = idxSec; - } - } - else { - break; - } - } - return strXml; -} - -function DealReplace(strXml : string, idx : any, idxThir : any) -{ - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i); - if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') - { - break; - } - } - var j = idx + 1; - for (; j < strXml.indexOf('<', idx) ; j++) { - var cXml = strXml.charAt(j); - if (i != idxThir) { - switch (cXml) { - case '\n': - strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); - break; - case '\v': - strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); - break; - case '\t': - strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); - break; - default: - break; - } - } else { - strXml = strXml.substring(0, j) + strXml.substring(j + 1); - --j; - } - } - return strXml; -} - -export default { - ConvertXml : ConvertXml -} - - diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json deleted file mode 100644 index e61c432f..00000000 --- a/convertxml/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ -"compilerOptions": { - "target": "es6", - "module": "es6", - "rootDir": "./src", - //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "noImplicitThis": false, - } -} -- Gitee From e2baadf8d278041261dd905279e2060d0fc48a80 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 16:12:54 +0800 Subject: [PATCH 08/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/js_convertxml.cpp --- convertxml/js_convertxml.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 2013decb..65a40944 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -86,7 +86,7 @@ std::string ConvertXml::Trim(std::string strXmltrim) } size_t i = 0; size_t strlen = strXmltrim.size(); - for (; i < strlen; ) { + for (; i < strlen;) { if (strXmltrim[i] == ' ') { i++; } else { @@ -467,7 +467,7 @@ void ConvertXml::DealOptions(napi_value napi_obj) DealSpaces(napi_obj); } -void ConvertXml::DealSingleLine(std::string &strXml,napi_value &object) +void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) { size_t iXml = 0; if ((iXml = strXml.find("xml")) != std::string::npos) { @@ -499,7 +499,6 @@ void ConvertXml::DealSingleLine(std::string &strXml,napi_value &object) strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); } } - size_t iCount = 0; size_t iLen = strXml.size(); for (; iCount < iLen; ++iCount) { @@ -569,12 +568,11 @@ void ConvertXml::DealCDataInfo(bool bCData, xmlNodePtr &curNode) curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { if (xmlNodeGetContent(curNode->next) != nullptr) { std::string strTemp = (char*)xmlNodeGetContent(curNode->next); - Replace(strTemp, " ",""); - Replace(strTemp, "\v",""); - Replace(strTemp, "\t",""); - Replace(strTemp, "\n",""); - if (strTemp == "") - { + Replace(strTemp, " ", ""); + Replace(strTemp, "\v", ""); + Replace(strTemp, "\t", ""); + Replace(strTemp, "\n", ""); + if (strTemp == "") { curNode = curNode->next->next; } } -- Gitee From 668d1c01bdead0a3f9bdee7f89b93c2ab3f20320 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 20:37:50 +0800 Subject: [PATCH 09/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn modified: convertxml/native_module_convertxml.cpp modified: uri/BUILD.gn modified: uri/native_module_uri.cpp modified: url/BUILD.gn modified: url/native_module_url.cpp --- convertxml/BUILD.gn | 36 +++++++++++++++++++++++++ convertxml/native_module_convertxml.cpp | 12 +++++++++ uri/BUILD.gn | 35 +++++++++++++++++++++++- uri/native_module_uri.cpp | 12 +++++++++ url/BUILD.gn | 35 +++++++++++++++++++++++- url/native_module_url.cpp | 26 +++++++++++++----- 6 files changed, 147 insertions(+), 9 deletions(-) diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index a2ac7c53..2eb33223 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -11,16 +11,51 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_convertxml_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path( + "//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), + "--dst-file", + rebase_path(target_out_dir + "/convertxml.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + + inputs = [ "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" ] + outputs = [ target_out_dir + "/convertxml.abc" ] +} base_output_path = get_label_info(":js_convertxml", "target_out_dir") js_xml_obj_path = base_output_path + "/convertxml.o" + gen_js_obj("js_convertxml") { input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" output = js_xml_obj_path } +abc_output_path = get_label_info(":convertxml_abc", "target_out_dir") +convertxml_abc_obj_path = abc_output_path + "/convertxml_abc.o" +gen_js_obj("convertxml_abc") { + input = "$target_out_dir/convertxml.abc" + output = convertxml_abc_obj_path + dep = ":gen_convertxml_abc" +} + ohos_shared_library("convertxml") { include_dirs = [ "//third_party/icu/icu4c/source/common", @@ -36,6 +71,7 @@ ohos_shared_library("convertxml") { ] deps = [ + ":convertxml_abc", ":js_convertxml", "//base/compileruntime/js_api_module/convertxml/:js_convertxml", "//foundation/ace/napi/:ace_napi", diff --git a/convertxml/native_module_convertxml.cpp b/convertxml/native_module_convertxml.cpp index cfca087e..05ca3943 100755 --- a/convertxml/native_module_convertxml.cpp +++ b/convertxml/native_module_convertxml.cpp @@ -19,6 +19,8 @@ extern const char _binary_js_convertxml_js_start[]; extern const char _binary_js_convertxml_js_end[]; +extern const char _binary_convertxml_abc_start[]; +extern const char _binary_convertxml_abc_end[]; static napi_value ConvertXmlConstructor(napi_env env, napi_callback_info info) { @@ -95,6 +97,16 @@ __attribute__((visibility("default"))) void NAPI_convertxml_GetJSCode(const char *bufLen = _binary_js_convertxml_js_end - _binary_js_convertxml_js_start; } } +extern "C" +__attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) +{ + if (buf != nullptr) { + *buf = _binary_convertxml_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_convertxml_abc_end - _binary_convertxml_abc_start; + } +} static napi_module ConvertXmlModule = { .nm_version = 1, diff --git a/uri/BUILD.gn b/uri/BUILD.gn index 0249e7a3..b0b2ca30 100755 --- a/uri/BUILD.gn +++ b/uri/BUILD.gn @@ -10,9 +10,41 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_uri_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path("//base/compileruntime/js_api_module/uri/js_uri.js"), + "--dst-file", + rebase_path(target_out_dir + "/uri.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build"] + + inputs = [ "//base/compileruntime/js_api_module/uri/js_uri.js" ] + outputs = [ target_out_dir + "/uri.abc" ] +} + +abc_output_path = get_label_info(":uri_abc", "target_out_dir") +uri_abc_obj_path = abc_output_path + "/uri_abc.o" +gen_js_obj("uri_abc") { + input = "$target_out_dir/uri.abc" + output = uri_abc_obj_path + dep = ":gen_uri_abc" +} base_output_path = get_label_info(":js_uri", "target_out_dir") js_uri_obj_path = base_output_path + "/uri.o" @@ -35,6 +67,7 @@ ohos_shared_library("uri") { ] deps = [ + ":uri_abc", ":js_uri", "//base/compileruntime/js_api_module/uri/:js_uri", "//foundation/ace/napi/:ace_napi", diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index c0ee394a..54320f86 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -21,6 +21,8 @@ extern const char _binary_js_uri_js_start[]; extern const char _binary_js_uri_js_end[]; +extern const char _binary_uri_abc_start[]; +extern const char _binary_uri_abc_end[]; namespace OHOS::Uri { static napi_value UriConstructor(napi_env env, napi_callback_info info) { @@ -283,6 +285,16 @@ namespace OHOS::Uri { *bufLen = _binary_js_uri_js_end - _binary_js_uri_js_start; } } + extern "C" + __attribute__((visibility("default"))) void NAPI_uri_GetABCCode(const char** buf, int* buflen) + { + if (buf != nullptr) { + *buf = _binary_uri_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_uri_abc_end - _binary_uri_abc_start; + } + } static napi_module UriModule = { .nm_version = 1, diff --git a/url/BUILD.gn b/url/BUILD.gn index 5e8d16fa..0a65834b 100755 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -10,9 +10,41 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_url_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path("//base/compileruntime/js_api_module/url/js_url.js"), + "--dst-file", + rebase_path(target_out_dir + "/url.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build"] + + inputs = [ "//base/compileruntime/js_api_module/url/js_url.js" ] + outputs = [ target_out_dir + "/url.abc" ] +} + +abc_output_path = get_label_info(":url_abc", "target_out_dir") +url_abc_obj_path = abc_output_path + "/url_abc.o" +gen_js_obj("url_abc") { + input = "$target_out_dir/url.abc" + output = url_abc_obj_path + dep = ":gen_url_abc" +} base_output_path = get_label_info(":js_url", "target_out_dir") js_url_obj_path = base_output_path + "/url.o" @@ -35,6 +67,7 @@ ohos_shared_library("url") { ] deps = [ + ":url_abc", ":js_url", "//base/compileruntime/js_api_module/url/:js_url", "//foundation/ace/napi/:ace_napi", diff --git a/url/native_module_url.cpp b/url/native_module_url.cpp index 61497a76..e80ab108 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -20,6 +20,8 @@ extern const char _binary_js_url_js_start[]; extern const char _binary_js_url_js_end[]; +extern const char _binary_url_abc_start[]; +extern const char _binary_url_abc_end[]; namespace OHOS::Url { static void UrlStructor(napi_env &env, napi_callback_info &info, URL *&object) { @@ -29,8 +31,8 @@ namespace OHOS::Url { void *data = nullptr; napi_get_cb_info(env, info, &argc, nullptr, &thisVar, &data); napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - napi_valuetype valuetype1 = napi_null; - napi_valuetype valuetype2 = napi_null; + napi_valuetype valuetype1; + napi_valuetype valuetype2; std::string input = ""; napi_typeof(env, argv[0], &valuetype1); if (valuetype1 == napi_string) { @@ -80,7 +82,7 @@ namespace OHOS::Url { if (argc == 1) { std::string input = ""; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); - napi_valuetype valuetype = napi_null; + napi_valuetype valuetype; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype == napi_string) { char *type = nullptr; @@ -102,9 +104,9 @@ namespace OHOS::Url { napi_wrap( env, thisVar, object, [](napi_env env, void *data, void *hint) { - auto obj = (URL*)data; - if (obj != nullptr) { - delete obj; + auto object = (URL*)data; + if (object != nullptr) { + delete object; } }, nullptr, nullptr); @@ -884,7 +886,7 @@ namespace OHOS::Url { DECLARE_NAPI_GETTER("GetIsIpv6", GetIsIpv6), }; NAPI_CALL(env, napi_define_class(env, urlClassName, strlen(urlClassName), UrlConstructor, - nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); + nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Url", urlClass) }; @@ -914,6 +916,16 @@ namespace OHOS::Url { *bufLen = _binary_js_url_js_end - _binary_js_url_js_start; } } + extern "C" + __attribute__((visibility("default"))) void NAPI_url_GetABCCode(const char** buf, int* buflen) + { + if (buf != nullptr) { + *buf = _binary_url_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_url_abc_end - _binary_url_abc_start; + } + } static napi_module UrlModule = { .nm_version = 1, -- Gitee From e3cb8d090a6c242f80f5f935b2b37c4b4ae4f8d9 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 20:48:12 +0800 Subject: [PATCH 10/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn modified: uri/BUILD.gn new file: uri/build_ts_js.py modified: uri/js_uri.cpp modified: uri/js_uri.h modified: uri/native_module_uri.cpp renamed: uri/js_uri.js -> uri/src/js_uri.ts new file: uri/tsconfig.json modified: url/BUILD.gn --- convertxml/BUILD.gn | 3 +- uri/BUILD.gn | 30 +++-- uri/build_ts_js.py | 21 ++++ uri/js_uri.cpp | 24 ++-- uri/js_uri.h | 16 +-- uri/native_module_uri.cpp | 34 +++-- uri/{js_uri.js => src/js_uri.ts} | 205 +++++++++++++++---------------- uri/tsconfig.json | 14 +++ url/BUILD.gn | 1 - 9 files changed, 192 insertions(+), 156 deletions(-) create mode 100644 uri/build_ts_js.py rename uri/{js_uri.js => src/js_uri.ts} (85%) mode change 100755 => 100644 create mode 100644 uri/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index 2eb33223..ebace873 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -23,8 +23,7 @@ action("gen_convertxml_abc") { args = [ "--src-js", - rebase_path( - "//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), + rebase_path("//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), "--dst-file", rebase_path(target_out_dir + "/convertxml.abc"), "--node", diff --git a/uri/BUILD.gn b/uri/BUILD.gn index b0b2ca30..be1eeae5 100755 --- a/uri/BUILD.gn +++ b/uri/BUILD.gn @@ -15,6 +15,22 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") +# compile .ts to .js. +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/uri/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [target_out_dir + "/js_uri.js" + ] +} + +base_output_path = get_label_info(":js_uri", "target_out_dir") +js_uri_obj_path = base_output_path + "/uri.o" +gen_js_obj("js_uri") { + input = "$target_out_dir/js_uri.js" + output = js_uri_obj_path + dep = ":build_ts_js" +} + # compile .js to .abc. action("gen_uri_abc") { visibility = [ ":*" ] @@ -22,7 +38,7 @@ action("gen_uri_abc") { args = [ "--src-js", - rebase_path("//base/compileruntime/js_api_module/uri/js_uri.js"), + rebase_path(target_out_dir + "/js_uri.js"), "--dst-file", rebase_path(target_out_dir + "/uri.abc"), "--node", @@ -32,9 +48,10 @@ action("gen_uri_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build"] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" , + ":build_ts_js" ] - inputs = [ "//base/compileruntime/js_api_module/uri/js_uri.js" ] + inputs = [ target_out_dir+"/js_uri.js" ] outputs = [ target_out_dir + "/uri.abc" ] } @@ -46,13 +63,6 @@ gen_js_obj("uri_abc") { dep = ":gen_uri_abc" } -base_output_path = get_label_info(":js_uri", "target_out_dir") -js_uri_obj_path = base_output_path + "/uri.o" -gen_js_obj("js_uri") { - input = "//base/compileruntime/js_api_module/uri/js_uri.js" - output = js_uri_obj_path -} - ohos_shared_library("uri") { include_dirs = [ "//third_party/icu/icu4c/source/common", diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py new file mode 100644 index 00000000..27024303 --- /dev/null +++ b/uri/build_ts_js.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/uri" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/uri/js_uri.cpp b/uri/js_uri.cpp index 34452121..b6e7de17 100755 --- a/uri/js_uri.cpp +++ b/uri/js_uri.cpp @@ -15,15 +15,15 @@ #include "js_uri.h" #include "utils/log.h" namespace OHOS::Uri { - std::bitset g_ruleAlpha; - std::bitset g_ruleScheme; - std::bitset g_ruleUrlc; - std::bitset g_rulePath; - std::bitset g_ruleUserInfo; - std::bitset g_ruleScope; - std::bitset g_ruleDigit; - std::bitset g_rulePort; - void Uri::PreliminaryWork() const + std::bitset g_ruleAlpha; + std::bitset g_ruleScheme; + std::bitset g_ruleUrlc; + std::bitset g_rulePath; + std::bitset g_ruleUserInfo; + std::bitset g_ruleScope; + std::bitset g_ruleDigit; + std::bitset g_rulePort; + void Uri::PreliminaryWork() { std::string digitAggregate = "0123456789"; for (size_t i = 0; i < digitAggregate.size(); ++i) { @@ -129,11 +129,11 @@ namespace OHOS::Uri { } } - bool Uri::CheckCharacter(std::string data, std::bitset rule, bool flag) const + bool Uri::CheckCharacter(std::string data, std::bitset rule, bool flag) { size_t dataLen = data.size(); for (size_t i = 0; i < dataLen; ++i) { - if (data[i] >= 0 && data[i] < 128) { // 128:Maximum value of char + if (data[i] >= 0 && data[i] < 128) { // 128:Number of ASCII characters bool isLegal = rule.test(data[i]); if (!isLegal) { return false; @@ -255,7 +255,7 @@ namespace OHOS::Uri { } } else { // ipv4 - if (!isLawfulProt || !AnalysisIPV4()) { + if (!isLawfulProt | !AnalysisIPV4()) { uriData_.port = -1; uriData_.host = ""; uriData_.userInfo = ""; diff --git a/uri/js_uri.h b/uri/js_uri.h index 16365f83..923be07f 100755 --- a/uri/js_uri.h +++ b/uri/js_uri.h @@ -16,17 +16,17 @@ #ifndef COMPILERUNTIME_JS_API_URI_H #define COMPILERUNTIME_JS_API_URI_H -#include -#include -#include #include #include +#include +#include +#include +#include #include "napi/native_api.h" #include "napi/native_node_api.h" - namespace OHOS::Uri { constexpr int MAX_BIT_SIZE = 128; - struct UriData { + struct uri_data { int port = -1; std::string scheme = ""; std::string userInfo = ""; @@ -59,7 +59,7 @@ namespace OHOS::Uri { std::string GetQuery() const; std::string GetFragment() const; private: - void PreliminaryWork() const; + void PreliminaryWork(); void AnalysisUri(); void SpecialPath(); void AnalysisFragment(size_t pos); @@ -70,13 +70,13 @@ namespace OHOS::Uri { void AnalysisUserInfo(size_t pos); void AnalysisIPV6(); - bool CheckCharacter(std::string data, std::bitset rule, bool flag) const; + bool CheckCharacter(std::string data, std::bitset rule, bool flag); bool AnalysisPort(size_t pos); bool AnalysisIPV4(); std::string Split(std::string path) const; private: - UriData uriData_; + uri_data uriData_; std::string data_; std::string inputUri_; std::string errStr_; diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index 54320f86..91581781 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -13,17 +13,17 @@ * limitations under the License. */ - -#include "js_uri.h" -#include "utils/log.h" #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "js_uri.h" +#include "utils/log.h" extern const char _binary_js_uri_js_start[]; extern const char _binary_js_uri_js_end[]; extern const char _binary_uri_abc_start[]; extern const char _binary_uri_abc_end[]; namespace OHOS::Uri { + napi_value g_uriClass = nullptr; static napi_value UriConstructor(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -36,24 +36,20 @@ namespace OHOS::Uri { NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype == napi_string) { char *type = nullptr; - std::string input = ""; size_t typelen = 0; NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typelen)); - if (typelen > 0) { - type = new char[typelen + 1]; - NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], type, typelen + 1, &typelen)); - input = type; - delete[] type; - } - object = new Uri(env, input); + type = new char[typelen + 1]; + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], type, typelen + 1, &typelen)); + object = new Uri(env, type); + delete[] type; } else { napi_throw_error(env, nullptr, "parameter type is error"); } NAPI_CALL(env, napi_wrap(env, thisVar, object, [](napi_env env, void *data, void *hint) { - auto obj = (Uri*)data; - if (obj != nullptr) { - delete obj; + auto object = (Uri*)data; + if (object != nullptr) { + delete object; } }, nullptr, nullptr)); return thisVar; @@ -66,9 +62,11 @@ namespace OHOS::Uri { Uri *muri = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); std::string normalizeUri = muri->Normalize(); + size_t argc = 1; + napi_value args[1] = { 0 }; napi_value result = nullptr; - size_t tempLen = normalizeUri.size(); - NAPI_CALL(env, napi_create_string_utf8(env, normalizeUri.c_str(), tempLen, &result)); + NAPI_CALL(env, napi_create_string_utf8(env, normalizeUri.c_str(), normalizeUri.size(), args)); + NAPI_CALL(env, napi_new_instance(env, g_uriClass, argc, args, &result)); return result; } @@ -266,7 +264,8 @@ namespace OHOS::Uri { DECLARE_NAPI_GETTER("isFailed", IsFailed), }; NAPI_CALL(env, napi_define_class(env, uriClassName, strlen(uriClassName), UriConstructor, - nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); + nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); + g_uriClass = uriClass; static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Uri", uriClass) }; @@ -295,7 +294,6 @@ namespace OHOS::Uri { *buflen = _binary_uri_abc_end - _binary_uri_abc_start; } } - static napi_module UriModule = { .nm_version = 1, .nm_flags = 0, diff --git a/uri/js_uri.js b/uri/src/js_uri.ts old mode 100755 new mode 100644 similarity index 85% rename from uri/js_uri.js rename to uri/src/js_uri.ts index d2603eef..f94da8a9 --- a/uri/js_uri.js +++ b/uri/src/js_uri.ts @@ -1,105 +1,100 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; -const uri = requireInternal("uri"); - -class URI { - constructor(input) { - if (typeof input !== 'string' || input.length === 0) { - throw new Error("input type err"); - } - this.uricalss = new uri.Uri(input); - let errStr = this.uricalss.isFailed; - if (errStr.length !== 0) { - throw new Error(errStr); - } - } - toString() { - return toAscllString(this.uricalss.toString()); - } - - equals(other) { - return this.uricalss.equals(other.uricalss); - } - - isAbsolute() { - return this.uricalss.isAbsolute(); - } - - normalize() { - let uriStr = this.uricalss.normalize(); - return createNewUri(uriStr); - } - - get scheme() { - return this.uricalss.scheme; - } - - get authority() { - return this.uricalss.authority; - } - - get ssp() { - return this.uricalss.ssp; - } - - get userinfo() { - return this.uricalss.userinfo; - } - - get host() { - return this.uricalss.host; - } - - get port() { - return this.uricalss.port; - } - - get path() { - return this.uricalss.path; - } - - get query() { - return this.uricalss.query; - } - - get fragment() { - return this.uricalss.fragment; - } - -} - -function toAscllString(uriStr) { - if (uriStr.indexOf('[') !== -1) { - let arr = uriStr.split("["); - let brr = arr[1].split("]"); - arr[1] = '[' + brr[0] + ']'; - arr[2] = brr[1]; - arr[0] = encodeURI(arr[0]); - arr[2] = encodeURI(arr[2]); - return arr.join(''); - } else { - return encodeURI(uriStr); - } -} - -function createNewUri(uriStr) { - return new URI(uriStr); -} - -export default { - URI: URI, -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +declare function requireInternal(s : string) : any; +const uri = requireInternal("uri"); + +class URI { + uricalss : any + constructor(input:any) { + if (typeof input !== 'string' || input.length === 0) { + throw new Error("input type err"); + } + this.uricalss = new uri.Uri(input); + let errStr = this.uricalss.isFailed; + if (errStr.length !== 0) { + throw new Error(errStr); + } + } + toString() { + return toAscllString(this.uricalss.toString()); + } + + equals(other:any) { + return this.uricalss.equals(other.uricalss); + } + + isAbsolute() { + return this.uricalss.isAbsolute(); + } + + normalize() { + return this.uricalss.normalize(); + } + + get scheme() { + return this.uricalss.scheme; + } + + get authority() { + return this.uricalss.authority; + } + + get ssp() { + return this.uricalss.ssp; + } + + get userinfo() { + return this.uricalss.userinfo; + } + + get host() { + return this.uricalss.host; + } + + get port() { + return this.uricalss.port; + } + + get path() { + return this.uricalss.path; + } + + get query() { + return this.uricalss.query; + } + + get fragment() { + return this.uricalss.fragment; + } + +} + +function toAscllString(uriStr:any) { + if (uriStr.indexOf('[') !== -1) { + let arr = uriStr.split("["); + let brr = arr[1].split("]"); + arr[1] = '[' + brr[0] + ']'; + arr[2] = brr[1]; + arr[0] = encodeURI(arr[0]); + arr[2] = encodeURI(arr[2]); + return arr.join(''); + } else { + return encodeURI(uriStr); + } +} + +export default { + URI: URI, +} diff --git a/uri/tsconfig.json b/uri/tsconfig.json new file mode 100644 index 00000000..f8212040 --- /dev/null +++ b/uri/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/uri/", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} diff --git a/url/BUILD.gn b/url/BUILD.gn index 0a65834b..920d024a 100755 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -67,7 +67,6 @@ ohos_shared_library("url") { ] deps = [ - ":url_abc", ":js_url", "//base/compileruntime/js_api_module/url/:js_url", "//foundation/ace/napi/:ace_napi", -- Gitee From dab2e6f6deb482527b887380fd4b91a672516db1 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Sun, 26 Sep 2021 22:23:30 +0800 Subject: [PATCH 11/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: uri/BUILD.gn deleted: uri/build_ts_js.py modified: uri/js_uri.cpp modified: uri/js_uri.h renamed: uri/src/js_uri.ts -> uri/js_uri.js modified: uri/native_module_uri.cpp deleted: uri/tsconfig.json modified: url/BUILD.gn modified: url/native_module_url.cpp --- uri/BUILD.gn | 33 +++++++++++-------------------- uri/build_ts_js.py | 21 -------------------- uri/js_uri.cpp | 24 +++++++++++----------- uri/js_uri.h | 16 +++++++-------- uri/{src/js_uri.ts => js_uri.js} | 17 ++++++++++------ uri/native_module_uri.cpp | 34 +++++++++++++++++--------------- uri/tsconfig.json | 14 ------------- url/BUILD.gn | 3 ++- url/native_module_url.cpp | 15 +++++++------- 9 files changed, 69 insertions(+), 108 deletions(-) delete mode 100644 uri/build_ts_js.py rename uri/{src/js_uri.ts => js_uri.js} (89%) delete mode 100644 uri/tsconfig.json diff --git a/uri/BUILD.gn b/uri/BUILD.gn index be1eeae5..8d84a14e 100755 --- a/uri/BUILD.gn +++ b/uri/BUILD.gn @@ -15,22 +15,6 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") -# compile .ts to .js. -action("build_ts_js") { - script = "//base/compileruntime/js_api_module/uri/build_ts_js.py" - depfile = "$target_gen_dir/$target_name.d" - outputs = [target_out_dir + "/js_uri.js" - ] -} - -base_output_path = get_label_info(":js_uri", "target_out_dir") -js_uri_obj_path = base_output_path + "/uri.o" -gen_js_obj("js_uri") { - input = "$target_out_dir/js_uri.js" - output = js_uri_obj_path - dep = ":build_ts_js" -} - # compile .js to .abc. action("gen_uri_abc") { visibility = [ ":*" ] @@ -38,7 +22,7 @@ action("gen_uri_abc") { args = [ "--src-js", - rebase_path(target_out_dir + "/js_uri.js"), + rebase_path("//base/compileruntime/js_api_module/uri/js_uri.js"), "--dst-file", rebase_path(target_out_dir + "/uri.abc"), "--node", @@ -48,10 +32,9 @@ action("gen_uri_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" , - ":build_ts_js" ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] - inputs = [ target_out_dir+"/js_uri.js" ] + inputs = [ "//base/compileruntime/js_api_module/uri/js_uri.js" ] outputs = [ target_out_dir + "/uri.abc" ] } @@ -63,6 +46,13 @@ gen_js_obj("uri_abc") { dep = ":gen_uri_abc" } +base_output_path = get_label_info(":js_uri", "target_out_dir") +js_uri_obj_path = base_output_path + "/uri.o" +gen_js_obj("js_uri") { + input = "//base/compileruntime/js_api_module/uri/js_uri.js" + output = js_uri_obj_path +} + ohos_shared_library("uri") { include_dirs = [ "//third_party/icu/icu4c/source/common", @@ -77,8 +67,8 @@ ohos_shared_library("uri") { ] deps = [ - ":uri_abc", ":js_uri", + ":uri_abc", "//base/compileruntime/js_api_module/uri/:js_uri", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", @@ -100,4 +90,3 @@ ohos_shared_library("uri") { group("uri_packages") { deps = [ ":uri" ] } - diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py deleted file mode 100644 index 27024303..00000000 --- a/uri/build_ts_js.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os - -if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/uri" % build_path) - os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/uri/js_uri.cpp b/uri/js_uri.cpp index b6e7de17..34452121 100755 --- a/uri/js_uri.cpp +++ b/uri/js_uri.cpp @@ -15,15 +15,15 @@ #include "js_uri.h" #include "utils/log.h" namespace OHOS::Uri { - std::bitset g_ruleAlpha; - std::bitset g_ruleScheme; - std::bitset g_ruleUrlc; - std::bitset g_rulePath; - std::bitset g_ruleUserInfo; - std::bitset g_ruleScope; - std::bitset g_ruleDigit; - std::bitset g_rulePort; - void Uri::PreliminaryWork() + std::bitset g_ruleAlpha; + std::bitset g_ruleScheme; + std::bitset g_ruleUrlc; + std::bitset g_rulePath; + std::bitset g_ruleUserInfo; + std::bitset g_ruleScope; + std::bitset g_ruleDigit; + std::bitset g_rulePort; + void Uri::PreliminaryWork() const { std::string digitAggregate = "0123456789"; for (size_t i = 0; i < digitAggregate.size(); ++i) { @@ -129,11 +129,11 @@ namespace OHOS::Uri { } } - bool Uri::CheckCharacter(std::string data, std::bitset rule, bool flag) + bool Uri::CheckCharacter(std::string data, std::bitset rule, bool flag) const { size_t dataLen = data.size(); for (size_t i = 0; i < dataLen; ++i) { - if (data[i] >= 0 && data[i] < 128) { // 128:Number of ASCII characters + if (data[i] >= 0 && data[i] < 128) { // 128:Maximum value of char bool isLegal = rule.test(data[i]); if (!isLegal) { return false; @@ -255,7 +255,7 @@ namespace OHOS::Uri { } } else { // ipv4 - if (!isLawfulProt | !AnalysisIPV4()) { + if (!isLawfulProt || !AnalysisIPV4()) { uriData_.port = -1; uriData_.host = ""; uriData_.userInfo = ""; diff --git a/uri/js_uri.h b/uri/js_uri.h index 923be07f..16365f83 100755 --- a/uri/js_uri.h +++ b/uri/js_uri.h @@ -16,17 +16,17 @@ #ifndef COMPILERUNTIME_JS_API_URI_H #define COMPILERUNTIME_JS_API_URI_H -#include -#include -#include #include -#include #include +#include +#include +#include #include "napi/native_api.h" #include "napi/native_node_api.h" + namespace OHOS::Uri { constexpr int MAX_BIT_SIZE = 128; - struct uri_data { + struct UriData { int port = -1; std::string scheme = ""; std::string userInfo = ""; @@ -59,7 +59,7 @@ namespace OHOS::Uri { std::string GetQuery() const; std::string GetFragment() const; private: - void PreliminaryWork(); + void PreliminaryWork() const; void AnalysisUri(); void SpecialPath(); void AnalysisFragment(size_t pos); @@ -70,13 +70,13 @@ namespace OHOS::Uri { void AnalysisUserInfo(size_t pos); void AnalysisIPV6(); - bool CheckCharacter(std::string data, std::bitset rule, bool flag); + bool CheckCharacter(std::string data, std::bitset rule, bool flag) const; bool AnalysisPort(size_t pos); bool AnalysisIPV4(); std::string Split(std::string path) const; private: - uri_data uriData_; + UriData uriData_; std::string data_; std::string inputUri_; std::string errStr_; diff --git a/uri/src/js_uri.ts b/uri/js_uri.js similarity index 89% rename from uri/src/js_uri.ts rename to uri/js_uri.js index f94da8a9..a2e37574 100644 --- a/uri/src/js_uri.ts +++ b/uri/js_uri.js @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -declare function requireInternal(s : string) : any; + +'use strict'; const uri = requireInternal("uri"); class URI { - uricalss : any - constructor(input:any) { + constructor(input) { if (typeof input !== 'string' || input.length === 0) { throw new Error("input type err"); } @@ -31,7 +31,7 @@ class URI { return toAscllString(this.uricalss.toString()); } - equals(other:any) { + equals(other) { return this.uricalss.equals(other.uricalss); } @@ -40,7 +40,8 @@ class URI { } normalize() { - return this.uricalss.normalize(); + let uriStr = this.uricalss.normalize(); + return createNewUri(uriStr); } get scheme() { @@ -81,7 +82,7 @@ class URI { } -function toAscllString(uriStr:any) { +function toAscllString(uriStr) { if (uriStr.indexOf('[') !== -1) { let arr = uriStr.split("["); let brr = arr[1].split("]"); @@ -95,6 +96,10 @@ function toAscllString(uriStr:any) { } } +function createNewUri(uriStr) { + return new URI(uriStr); +} + export default { URI: URI, } diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index 91581781..96107d99 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -13,17 +13,18 @@ * limitations under the License. */ -#include "napi/native_api.h" -#include "napi/native_node_api.h" + #include "js_uri.h" #include "utils/log.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" extern const char _binary_js_uri_js_start[]; extern const char _binary_js_uri_js_end[]; extern const char _binary_uri_abc_start[]; extern const char _binary_uri_abc_end[]; + namespace OHOS::Uri { - napi_value g_uriClass = nullptr; static napi_value UriConstructor(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -36,20 +37,24 @@ namespace OHOS::Uri { NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype == napi_string) { char *type = nullptr; + std::string input = ""; size_t typelen = 0; NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typelen)); - type = new char[typelen + 1]; - NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], type, typelen + 1, &typelen)); - object = new Uri(env, type); - delete[] type; + if (typelen > 0) { + type = new char[typelen + 1]; + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], type, typelen + 1, &typelen)); + input = type; + delete[] type; + } + object = new Uri(env, input); } else { napi_throw_error(env, nullptr, "parameter type is error"); } NAPI_CALL(env, napi_wrap(env, thisVar, object, [](napi_env env, void *data, void *hint) { - auto object = (Uri*)data; - if (object != nullptr) { - delete object; + auto obj = (Uri*)data; + if (obj != nullptr) { + delete obj; } }, nullptr, nullptr)); return thisVar; @@ -62,11 +67,9 @@ namespace OHOS::Uri { Uri *muri = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); std::string normalizeUri = muri->Normalize(); - size_t argc = 1; - napi_value args[1] = { 0 }; napi_value result = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, normalizeUri.c_str(), normalizeUri.size(), args)); - NAPI_CALL(env, napi_new_instance(env, g_uriClass, argc, args, &result)); + size_t tempLen = normalizeUri.size(); + NAPI_CALL(env, napi_create_string_utf8(env, normalizeUri.c_str(), tempLen, &result)); return result; } @@ -264,8 +267,7 @@ namespace OHOS::Uri { DECLARE_NAPI_GETTER("isFailed", IsFailed), }; NAPI_CALL(env, napi_define_class(env, uriClassName, strlen(uriClassName), UriConstructor, - nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); - g_uriClass = uriClass; + nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Uri", uriClass) }; diff --git a/uri/tsconfig.json b/uri/tsconfig.json deleted file mode 100644 index f8212040..00000000 --- a/uri/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ -"compilerOptions": { - "target": "es6", - "module": "es6", - "rootDir": "./src", - //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/uri/", /* Specify an output folder for all emitted files. */ - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "noImplicitThis": false, - } -} diff --git a/url/BUILD.gn b/url/BUILD.gn index 920d024a..11b32a4d 100755 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -32,7 +32,7 @@ action("gen_url_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build"] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] inputs = [ "//base/compileruntime/js_api_module/url/js_url.js" ] outputs = [ target_out_dir + "/url.abc" ] @@ -68,6 +68,7 @@ ohos_shared_library("url") { deps = [ ":js_url", + ":url_abc", "//base/compileruntime/js_api_module/url/:js_url", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", diff --git a/url/native_module_url.cpp b/url/native_module_url.cpp index e80ab108..57fc077d 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -31,8 +31,8 @@ namespace OHOS::Url { void *data = nullptr; napi_get_cb_info(env, info, &argc, nullptr, &thisVar, &data); napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); - napi_valuetype valuetype1; - napi_valuetype valuetype2; + napi_valuetype valuetype1 = napi_null; + napi_valuetype valuetype2 = napi_null; std::string input = ""; napi_typeof(env, argv[0], &valuetype1); if (valuetype1 == napi_string) { @@ -82,7 +82,7 @@ namespace OHOS::Url { if (argc == 1) { std::string input = ""; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); - napi_valuetype valuetype; + napi_valuetype valuetype = napi_null; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype == napi_string) { char *type = nullptr; @@ -104,9 +104,9 @@ namespace OHOS::Url { napi_wrap( env, thisVar, object, [](napi_env env, void *data, void *hint) { - auto object = (URL*)data; - if (object != nullptr) { - delete object; + auto obj = (URL*)data; + if (obj != nullptr) { + delete obj; } }, nullptr, nullptr); @@ -886,7 +886,7 @@ namespace OHOS::Url { DECLARE_NAPI_GETTER("GetIsIpv6", GetIsIpv6), }; NAPI_CALL(env, napi_define_class(env, urlClassName, strlen(urlClassName), UrlConstructor, - nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); + nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Url", urlClass) }; @@ -926,7 +926,6 @@ namespace OHOS::Url { *buflen = _binary_url_abc_end - _binary_url_abc_start; } } - static napi_module UrlModule = { .nm_version = 1, .nm_flags = 0, -- Gitee From 9808c71e0cab38adab72521c6ed64e26e8628466 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Mon, 27 Sep 2021 17:43:46 +0800 Subject: [PATCH 12/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn new file: convertxml/build_ts_js.py modified: convertxml/native_module_convertxml.cpp renamed: convertxml/js_convertxml.js -> convertxml/src/js_convertxml.ts new file: convertxml/tsconfig.json --- convertxml/BUILD.gn | 32 ++++++++++++------- convertxml/build_ts_js.py | 21 ++++++++++++ convertxml/native_module_convertxml.cpp | 16 +++++----- .../js_convertxml.ts} | 8 ++--- convertxml/tsconfig.json | 14 ++++++++ 5 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 convertxml/build_ts_js.py rename convertxml/{js_convertxml.js => src/js_convertxml.ts} (95%) mode change 100755 => 100644 create mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index ebace873..5e130653 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -16,6 +16,21 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") +# compile .ts to .js. +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [ target_out_dir + "/js_convertxml.js" ] +} + +base_output_path = get_label_info(":js_convertxml", "target_out_dir") +js_xml_obj_path = base_output_path + "/convertxml.o" +gen_js_obj("js_convertxml") { + input = "$target_out_dir/js_convertxml.js" + output = js_xml_obj_path + dep = ":build_ts_js" +} + # compile .js to .abc. action("gen_convertxml_abc") { visibility = [ ":*" ] @@ -23,7 +38,7 @@ action("gen_convertxml_abc") { args = [ "--src-js", - rebase_path("//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), + rebase_path(target_out_dir + "/js_convertxml.js"), "--dst-file", rebase_path(target_out_dir + "/convertxml.abc"), "--node", @@ -33,20 +48,15 @@ action("gen_convertxml_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + deps = [ + ":build_ts_js", + "//ark/ts2abc/ts2panda:ark_ts2abc_build", + ] - inputs = [ "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" ] + inputs = [ target_out_dir + "/js_convertxml.js" ] outputs = [ target_out_dir + "/convertxml.abc" ] } -base_output_path = get_label_info(":js_convertxml", "target_out_dir") -js_xml_obj_path = base_output_path + "/convertxml.o" - -gen_js_obj("js_convertxml") { - input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" - output = js_xml_obj_path -} - abc_output_path = get_label_info(":convertxml_abc", "target_out_dir") convertxml_abc_obj_path = abc_output_path + "/convertxml_abc.o" gen_js_obj("convertxml_abc") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py new file mode 100644 index 00000000..76b3fb1d --- /dev/null +++ b/convertxml/build_ts_js.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/convertxml/native_module_convertxml.cpp b/convertxml/native_module_convertxml.cpp index 05ca3943..01909055 100755 --- a/convertxml/native_module_convertxml.cpp +++ b/convertxml/native_module_convertxml.cpp @@ -98,15 +98,15 @@ __attribute__((visibility("default"))) void NAPI_convertxml_GetJSCode(const char } } extern "C" -__attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) -{ - if (buf != nullptr) { - *buf = _binary_convertxml_abc_start; + __attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) + { + if (buf != nullptr) { + *buf = _binary_convertxml_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_convertxml_abc_end - _binary_convertxml_abc_start; + } } - if (buflen != nullptr) { - *buflen = _binary_convertxml_abc_end - _binary_convertxml_abc_start; - } -} static napi_module ConvertXmlModule = { .nm_version = 1, diff --git a/convertxml/js_convertxml.js b/convertxml/src/js_convertxml.ts old mode 100755 new mode 100644 similarity index 95% rename from convertxml/js_convertxml.js rename to convertxml/src/js_convertxml.ts index e045ea7a..93ebb980 --- a/convertxml/js_convertxml.js +++ b/convertxml/src/js_convertxml.ts @@ -13,14 +13,14 @@ * limitations under the License. */ -'use strict'; +declare function requireInternal(s : string) : any; const convertXml = requireInternal("ConvertXML"); class ConvertXml { convertxmlclass; constructor() { this.convertxmlclass = new convertXml.ConvertXml(); } - convert(strXml, options) { + convert(strXml : string, options : any) { strXml = DealXml(strXml); let converted = this.convertxmlclass.convert(strXml, options); let space = 0; @@ -43,7 +43,7 @@ class ConvertXml { } } -function DealXml(strXml) +function DealXml(strXml : string) { var idx = 0; var idxSec = 0; @@ -88,7 +88,7 @@ function DealXml(strXml) return strXml; } -function DealReplace(strXml, idx, idxThir) +function DealReplace(strXml : string, idx : any, idxThir : any) { var i = idx + 1; for (; i < idxThir ; i++) { diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json new file mode 100644 index 00000000..e61c432f --- /dev/null +++ b/convertxml/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} -- Gitee From 2375d2b925f391ceb325eb1dc8d778d881e92983 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Mon, 27 Sep 2021 18:28:03 +0800 Subject: [PATCH 13/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/build_ts_js.py --- convertxml/build_ts_js.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 convertxml/build_ts_js.py diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py old mode 100644 new mode 100755 -- Gitee From f93ee6c07b229cd46b05fd75acc3ab121768be18 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 28 Sep 2021 10:07:14 +0800 Subject: [PATCH 14/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/build_ts_js.py --- convertxml/build_ts_js.py | 1 + 1 file changed, 1 insertion(+) diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index 76b3fb1d..aed2b91b 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -18,4 +18,5 @@ if __name__ == '__main__': build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) + os.system('npm install --prefix ../../../../developtools/ace-ets2bundle/compiler/') os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file -- Gitee From bb1cf861d558946ae47055e56e2ee36cbb073d0f Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 28 Sep 2021 11:28:05 +0800 Subject: [PATCH 15/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/build_ts_js.py --- convertxml/build_ts_js.py | 1 - 1 file changed, 1 deletion(-) diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index aed2b91b..76b3fb1d 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -18,5 +18,4 @@ if __name__ == '__main__': build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) - os.system('npm install --prefix ../../../../developtools/ace-ets2bundle/compiler/') os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file -- Gitee From b7b4afe2625ad8350a9339aea3aec8b1460c5905 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 28 Sep 2021 15:52:02 +0800 Subject: [PATCH 16/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. Changes to be committed: modified: convertxml/BUILD.gn deleted: convertxml/build_ts_js.py modified: convertxml/js_convertxml.cpp renamed: convertxml/src/js_convertxml.ts -> convertxml/js_convertxml.js modified: convertxml/native_module_convertxml.cpp deleted: convertxml/tsconfig.json modified: uri/native_module_uri.cpp modified: url/native_module_url.cpp --- convertxml/BUILD.gn | 32 +++------ convertxml/build_ts_js.py | 21 ------ convertxml/js_convertxml.cpp | 34 +++++---- .../js_convertxml.ts => js_convertxml.js} | 8 +-- convertxml/native_module_convertxml.cpp | 20 +++--- convertxml/tsconfig.json | 14 ---- uri/native_module_uri.cpp | 32 ++++----- url/native_module_url.cpp | 72 +++++++++---------- 8 files changed, 98 insertions(+), 135 deletions(-) delete mode 100755 convertxml/build_ts_js.py rename convertxml/{src/js_convertxml.ts => js_convertxml.js} (95%) delete mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index 5e130653..ebace873 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -16,21 +16,6 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") -# compile .ts to .js. -action("build_ts_js") { - script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" - depfile = "$target_gen_dir/$target_name.d" - outputs = [ target_out_dir + "/js_convertxml.js" ] -} - -base_output_path = get_label_info(":js_convertxml", "target_out_dir") -js_xml_obj_path = base_output_path + "/convertxml.o" -gen_js_obj("js_convertxml") { - input = "$target_out_dir/js_convertxml.js" - output = js_xml_obj_path - dep = ":build_ts_js" -} - # compile .js to .abc. action("gen_convertxml_abc") { visibility = [ ":*" ] @@ -38,7 +23,7 @@ action("gen_convertxml_abc") { args = [ "--src-js", - rebase_path(target_out_dir + "/js_convertxml.js"), + rebase_path("//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), "--dst-file", rebase_path(target_out_dir + "/convertxml.abc"), "--node", @@ -48,15 +33,20 @@ action("gen_convertxml_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ - ":build_ts_js", - "//ark/ts2abc/ts2panda:ark_ts2abc_build", - ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] - inputs = [ target_out_dir + "/js_convertxml.js" ] + inputs = [ "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" ] outputs = [ target_out_dir + "/convertxml.abc" ] } +base_output_path = get_label_info(":js_convertxml", "target_out_dir") +js_xml_obj_path = base_output_path + "/convertxml.o" + +gen_js_obj("js_convertxml") { + input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" + output = js_xml_obj_path +} + abc_output_path = get_label_info(":convertxml_abc", "target_out_dir") convertxml_abc_obj_path = abc_output_path + "/convertxml_abc.o" gen_js_obj("convertxml_abc") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py deleted file mode 100755 index 76b3fb1d..00000000 --- a/convertxml/build_ts_js.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os - -if __name__ == '__main__': - - build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) - os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') \ No newline at end of file diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 65a40944..505e06d4 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -113,22 +113,24 @@ void ConvertXml::GetPrevNodeList(xmlNodePtr curNode) napi_create_object(env_, &elementsObject); if (curNode->type == xmlElementType::XML_PI_NODE && !m_Options.ignoreInstruction) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); + SetKeyValue(elementsObject, m_Options.name, reinterpret_cast(curNode->name)); if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.instruction, (const char*)xmlNodeGetContent(curNode)); + SetKeyValue(elementsObject, m_Options.instruction, + reinterpret_cast(xmlNodeGetContent(curNode))); } m_prevObj.push_back(elementsObject); } if (curNode->type == xmlElementType::XML_COMMENT_NODE && !m_Options.ignoreComment) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.comment, (const char*)xmlNodeGetContent(curNode)); + SetKeyValue(elementsObject, m_Options.comment, + reinterpret_cast(xmlNodeGetContent(curNode))); } m_prevObj.push_back(elementsObject); } if (curNode->type == xmlElementType::XML_DTD_NODE && !m_Options.ignoreDoctype) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - SetKeyValue(elementsObject, m_Options.doctype, (char*)curNode->name); + SetKeyValue(elementsObject, m_Options.doctype, reinterpret_cast(curNode->name)); m_prevObj.push_back(elementsObject); } } @@ -141,7 +143,8 @@ void ConvertXml::SetAttributes(xmlNodePtr curNode, napi_value &elementsObject) napi_value attrTitleObj = nullptr; napi_create_object(env_, &attrTitleObj); while (attr) { - SetKeyValue(attrTitleObj, (const char*)attr->name, (const char*)attr->children->content); + SetKeyValue(attrTitleObj, reinterpret_cast(attr->name), + reinterpret_cast(attr->children->content)); attr = attr->next; } napi_set_named_property(env_, elementsObject, m_Options.attributes.c_str(), attrTitleObj); @@ -152,17 +155,20 @@ void ConvertXml::SetXmlElementType(xmlNodePtr curNode, napi_value &elementsObjec { if (curNode->type == xmlElementType::XML_PI_NODE && !m_Options.ignoreInstruction) { if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.instruction.c_str(), (const char*)xmlNodeGetContent(curNode)); + SetKeyValue(elementsObject, m_Options.instruction.c_str(), + reinterpret_cast(xmlNodeGetContent(curNode))); bFlag = true; } } else if (curNode->type == xmlElementType::XML_COMMENT_NODE && !m_Options.ignoreComment) { if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.comment.c_str(), (const char*)xmlNodeGetContent(curNode)); + SetKeyValue(elementsObject, m_Options.comment.c_str(), + reinterpret_cast(xmlNodeGetContent(curNode))); bFlag = true; } } else if (curNode->type == xmlElementType::XML_CDATA_SECTION_NODE && !m_Options.ignoreCdata) { if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.cdata, (const char*)xmlNodeGetContent(curNode)); + SetKeyValue(elementsObject, m_Options.cdata, + reinterpret_cast(xmlNodeGetContent(curNode))); bFlag = true; } } @@ -182,7 +188,7 @@ void ConvertXml::SetNodeInfo(xmlNodePtr curNode, napi_value &elementsObject) if ((curNode->type != xmlElementType::XML_COMMENT_NODE) && (curNode->type != xmlElementType::XML_CDATA_SECTION_NODE)) { if (!(curNode->type == xmlElementType::XML_PI_NODE && m_Options.ignoreInstruction)) { - SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); + SetKeyValue(elementsObject, m_Options.name, reinterpret_cast(curNode->name)); } } } @@ -192,16 +198,18 @@ void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); if (curNode->type == xmlElementType::XML_ELEMENT_NODE) { - SetKeyValue(elementsObject, m_Options.name.c_str(), (const char*)curNode->name); + SetKeyValue(elementsObject, m_Options.name.c_str(), reinterpret_cast(curNode->name)); bFlag = true; } else if (curNode->type == xmlElementType::XML_TEXT_NODE) { if (m_Options.trim) { if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.text, Trim((const char*)xmlNodeGetContent(curNode))); + SetKeyValue(elementsObject, m_Options.text, + Trim(reinterpret_cast(xmlNodeGetContent(curNode)))); } } else { if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.text, (const char*)xmlNodeGetContent(curNode)); + SetKeyValue(elementsObject, m_Options.text, + reinterpret_cast(xmlNodeGetContent(curNode))); } } if (!m_Options.ignoreText) { @@ -567,7 +575,7 @@ void ConvertXml::DealCDataInfo(bool bCData, xmlNodePtr &curNode) curNode->next && curNode->next->type == xmlElementType::XML_TEXT_NODE && curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { if (xmlNodeGetContent(curNode->next) != nullptr) { - std::string strTemp = (char*)xmlNodeGetContent(curNode->next); + std::string strTemp = reinterpret_cast(xmlNodeGetContent(curNode->next)); Replace(strTemp, " ", ""); Replace(strTemp, "\v", ""); Replace(strTemp, "\t", ""); diff --git a/convertxml/src/js_convertxml.ts b/convertxml/js_convertxml.js similarity index 95% rename from convertxml/src/js_convertxml.ts rename to convertxml/js_convertxml.js index 93ebb980..e045ea7a 100644 --- a/convertxml/src/js_convertxml.ts +++ b/convertxml/js_convertxml.js @@ -13,14 +13,14 @@ * limitations under the License. */ -declare function requireInternal(s : string) : any; +'use strict'; const convertXml = requireInternal("ConvertXML"); class ConvertXml { convertxmlclass; constructor() { this.convertxmlclass = new convertXml.ConvertXml(); } - convert(strXml : string, options : any) { + convert(strXml, options) { strXml = DealXml(strXml); let converted = this.convertxmlclass.convert(strXml, options); let space = 0; @@ -43,7 +43,7 @@ class ConvertXml { } } -function DealXml(strXml : string) +function DealXml(strXml) { var idx = 0; var idxSec = 0; @@ -88,7 +88,7 @@ function DealXml(strXml : string) return strXml; } -function DealReplace(strXml : string, idx : any, idxThir : any) +function DealReplace(strXml, idx, idxThir) { var i = idx + 1; for (; i < idxThir ; i++) { diff --git a/convertxml/native_module_convertxml.cpp b/convertxml/native_module_convertxml.cpp index 01909055..ec877c16 100755 --- a/convertxml/native_module_convertxml.cpp +++ b/convertxml/native_module_convertxml.cpp @@ -31,7 +31,7 @@ static napi_value ConvertXmlConstructor(napi_env env, napi_callback_info info) napi_wrap( env, thisVar, objectInfo, [](napi_env env, void *data, void *hint) { - auto obj = (ConvertXml*)data; + auto obj = reinterpret_cast(data); if (obj != nullptr) { delete obj; } @@ -53,7 +53,7 @@ static napi_value Convert(napi_env env, napi_callback_info info) std::string strXml; napi_valuetype valuetype; ConvertXml *object = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&object))); if (args[0] == nullptr) { NAPI_CALL(env, napi_throw_error(env, "", "parameter is empty")); } else { @@ -98,15 +98,15 @@ __attribute__((visibility("default"))) void NAPI_convertxml_GetJSCode(const char } } extern "C" - __attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) - { - if (buf != nullptr) { - *buf = _binary_convertxml_abc_start; - } - if (buflen != nullptr) { - *buflen = _binary_convertxml_abc_end - _binary_convertxml_abc_start; - } +__attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) +{ + if (buf != nullptr) { + *buf = _binary_convertxml_abc_start; } + if (buflen != nullptr) { + *buflen = _binary_convertxml_abc_end - _binary_convertxml_abc_start; + } +} static napi_module ConvertXmlModule = { .nm_version = 1, diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json deleted file mode 100644 index e61c432f..00000000 --- a/convertxml/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ -"compilerOptions": { - "target": "es6", - "module": "es6", - "rootDir": "./src", - //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "noImplicitThis": false, - } -} diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index 96107d99..23eb1c6f 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -52,7 +52,7 @@ namespace OHOS::Uri { } NAPI_CALL(env, napi_wrap(env, thisVar, object, [](napi_env env, void *data, void *hint) { - auto obj = (Uri*)data; + auto obj = reinterpret_cast(data); if (obj != nullptr) { delete obj; } @@ -65,7 +65,7 @@ namespace OHOS::Uri { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string normalizeUri = muri->Normalize(); napi_value result = nullptr; size_t tempLen = normalizeUri.size(); @@ -82,9 +82,9 @@ namespace OHOS::Uri { NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); Uri *other = nullptr; - NAPI_CALL(env, napi_unwrap(env, argv[0], (void**)&other)); + NAPI_CALL(env, napi_unwrap(env, argv[0], reinterpret_cast(&other))); bool flag = muri->Equals(*other); NAPI_CALL(env, napi_get_boolean(env, flag, &result)); @@ -97,7 +97,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); bool flag = muri->IsAbsolute(); NAPI_CALL(env, napi_get_boolean(env, flag, &result)); return result; @@ -109,7 +109,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->IsFailed(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -122,7 +122,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->ToString(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -135,7 +135,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetScheme(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -148,7 +148,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetAuthority(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -161,7 +161,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetSsp(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -174,7 +174,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetUserinfo(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -187,7 +187,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetHost(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -200,7 +200,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetPort(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -213,7 +213,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetPath(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -226,7 +226,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetQuery(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); @@ -239,7 +239,7 @@ namespace OHOS::Uri { napi_value result = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); Uri *muri = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&muri)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&muri))); std::string temp = muri->GetFragment(); size_t templen = temp.size(); NAPI_CALL(env, napi_create_string_utf8(env, temp.c_str(), templen, &result)); diff --git a/url/native_module_url.cpp b/url/native_module_url.cpp index 57fc077d..75cf918a 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -60,7 +60,7 @@ namespace OHOS::Url { object = new URL(env, input, base); } else if (valuetype2 == napi_object) { URL *temp = nullptr; - napi_unwrap(env, argv[1], (void**)&temp); + napi_unwrap(env, argv[1], reinterpret_cast(&temp)); object = new URL(env, input, *temp); } else { HILOG_INFO("secondParameter error"); @@ -118,7 +118,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetHostname(); return retVal; } @@ -128,7 +128,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetSearch(); return retVal; } @@ -138,7 +138,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetUsername(); return retVal; } @@ -148,7 +148,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetPassword(); return retVal; } @@ -158,7 +158,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetFragment(); return retVal; } @@ -168,7 +168,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetScheme(); return retVal; } @@ -178,7 +178,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetPort(); return retVal; } @@ -188,7 +188,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetHost(); return retVal; } @@ -198,7 +198,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetPath(); return retVal; } @@ -208,7 +208,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetOnOrOff(); return retVal; } @@ -218,7 +218,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetIsIpv6(); return retVal; } @@ -243,7 +243,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetHref(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -270,7 +270,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetHostname(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -297,7 +297,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetPort(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -324,7 +324,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetHost(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -351,7 +351,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetSearch(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -378,7 +378,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetScheme(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -405,7 +405,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetFragment(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -432,7 +432,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetUsername(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -459,7 +459,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetPath(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -486,7 +486,7 @@ namespace OHOS::Url { type = nullptr; } URL *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetPassword(input); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -537,7 +537,7 @@ namespace OHOS::Url { } } URLSearchParams *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); murl->SetArray(vec); napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); @@ -549,7 +549,7 @@ namespace OHOS::Url { napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr)); URLSearchParams *murl = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&murl)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&murl))); napi_value retVal = murl->GetArray(); return retVal; } @@ -565,7 +565,7 @@ namespace OHOS::Url { return nullptr; } URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); napi_value result = object->Get(args); return result; } @@ -581,7 +581,7 @@ namespace OHOS::Url { return nullptr; } URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); napi_value result = object->GetAll(args); return result; } @@ -598,7 +598,7 @@ namespace OHOS::Url { return nullptr; } URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); object->Append(args[0], args[1]); return nullptr; } @@ -614,7 +614,7 @@ namespace OHOS::Url { return nullptr; } URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); object->Delete(args); return nullptr; } @@ -626,7 +626,7 @@ namespace OHOS::Url { napi_value args = nullptr; napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); object->ForEach(args, thisVar); return nullptr; } @@ -638,7 +638,7 @@ namespace OHOS::Url { napi_value args = nullptr; napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); napi_value result = object->Entries(); return result; } @@ -650,7 +650,7 @@ namespace OHOS::Url { napi_value args = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); URLSearchParams *object = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + NAPI_CALL(env, napi_unwrap(env, thisVar, reinterpret_cast(&object))); napi_value result = object->IsHas(args); return result; } @@ -662,7 +662,7 @@ namespace OHOS::Url { napi_value args[2] = { 0 }; napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); object->Set(args[0], args[1]); return nullptr; } @@ -674,7 +674,7 @@ namespace OHOS::Url { napi_value args = nullptr; napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); object->Sort(); return nullptr; } @@ -686,7 +686,7 @@ namespace OHOS::Url { napi_value args = nullptr; napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); napi_value result = object->ToString(); return result; } @@ -698,7 +698,7 @@ namespace OHOS::Url { napi_value args = nullptr; napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); napi_value result = object->IterByKeys(); return result; } @@ -710,7 +710,7 @@ namespace OHOS::Url { napi_value args = nullptr; napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr); URLSearchParams *object = nullptr; - napi_unwrap(env, thisVar, (void**)&object); + napi_unwrap(env, thisVar, reinterpret_cast(&object)); napi_value result = object->IterByValues(); return result; } -- Gitee From 68468556fef9531c52eedc892361ca75f4658b80 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 28 Sep 2021 16:53:52 +0800 Subject: [PATCH 17/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/js_convertxml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 505e06d4..339bb991 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -203,7 +203,7 @@ void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool } else if (curNode->type == xmlElementType::XML_TEXT_NODE) { if (m_Options.trim) { if (xmlNodeGetContent(curNode) != nullptr) { - SetKeyValue(elementsObject, m_Options.text, + SetKeyValue(elementsObject, m_Options.text, Trim(reinterpret_cast(xmlNodeGetContent(curNode)))); } } else { -- Gitee From e670b0bc1d5d64e2278f35d3f713f921e099dfea Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 29 Sep 2021 11:32:37 +0800 Subject: [PATCH 18/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/BUILD.gn | 32 ++++-- convertxml/build_ts_js.py | 21 ++++ convertxml/native_module_convertxml.cpp | 2 +- convertxml/src/js_convertxml.ts | 130 ++++++++++++++++++++++++ convertxml/tsconfig.json | 14 +++ 5 files changed, 187 insertions(+), 12 deletions(-) create mode 100644 convertxml/build_ts_js.py create mode 100644 convertxml/src/js_convertxml.ts create mode 100644 convertxml/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index ebace873..5e130653 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -16,6 +16,21 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") +# compile .ts to .js. +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/convertxml/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [ target_out_dir + "/js_convertxml.js" ] +} + +base_output_path = get_label_info(":js_convertxml", "target_out_dir") +js_xml_obj_path = base_output_path + "/convertxml.o" +gen_js_obj("js_convertxml") { + input = "$target_out_dir/js_convertxml.js" + output = js_xml_obj_path + dep = ":build_ts_js" +} + # compile .js to .abc. action("gen_convertxml_abc") { visibility = [ ":*" ] @@ -23,7 +38,7 @@ action("gen_convertxml_abc") { args = [ "--src-js", - rebase_path("//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), + rebase_path(target_out_dir + "/js_convertxml.js"), "--dst-file", rebase_path(target_out_dir + "/convertxml.abc"), "--node", @@ -33,20 +48,15 @@ action("gen_convertxml_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + deps = [ + ":build_ts_js", + "//ark/ts2abc/ts2panda:ark_ts2abc_build", + ] - inputs = [ "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" ] + inputs = [ target_out_dir + "/js_convertxml.js" ] outputs = [ target_out_dir + "/convertxml.abc" ] } -base_output_path = get_label_info(":js_convertxml", "target_out_dir") -js_xml_obj_path = base_output_path + "/convertxml.o" - -gen_js_obj("js_convertxml") { - input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" - output = js_xml_obj_path -} - abc_output_path = get_label_info(":convertxml_abc", "target_out_dir") convertxml_abc_obj_path = abc_output_path + "/convertxml_abc.o" gen_js_obj("convertxml_abc") { diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py new file mode 100644 index 00000000..569cdebd --- /dev/null +++ b/convertxml/build_ts_js.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') diff --git a/convertxml/native_module_convertxml.cpp b/convertxml/native_module_convertxml.cpp index ec877c16..4a8626bf 100755 --- a/convertxml/native_module_convertxml.cpp +++ b/convertxml/native_module_convertxml.cpp @@ -98,7 +98,7 @@ __attribute__((visibility("default"))) void NAPI_convertxml_GetJSCode(const char } } extern "C" -__attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) +__attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char **buf, int *buflen) { if (buf != nullptr) { *buf = _binary_convertxml_abc_start; diff --git a/convertxml/src/js_convertxml.ts b/convertxml/src/js_convertxml.ts new file mode 100644 index 00000000..93ebb980 --- /dev/null +++ b/convertxml/src/js_convertxml.ts @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function requireInternal(s : string) : any; +const convertXml = requireInternal("ConvertXML"); +class ConvertXml { + convertxmlclass; + constructor() { + this.convertxmlclass = new convertXml.ConvertXml(); + } + convert(strXml : string, options : any) { + strXml = DealXml(strXml); + let converted = this.convertxmlclass.convert(strXml, options); + let space = 0; + if (converted.hasOwnProperty("spaces")) { + space = converted.spaces; + delete converted.spaces; + } + var strEnd = JSON.stringify(converted, null, space); + var idx = 0; + while ((idx = strEnd.indexOf('\\t')) != -1) { + strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\n')) != -1) { + strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\')) != -1) { + strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); + } + return strEnd; + } +} + +function DealXml(strXml : string) +{ + var idx = 0; + var idxSec = 0; + var idxThir = 0; + var idxCData = 0; + var idxCDataSec = 0; + while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { + idxThir = strXml.indexOf('<', idx); + strXml = DealReplace(strXml, idx, idxThir); + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf('', idxCData); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i) + switch (cXml) { + case '\n': + strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); + break; + case '\v': + strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); + break; + case '\t': + strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); + break; + default: + break; + } + } + idxCDataSec = idxSec; + } + } + else { + break; + } + } + return strXml; +} + +function DealReplace(strXml : string, idx : any, idxThir : any) +{ + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { + case '\n': + strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); + break; + case '\v': + strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); + break; + case '\t': + strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); + break; + default: + break; + } + } else { + strXml = strXml.substring(0, j) + strXml.substring(j + 1); + --j; + } + } + return strXml; +} + +export default { + ConvertXml : ConvertXml +} + + diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json new file mode 100644 index 00000000..22fac622 --- /dev/null +++ b/convertxml/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} -- Gitee From d685d670bec3fbb4a2234a21124eb71e8f50a427 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 29 Sep 2021 14:03:44 +0800 Subject: [PATCH 19/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/build_ts_js.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 convertxml/build_ts_js.py diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py old mode 100644 new mode 100755 -- Gitee From 17622d927d0f33cf48f4138f99cb890d842760e1 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 29 Sep 2021 14:48:19 +0800 Subject: [PATCH 20/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json index 22fac622..bd8716af 100644 --- a/convertxml/tsconfig.json +++ b/convertxml/tsconfig.json @@ -4,7 +4,7 @@ "module": "es6", "rootDir": "./src", //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, -- Gitee From 8d141f65d7eaa721c06cc3794514f739235f2c12 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 29 Sep 2021 16:35:03 +0800 Subject: [PATCH 21/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/build_ts_js.py | 1 + convertxml/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index 569cdebd..87417136 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -19,3 +19,4 @@ if __name__ == '__main__': build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') + os.system('cp -r ../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/js_convertxml.js ../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/js_convertxml.js') diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json index bd8716af..bbee1e1a 100644 --- a/convertxml/tsconfig.json +++ b/convertxml/tsconfig.json @@ -4,7 +4,7 @@ "module": "es6", "rootDir": "./src", //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "outDir": "../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, -- Gitee From 3c89185682919eec2b7b11c9dacd71e70914df90 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Thu, 30 Sep 2021 10:33:10 +0800 Subject: [PATCH 22/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/BUILD.gn | 2 +- convertxml/build_ts_js.py | 9 +- convertxml/js_convertxml.js | 130 ----- convertxml/tsconfig.json | 5 +- uri/BUILD.gn | 33 +- uri/build_ts_js.py | 29 ++ uri/{js_uri.js => src/js_uri.ts} | 17 +- uri/tsconfig.json | 14 + url/BUILD.gn | 34 +- url/build_ts_js.py | 29 ++ url/{js_url.js => src/js_url.ts} | 836 ++++++++++++++++--------------- url/tsconfig.json | 14 + 12 files changed, 569 insertions(+), 583 deletions(-) delete mode 100644 convertxml/js_convertxml.js create mode 100644 uri/build_ts_js.py rename uri/{js_uri.js => src/js_uri.ts} (89%) create mode 100644 uri/tsconfig.json create mode 100644 url/build_ts_js.py rename url/{js_url.js => src/js_url.ts} (82%) mode change 100755 => 100644 create mode 100644 url/tsconfig.json diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index 5e130653..8096a2a1 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -103,4 +103,4 @@ ohos_shared_library("convertxml") { group("convertxml_packages") { deps = [ ":convertxml" ] -} +} \ No newline at end of file diff --git a/convertxml/build_ts_js.py b/convertxml/build_ts_js.py index 87417136..83a660e1 100755 --- a/convertxml/build_ts_js.py +++ b/convertxml/build_ts_js.py @@ -19,4 +19,11 @@ if __name__ == '__main__': build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) os.chdir("%s/base/compileruntime/js_api_module/convertxml" % build_path) os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') - os.system('cp -r ../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/js_convertxml.js ../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/js_convertxml.js') + + if os.access("../../../../out/ohos-arm64-release", os.F_OK): + os.system('cp -r ./out/js_convertxml.js ../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/js_convertxml.js') + + if os.access("../../../../out/ohos-arm-release", os.F_OK): + os.system('cp -r ./out/js_convertxml.js ../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/convertxml/js_convertxml.js') + + os.system('rm -rf ./out') \ No newline at end of file diff --git a/convertxml/js_convertxml.js b/convertxml/js_convertxml.js deleted file mode 100644 index e045ea7a..00000000 --- a/convertxml/js_convertxml.js +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; -const convertXml = requireInternal("ConvertXML"); -class ConvertXml { - convertxmlclass; - constructor() { - this.convertxmlclass = new convertXml.ConvertXml(); - } - convert(strXml, options) { - strXml = DealXml(strXml); - let converted = this.convertxmlclass.convert(strXml, options); - let space = 0; - if (converted.hasOwnProperty("spaces")) { - space = converted.spaces; - delete converted.spaces; - } - var strEnd = JSON.stringify(converted, null, space); - var idx = 0; - while ((idx = strEnd.indexOf('\\t')) != -1) { - strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); - } - while ((idx = strEnd.indexOf('\\n')) != -1) { - strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); - } - while ((idx = strEnd.indexOf('\\')) != -1) { - strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); - } - return strEnd; - } -} - -function DealXml(strXml) -{ - var idx = 0; - var idxSec = 0; - var idxThir = 0; - var idxCData = 0; - var idxCDataSec = 0; - while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { - idxThir = strXml.indexOf('<', idx); - strXml = DealReplace(strXml, idx, idxThir); - if (strXml.indexOf('<', idx) != -1) { - idxCData = strXml.indexOf('', idxCData); - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i) - switch (cXml) { - case '\n': - strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); - break; - case '\v': - strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); - break; - case '\t': - strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); - break; - default: - break; - } - } - idxCDataSec = idxSec; - } - } - else { - break; - } - } - return strXml; -} - -function DealReplace(strXml, idx, idxThir) -{ - var i = idx + 1; - for (; i < idxThir ; i++) { - var cXml = strXml.charAt(i); - if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') - { - break; - } - } - var j = idx + 1; - for (; j < strXml.indexOf('<', idx) ; j++) { - var cXml = strXml.charAt(j); - if (i != idxThir) { - switch (cXml) { - case '\n': - strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); - break; - case '\v': - strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); - break; - case '\t': - strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); - break; - default: - break; - } - } else { - strXml = strXml.substring(0, j) + strXml.substring(j + 1); - --j; - } - } - return strXml; -} - -export default { - ConvertXml : ConvertXml -} - - diff --git a/convertxml/tsconfig.json b/convertxml/tsconfig.json index bbee1e1a..c86e350c 100644 --- a/convertxml/tsconfig.json +++ b/convertxml/tsconfig.json @@ -4,11 +4,12 @@ "module": "es6", "rootDir": "./src", //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/convertxml/", /* Specify an output folder for all emitted files. */ + "outDir": "./out", /* Specify an output folder for all emitted files. */ "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, "noImplicitThis": false, - } + } } + diff --git a/uri/BUILD.gn b/uri/BUILD.gn index 8d84a14e..be1eeae5 100755 --- a/uri/BUILD.gn +++ b/uri/BUILD.gn @@ -15,6 +15,22 @@ import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") +# compile .ts to .js. +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/uri/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [target_out_dir + "/js_uri.js" + ] +} + +base_output_path = get_label_info(":js_uri", "target_out_dir") +js_uri_obj_path = base_output_path + "/uri.o" +gen_js_obj("js_uri") { + input = "$target_out_dir/js_uri.js" + output = js_uri_obj_path + dep = ":build_ts_js" +} + # compile .js to .abc. action("gen_uri_abc") { visibility = [ ":*" ] @@ -22,7 +38,7 @@ action("gen_uri_abc") { args = [ "--src-js", - rebase_path("//base/compileruntime/js_api_module/uri/js_uri.js"), + rebase_path(target_out_dir + "/js_uri.js"), "--dst-file", rebase_path(target_out_dir + "/uri.abc"), "--node", @@ -32,9 +48,10 @@ action("gen_uri_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" , + ":build_ts_js" ] - inputs = [ "//base/compileruntime/js_api_module/uri/js_uri.js" ] + inputs = [ target_out_dir+"/js_uri.js" ] outputs = [ target_out_dir + "/uri.abc" ] } @@ -46,13 +63,6 @@ gen_js_obj("uri_abc") { dep = ":gen_uri_abc" } -base_output_path = get_label_info(":js_uri", "target_out_dir") -js_uri_obj_path = base_output_path + "/uri.o" -gen_js_obj("js_uri") { - input = "//base/compileruntime/js_api_module/uri/js_uri.js" - output = js_uri_obj_path -} - ohos_shared_library("uri") { include_dirs = [ "//third_party/icu/icu4c/source/common", @@ -67,8 +77,8 @@ ohos_shared_library("uri") { ] deps = [ - ":js_uri", ":uri_abc", + ":js_uri", "//base/compileruntime/js_api_module/uri/:js_uri", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", @@ -90,3 +100,4 @@ ohos_shared_library("uri") { group("uri_packages") { deps = [ ":uri" ] } + diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py new file mode 100644 index 00000000..4461b2bb --- /dev/null +++ b/uri/build_ts_js.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/uri" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') + + if os.access("../../../../out/ohos-arm64-release", os.F_OK): + os.system('cp -r ./out/js_uri.js ../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/uri/js_uri.js') + + if os.access("../../../../out/ohos-arm-release", os.F_OK): + os.system('cp -r ./out/js_uri.js ../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/uri/js_uri.js') + + os.system('rm -rf ./out') \ No newline at end of file diff --git a/uri/js_uri.js b/uri/src/js_uri.ts similarity index 89% rename from uri/js_uri.js rename to uri/src/js_uri.ts index a2e37574..f94da8a9 100644 --- a/uri/js_uri.js +++ b/uri/src/js_uri.ts @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -'use strict'; +declare function requireInternal(s : string) : any; const uri = requireInternal("uri"); class URI { - constructor(input) { + uricalss : any + constructor(input:any) { if (typeof input !== 'string' || input.length === 0) { throw new Error("input type err"); } @@ -31,7 +31,7 @@ class URI { return toAscllString(this.uricalss.toString()); } - equals(other) { + equals(other:any) { return this.uricalss.equals(other.uricalss); } @@ -40,8 +40,7 @@ class URI { } normalize() { - let uriStr = this.uricalss.normalize(); - return createNewUri(uriStr); + return this.uricalss.normalize(); } get scheme() { @@ -82,7 +81,7 @@ class URI { } -function toAscllString(uriStr) { +function toAscllString(uriStr:any) { if (uriStr.indexOf('[') !== -1) { let arr = uriStr.split("["); let brr = arr[1].split("]"); @@ -96,10 +95,6 @@ function toAscllString(uriStr) { } } -function createNewUri(uriStr) { - return new URI(uriStr); -} - export default { URI: URI, } diff --git a/uri/tsconfig.json b/uri/tsconfig.json new file mode 100644 index 00000000..66ad1485 --- /dev/null +++ b/uri/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./out", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} diff --git a/url/BUILD.gn b/url/BUILD.gn index 11b32a4d..3163806f 100755 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -10,11 +10,29 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") import("//foundation/ace/ace_engine/ace_config.gni") +# compile .ts to .js. + +action("build_ts_js") { + script = "//base/compileruntime/js_api_module/url/build_ts_js.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [target_out_dir + "/js_url.js" + ] +} +base_output_path = get_label_info(":js_url", "target_out_dir") +js_url_obj_path = base_output_path + "/url.o" + +gen_js_obj("js_url") { + input = "$target_out_dir/js_url.js" + output = js_url_obj_path + dep = ":build_ts_js" +} + # compile .js to .abc. action("gen_url_abc") { visibility = [ ":*" ] @@ -22,7 +40,7 @@ action("gen_url_abc") { args = [ "--src-js", - rebase_path("//base/compileruntime/js_api_module/url/js_url.js"), + rebase_path(target_out_dir + "/js_url.js"), "--dst-file", rebase_path(target_out_dir + "/url.abc"), "--node", @@ -32,9 +50,10 @@ action("gen_url_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" , + ":build_ts_js" ] - inputs = [ "//base/compileruntime/js_api_module/url/js_url.js" ] + inputs = [ target_out_dir+"/js_url.js" ] outputs = [ target_out_dir + "/url.abc" ] } @@ -46,13 +65,6 @@ gen_js_obj("url_abc") { dep = ":gen_url_abc" } -base_output_path = get_label_info(":js_url", "target_out_dir") -js_url_obj_path = base_output_path + "/url.o" -gen_js_obj("js_url") { - input = "//base/compileruntime/js_api_module/url/js_url.js" - output = js_url_obj_path -} - ohos_shared_library("url") { include_dirs = [ "//third_party/icu/icu4c/source/common", @@ -67,8 +79,8 @@ ohos_shared_library("url") { ] deps = [ - ":js_url", ":url_abc", + ":js_url", "//base/compileruntime/js_api_module/url/:js_url", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", diff --git a/url/build_ts_js.py b/url/build_ts_js.py new file mode 100644 index 00000000..fb895e01 --- /dev/null +++ b/url/build_ts_js.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +if __name__ == '__main__': + + build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir("%s/base/compileruntime/js_api_module/url" % build_path) + os.system('../../../../developtools/ace-ets2bundle/compiler/node_modules/typescript/bin/tsc') + + if os.access("../../../../out/ohos-arm64-release", os.F_OK): + os.system('cp -r ./out/js_url.js ../../../../out/ohos-arm64-release/obj/base/compileruntime/js_api_module/url/js_url.js') + + if os.access("../../../../out/ohos-arm-release", os.F_OK): + os.system('cp -r ./out/js_url.js ../../../../out/ohos-arm-release/obj/base/compileruntime/js_api_module/url/js_url.js') + + os.system('rm -rf ./out') \ No newline at end of file diff --git a/url/js_url.js b/url/src/js_url.ts old mode 100755 new mode 100644 similarity index 82% rename from url/js_url.js rename to url/src/js_url.ts index 7eef1b4c..aae31cf4 --- a/url/js_url.js +++ b/url/src/js_url.ts @@ -1,416 +1,420 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; -const Url = requireInternal("url"); - -let seachParamsArr = []; -class URLSearchParams { - urlcalss; - constructor(input) { - let out = []; - out = parameterProcessing(input); - this.urlcalss = new Url.URLSearchParams1(); - this.urlcalss.array = out; - } - append(params1, params2) { - this.urlcalss.append(params1, params2); - } - - set(setname, setvalues) { - this.urlcalss.set(setname, setvalues); - } - - sort() { - this.urlcalss.sort(); - } - - has(hasname) { - return this.urlcalss.has(hasname); - } - toString() { - return this.urlcalss.toString(); - } - - keys() { - return this.urlcalss.keys(); - } - - values() { - console.log('constructor failed'); - return this.urlcalss.values(); - } - - getAll(getAllname) { - return this.urlcalss.getAll(getAllname); - } - - get(getname) { - return this.urlcalss.get(getname); - } - - entries() { - - return this.urlcalss.entries(); - } - - delete(deletename) { - this.urlcalss.delete(deletename); - } - - forEach(objfun) { - return this.urlcalss.forEach(objfun); - } - - [Symbol.iterator]() { - return this.urlcalss.entries(); - } - - updateParams(input) { - let out = []; - out = parameterProcessing(input); - this.urlcalss.array = out; - } -} - -function toHleString(arg) { - return arg.toString(); -} - -function parameterProcessing(input) { - if (input === null || typeof input === 'undefined') { - seachParamsArr = []; - return seachParamsArr; - } else if (typeof input === 'object' || typeof input === 'function') { - return initObjectSeachParams(input); - } else { - return initToStringSeachParams(input); - } -} -function initObjectSeachParams(input) { - if (typeof input[Symbol.iterator] === 'function') { - return iteratorMethod(input); - } - return recordMethod(input); -} -function recordMethod(input) { - const objectkeys = Reflect.ownKeys(input); - seachParamsArr = []; - let objectlength = objectkeys.length; - for (let i = 0; i <= objectlength; i++) { - const objectkey = objectkeys[i]; - const descry = Reflect.getOwnPropertyDescriptor(input, objectkey); - if (descry !== undefined && descry.enumerable) { - const inputkey = toHleString(objectkey); - const inputValue = toHleString(input[objectkey]); - seachParamsArr.push(inputkey, inputValue); - } - } - return seachParamsArr; -} -function iteratorMethod(input) { - let pairs = []; - seachParamsArr = []; - for (const pair of input) { - const conversionsPair = []; - for (let element of pair) { - conversionsPair.push(element); - } - pairs.push(conversionsPair); - } - - for (const pair of pairs) { - if (pair.length !== 2) { - console.log('key-value-is-worong'); - } - seachParamsArr.push(pair[0], pair[1]); - } - return seachParamsArr; -} - -function initToStringSeachParams(input) { - if (input[0] === '?') { - input = input.slice(1); - } - let strVal = decodeURI(input); - seachParamsArr = Url.stringParmas(strVal); - return seachParamsArr; -} -class URL { - href_; - search_; - origin_; - username_; - password_; - hostname_; - host_; - hash_; - protocol_; - pathname_; - port_; - searchParamsClass_; - c_info; - constructor() { - let nativeUrl; - let inputUrl; - let inputBase; - - if (arguments.length === 1) { - inputUrl = arguments[0]; - if (typeof inputUrl === 'string' && inputUrl.length > 0) { - nativeUrl = new Url.Url(inputUrl); - } else { - console.log('Input parameter error'); - } - } - - if (arguments.length === 2) { - inputUrl = arguments[0]; - inputBase = arguments[1]; - if (typeof inputUrl === 'string') { - if (typeof inputBase === 'string') { - if (inputBase.length > 0) { - nativeUrl = new Url.Url(inputUrl, inputBase); - } else { - console.log('Input parameter error'); - return; - } - } - if (typeof inputBase === 'object') { - let nativeBase = inputBase.getInfo(); - nativeUrl = new Url.Url(inputUrl, nativeBase); - } - } - } - this.c_info = nativeUrl; - if (nativeUrl.onOrOff) { - this.search_ = encodeURI(nativeUrl.search); - this.username_ = encodeURI(nativeUrl.username); - this.password_ = encodeURI(nativeUrl.password); - if (nativeUrl.GetIsIpv6) { - this.hostname_ = nativeUrl.hostname; - this.host_ = nativeUrl.host; - } else { - this.hostname_ = encodeURI(nativeUrl.hostname); - this.host_ = encodeURI(nativeUrl.host); - } - this.hash_ = encodeURI(nativeUrl.hash); - this.protocol_ = encodeURI(nativeUrl.protocol); - this.pathname_ = encodeURI(nativeUrl.pathname); - this.port_ = nativeUrl.port; - this.origin_ = nativeUrl.protocol + '//' + nativeUrl.host; - this.searchParamsClass_ = new URLSearchParams(this.search_); - this.set_href(); - } else { - console.log('constructor failed'); - } - } - getInfo() { - return this.c_info; - } - toString() { - return this.href_; - } - - get protocol() { - return this.protocol_; - } - set protocol(scheme) { - if (scheme.length === 0) { - return; - } - if (this.protocol_ === 'file:' - && (this.host_ === '' || this.host_ == null)) { - return; - } - this.c_info.protocol = scheme; - this.protocol_ = this.c_info.protocol; - this.set_href() - } - get origin() { - let kOpaqueOrigin = 'null'; - switch (this.protocol_) { - case 'ftp:': - case 'gopher:': - case 'http:': - case 'https:': - case 'ws:': - case 'wss:': - return this.origin_; - } - return kOpaqueOrigin; - } - get username() { - return this.username_; - } - set username(input) { - if (this.host_ == null || this.host_ === '' || this.protocol_ === 'file:') { - return; - } - const usname_ = escape(input); - this.c_info.username = usname_; - this.username_ = this.c_info.username; - this.set_href(); - } - get password() { - return this.password_; - } - set password(input) { - if (this.host_ == null || this.host_ === '' || this.protocol_ === 'file:') { - return; - } - const passwd_ = escape(input); - this.c_info.password = passwd_; - this.password_ = this.c_info.password; - this.set_href(); - } - get hash() { - return this.hash_; - } - set hash(fragment) { - const fragment_ = encodeURI(fragment); - this.c_info.hash = fragment_; - this.hash_ = this.c_info.hash; - this.set_href(); - } - get search() { - return this.search_; - } - set search(query) { - const query_ = encodeURI(query); - this.c_info.search = query_; - this.search_ = this.c_info.search; - this.searchParamsClass_.updateParams(this.search_); - this.set_href(); - } - get hostname() { - return this.hostname_; - } - set hostname(hostname) { - this.c_info.hostname = hostname; - if (this.c_info.GetIsIpv6) { - this.hostname_ = this.c_info.hostname; - } else { - this.hostname_ = encodeURI(this.c_info.hostname); - } - this.set_href(); - } - get host() { - return this.host_; - } - set host(host_) { - this.c_info.host = host_; - if (this.c_info.GetIsIpv6) { - this.host_ = this.c_info.host; - this.hostname_ = this.c_info.hostname; - this.port_ = this.c_info.port; - } else { - this.host_ = encodeURI(this.c_info.host); - this.hostname_ = encodeURI(this.c_info.hostname); - this.port_ = this.c_info.port; - } - this.set_href(); - } - get port() { - return this.port_; - } - set port(port) { - if (this.host_ === '' || this.protocol_ === 'file:' || port === '') { - return; - } - this.c_info.port = port; - this.port_ = this.c_info.port; - this.set_href(); - } - get href() { - return this.href_; - } - set href(href_) { - this.c_info.href(href_); - if (this.c_info.onOrOff) { - this.search_ = encodeURI(this.c_info.search); - this.username_ = encodeURI(this.c_info.username); - this.password_ = encodeURI(this.c_info.password); - if (this.c_info.GetIsIpv6) { - this.hostname_ = this.c_info.hostname; - this.host_ = this.c_info.host; - } else { - this.hostname_ = encodeURI(this.c_info.hostname); - this.host_ = encodeURI(this.c_info.host); - } - this.hash_ = encodeURI(this.c_info.hash); - this.protocol_ = encodeURI(this.c_info.protocol); - this.pathname_ = encodeURI(this.c_info.pathname); - this.port_ = this.c_info.port; - this.origin_ = this.protocol_ + '//' + this.host_; - this.searchParamsClass_.updateParams(this.search_); - this.set_href(); - } - } - - get pathname() { - return this.pathname_; - } - set pathname(path) { - const path_ = encodeURI(path); - this.c_info.pathname = path_; - this.pathname_ = this.c_info.pathname; - this.set_href(); - } - - get searchParams() { - return this.searchParamsClass_; - } - - toJSON() { - return this.href_; - } - set_href() { - let temp = this.protocol_; - if (this.hostname_ !== '') { - temp += '//'; - if (this.password_ !== '' || this.username_ !== '') { - if (this.username_ !== '') { - temp += this.username_; - } - if (this.password_ !== '') { - temp += ':'; - temp += this.password_; - } - temp += '@'; - } - temp += this.hostname_; - if (this.port_ !== '') { - temp += ':'; - temp += this.port_; - } - } else if (this.protocol_ === 'file:') { - temp += '//'; - } - temp += this.pathname_; - if (this.search_) { - temp += this.search_; - } - if (this.hash_) { - temp += this.hash_; - } - this.href_ = temp; - } -} - -export default { - URLSearchParams: URLSearchParams, - URL: URL, -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function requireInternal(s : string) : any; +const urlUtil = requireInternal('url'); + +let seachParamsArr:Array = []; + +class URLSearchParams { + urlcalss:any; + constructor(input:any) { + let out = []; + out = parameterProcessing(input); + this.urlcalss = new urlUtil.URLSearchParams1(); + this.urlcalss.array = out; + } + append(params1:string, params2:string) { + this.urlcalss.append(params1, params2); + } + + set(setname:string, setvalues:string) { + this.urlcalss.set(setname, setvalues); + } + + sort() { + this.urlcalss.sort(); + } + + has(hasname:string) { + return this.urlcalss.has(hasname); + } + + toString() { + return this.urlcalss.toString(); + } + + keys() { + return this.urlcalss.keys(); + } + + values() { + return this.urlcalss.values(); + } + + getAll(getAllname:string) { + return this.urlcalss.getAll(getAllname); + } + + get(getname:string) { + return this.urlcalss.get(getname); + } + + entries() { + + return this.urlcalss.entries(); + } + + delete(deletename:string) { + this.urlcalss.delete(deletename); + } + + forEach(objfun:object) { + return this.urlcalss.forEach(objfun); + } + + [Symbol.iterator]() { + return this.urlcalss.entries(); + } + + updateParams(input:any) { + let out = []; + out = parameterProcessing(input); + this.urlcalss.array = out; + } +} + +function toHleString(arg:any) { + return arg.toString(); +} + +function parameterProcessing(input:any) { + if (input === null || typeof input === 'undefined') { + seachParamsArr = []; + return seachParamsArr; + } else if (typeof input === 'object' || typeof input === 'function') { + return initObjectSeachParams(input); + } else { + return initToStringSeachParams(input); + } +} + +function initObjectSeachParams(input:any) { + if (typeof input[Symbol.iterator] === 'function') { + return iteratorMethod(input); + } + return recordMethod(input); +} + +function recordMethod(input:any) { + const keys = Reflect.ownKeys(input); + seachParamsArr = []; + for (let i = 0; i <= keys.length; i++) { + const key = keys[i]; + const desc = Reflect.getOwnPropertyDescriptor(input, key); + if (desc !== undefined && desc.enumerable) { + const typedKey = toHleString(key); + const typedValue = toHleString(input[key]); + seachParamsArr.push(typedKey, typedValue); + } + } + return seachParamsArr; +} + +function iteratorMethod(input:any) { + let pairs = []; + seachParamsArr = []; + for (const pair of input) { + const convertedPair = []; + for (let element of pair) { + convertedPair.push(element); + } + pairs.push(convertedPair); + } + + for (const pair of pairs) { + if (pair.length !== 2) { + console.log('key-value-is-worong'); + } + seachParamsArr.push(pair[0], pair[1]); + } + return seachParamsArr; +} + +function initToStringSeachParams(input:any) { + if (input[0] === '?') { + input = input.slice(1); + } + let strVal = decodeURI(input); + seachParamsArr = urlUtil.stringParmas(strVal); + return seachParamsArr; +} + +class URL { + href_:string = ''; + search_:string = ''; + origin_:string = ''; + username_:string = ''; + password_:string = ''; + hostname_:string = ''; + host_:string = ''; + hash_:string = ''; + protocol_:string = ''; + pathname_:string = ''; + port_:string = ''; + searchParamsClass_:any; + c_info:any; + constructor() { + let nativeUrl:any; + let inputUrl:string = ''; + let inputBase:any; + + if (arguments.length === 1) { + inputUrl = arguments[0]; + if (typeof inputUrl === 'string' && inputUrl.length > 0) { + nativeUrl = new urlUtil.Url(inputUrl); + } else { + console.log('Input parameter error'); + } + } + + if (arguments.length === 2) { + inputUrl = arguments[0]; + inputBase = arguments[1]; + if (typeof inputUrl === 'string') { + if (typeof inputBase === 'string') { + if (inputBase.length > 0) { + nativeUrl = new urlUtil.Url(inputUrl, inputBase); + } else { + console.log('Input parameter error'); + return; + } + } + if (typeof inputBase === 'object') { + let nativeBase = inputBase.getInfo(); + nativeUrl = new urlUtil.Url(inputUrl, nativeBase); + } + } + } + this.c_info = nativeUrl; + if (nativeUrl.onOrOff) { + this.search_ = encodeURI(nativeUrl.search); + this.username_ = encodeURI(nativeUrl.username); + this.password_ = encodeURI(nativeUrl.password); + if (nativeUrl.GetIsIpv6) { + this.hostname_ = nativeUrl.hostname; + this.host_ = nativeUrl.host; + } else { + this.hostname_ = encodeURI(nativeUrl.hostname); + this.host_ = encodeURI(nativeUrl.host); + } + this.hash_ = encodeURI(nativeUrl.hash); + this.protocol_ = encodeURI(nativeUrl.protocol); + this.pathname_ = encodeURI(nativeUrl.pathname); + this.port_ = nativeUrl.port; + this.origin_ = nativeUrl.protocol + '//' + nativeUrl.host; + this.searchParamsClass_ = new URLSearchParams(this.search_); + this.set_href(); + } else { + console.log('constructor failed'); + } + } + getInfo() { + return this.c_info; + } + toString() { + return this.href_; + } + + get protocol() { + return this.protocol_; + } + set protocol(scheme) { + if (scheme.length === 0) { + return; + } + if (this.protocol_ === 'file:' + && (this.host_ === '' || this.host_ == null)) { + return; + } + this.c_info.protocol = scheme; + this.protocol_ = this.c_info.protocol; + this.set_href() + } + get origin() { + let kOpaqueOrigin = 'null'; + switch (this.protocol_) { + case 'ftp:': + case 'gopher:': + case 'http:': + case 'https:': + case 'ws:': + case 'wss:': + return this.origin_; + } + return kOpaqueOrigin; + } + get username() { + return this.username_; + } + set username(input) { + if (this.host_ == null || this.host_ === '' || this.protocol_ === 'file:') { + return; + } + const usname_ = escape(input); + this.c_info.username = usname_; + this.username_ = this.c_info.username; + this.set_href(); + } + get password() { + return this.password_; + } + set password(input) { + if (this.host_ == null || this.host_ === '' || this.protocol_ === 'file:') { + return; + } + const passwd_ = escape(input); + this.c_info.password = passwd_; + this.password_ = this.c_info.password; + this.set_href(); + } + get hash() { + return this.hash_; + } + set hash(fragment) { + const fragment_ = encodeURI(fragment); + this.c_info.hash = fragment_; + this.hash_ = this.c_info.hash; + this.set_href(); + } + get search() { + return this.search_; + } + set search(query) { + const query_ = encodeURI(query); + this.c_info.search = query_; + this.search_ = this.c_info.search; + this.searchParamsClass_.updateParams(this.search_); + this.set_href(); + } + get hostname() { + return this.hostname_; + } + set hostname(hostname) { + this.c_info.hostname = hostname; + if (this.c_info.GetIsIpv6) { + this.hostname_ = this.c_info.hostname; + } else { + this.hostname_ = encodeURI(this.c_info.hostname); + } + this.set_href(); + } + get host() { + return this.host_; + } + set host(host_) { + this.c_info.host = host_; + if (this.c_info.GetIsIpv6) { + this.host_ = this.c_info.host; + this.hostname_ = this.c_info.hostname; + this.port_ = this.c_info.port; + } else { + this.host_ = encodeURI(this.c_info.host); + this.hostname_ = encodeURI(this.c_info.hostname); + this.port_ = this.c_info.port; + } + this.set_href(); + } + get port() { + return this.port_; + } + set port(port) { + if (this.host_ === '' || this.protocol_ === 'file:' || port === '') { + return; + } + this.c_info.port = port; + this.port_ = this.c_info.port; + this.set_href(); + } + get href() { + return this.href_; + } + set href(href_) { + this.c_info.href(href_); + if (this.c_info.onOrOff) { + this.search_ = encodeURI(this.c_info.search); + this.username_ = encodeURI(this.c_info.username); + this.password_ = encodeURI(this.c_info.password); + if (this.c_info.GetIsIpv6) { + this.hostname_ = this.c_info.hostname; + this.host_ = this.c_info.host; + } else { + this.hostname_ = encodeURI(this.c_info.hostname); + this.host_ = encodeURI(this.c_info.host); + } + this.hash_ = encodeURI(this.c_info.hash); + this.protocol_ = encodeURI(this.c_info.protocol); + this.pathname_ = encodeURI(this.c_info.pathname); + this.port_ = this.c_info.port; + this.origin_ = this.protocol_ + '//' + this.host_; + this.searchParamsClass_.updateParams(this.search_); + this.set_href(); + } + } + + get pathname() { + return this.pathname_; + } + set pathname(path) { + const path_ = encodeURI(path); + this.c_info.pathname = path_; + this.pathname_ = this.c_info.pathname; + this.set_href(); + } + + get searchParams() { + return this.searchParamsClass_; + } + + toJSON() { + return this.href_; + } + set_href() { + let temp = this.protocol_; + if (this.hostname_ !== '') { + temp += '//'; + if (this.password_ !== '' || this.username_ !== '') { + if (this.username_ !== '') { + temp += this.username_; + } + if (this.password_ !== '') { + temp += ':'; + temp += this.password_; + } + temp += '@'; + } + temp += this.hostname_; + if (this.port_ !== '') { + temp += ':'; + temp += this.port_; + } + } else if (this.protocol_ === 'file:') { + temp += '//'; + } + temp += this.pathname_; + if (this.search_) { + temp += this.search_; + } + if (this.hash_) { + temp += this.hash_; + } + this.href_ = temp; + } +} + +export default { + URLSearchParams: URLSearchParams, + URL: URL, +} diff --git a/url/tsconfig.json b/url/tsconfig.json new file mode 100644 index 00000000..66ad1485 --- /dev/null +++ b/url/tsconfig.json @@ -0,0 +1,14 @@ +{ +"compilerOptions": { + "target": "es6", + "module": "es6", + "rootDir": "./src", + //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./out", /* Specify an output folder for all emitted files. */ + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + } +} -- Gitee From 3a1703359e5576e2a1f4cfdba528f7326d3ceec8 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Thu, 30 Sep 2021 10:36:00 +0800 Subject: [PATCH 23/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- uri/build_ts_js.py | 0 url/build_ts_js.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 uri/build_ts_js.py mode change 100644 => 100755 url/build_ts_js.py diff --git a/uri/build_ts_js.py b/uri/build_ts_js.py old mode 100644 new mode 100755 diff --git a/url/build_ts_js.py b/url/build_ts_js.py old mode 100644 new mode 100755 -- Gitee From 05f735c7b78008fe173e7a9cd78f2687c8e983d0 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Thu, 30 Sep 2021 10:57:55 +0800 Subject: [PATCH 24/24] Signed-off-by: lifansheng On branch OpenHarmony-3.0-LTS Your branch is up to date with 'origin/OpenHarmony-3.0-LTS'. --- convertxml/BUILD.gn | 2 +- uri/BUILD.gn | 14 +++++++------- url/BUILD.gn | 13 +++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index 8096a2a1..5e130653 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -103,4 +103,4 @@ ohos_shared_library("convertxml") { group("convertxml_packages") { deps = [ ":convertxml" ] -} \ No newline at end of file +} diff --git a/uri/BUILD.gn b/uri/BUILD.gn index be1eeae5..a136c4bf 100755 --- a/uri/BUILD.gn +++ b/uri/BUILD.gn @@ -19,8 +19,7 @@ import("//foundation/ace/ace_engine/ace_config.gni") action("build_ts_js") { script = "//base/compileruntime/js_api_module/uri/build_ts_js.py" depfile = "$target_gen_dir/$target_name.d" - outputs = [target_out_dir + "/js_uri.js" - ] + outputs = [ target_out_dir + "/js_uri.js" ] } base_output_path = get_label_info(":js_uri", "target_out_dir") @@ -48,10 +47,12 @@ action("gen_uri_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" , - ":build_ts_js" ] + deps = [ + ":build_ts_js", + "//ark/ts2abc/ts2panda:ark_ts2abc_build", + ] - inputs = [ target_out_dir+"/js_uri.js" ] + inputs = [ target_out_dir + "/js_uri.js" ] outputs = [ target_out_dir + "/uri.abc" ] } @@ -77,8 +78,8 @@ ohos_shared_library("uri") { ] deps = [ - ":uri_abc", ":js_uri", + ":uri_abc", "//base/compileruntime/js_api_module/uri/:js_uri", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", @@ -100,4 +101,3 @@ ohos_shared_library("uri") { group("uri_packages") { deps = [ ":uri" ] } - diff --git a/url/BUILD.gn b/url/BUILD.gn index 3163806f..72187427 100755 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -21,8 +21,7 @@ import("//foundation/ace/ace_engine/ace_config.gni") action("build_ts_js") { script = "//base/compileruntime/js_api_module/url/build_ts_js.py" depfile = "$target_gen_dir/$target_name.d" - outputs = [target_out_dir + "/js_url.js" - ] + outputs = [ target_out_dir + "/js_url.js" ] } base_output_path = get_label_info(":js_url", "target_out_dir") js_url_obj_path = base_output_path + "/url.o" @@ -50,10 +49,12 @@ action("gen_url_abc") { "--node-modules", rebase_path("${node_modules}"), ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" , - ":build_ts_js" ] + deps = [ + ":build_ts_js", + "//ark/ts2abc/ts2panda:ark_ts2abc_build", + ] - inputs = [ target_out_dir+"/js_url.js" ] + inputs = [ target_out_dir + "/js_url.js" ] outputs = [ target_out_dir + "/url.abc" ] } @@ -79,8 +80,8 @@ ohos_shared_library("url") { ] deps = [ - ":url_abc", ":js_url", + ":url_abc", "//base/compileruntime/js_api_module/url/:js_url", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", -- Gitee