From bf607ea83d5f98bc67a9dd9821f5ac6d86c1992c Mon Sep 17 00:00:00 2001 From: xllify Date: Tue, 15 Mar 2022 14:22:40 +0800 Subject: [PATCH] Modify the util issue defect master pick to 3.1-Release Signed-off-by: xllify Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. On branch OpenHarmony-3.1-Release Your branch is up to date with 'origin/OpenHarmony-3.1-Release'. --- README.md | 22 +++--- README_zh.md | 16 ++--- build_ts_js.py | 4 +- mozilla_docs.txt | 4 +- util/BUILD.gn | 2 +- util/js_base64.cpp | 24 ++++--- util/js_base64.h | 2 +- util/js_textdecoder.cpp | 8 +-- util/js_textdecoder.h | 2 +- util/js_textencoder.cpp | 8 +-- util/js_textencoder.h | 2 +- util/js_types.cpp | 2 +- util/js_types.h | 3 +- util/native_module_util.cpp | 2 +- util/src/util_js.ts | 129 ++++++++++++++++++------------------ 15 files changed, 111 insertions(+), 119 deletions(-) diff --git a/README.md b/README.md index 5b78f40..1fc35cf 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ - [Related warehouse](#Related warehouse) ## Introduction -The interface of util is used for character Textencoder, TextDecoder and HelpFunction module.The TextEncoder represents a text encoder that accepts a string as input, encodes it in UTF-8 format, and outputs UTF-8 byte stream. The TextDecoder interface represents a text decoder. The decoder takes the byte stream as the input and outputs the Stirng string. HelpFunction is mainly used to callback and promise functions, write and output error codes, and format class strings. +The interface of util is used for character Textencoder, TextDecoder and HelpFunction module.The TextEncoder represents a text encoder that accepts a string as input, encodes it in UTF-8 format, and outputs UTF-8 byte stream. The TextDecoder interface represents a text decoder. The decoder takes the byte stream as the input and outputs the String string. HelpFunction is mainly used to callback and promise functions, write and output error codes, and format class strings. Encodes all bytes from the specified u8 array into a newly-allocated u8 array using the Base64 encoding scheme or Encodes the specified byte array into a String using the Base64 encoding scheme.Decodes a Base64 encoded String or input u8 array into a newly-allocated u8 array using the Base64 encoding scheme.The rational number is mainly to compare rational numbers and obtain the numerator and denominator.The LruBuffer algorithm replaces the least used data with new data when the buffer space is insufficient. The algorithm derives from the need to access resources: recently accessed data can be Will visit again in the near future. The least accessed data is the least valuable data that should be kicked out of the cache space. The Scope interface is used to describe the valid range of a field. The constructor for the Scope instance is used to create objects with specified lower and upper bounds and require that these objects be comparable. ## 目录 @@ -135,8 +135,8 @@ base/compileruntime/js_util_module/ | Interface name | Description | | -------- | -------- | | readonly encoding : string | In the TextEncoder module, get the encoding format, only UTF-8 is supported. | -| encode(input : string) : Uint8Array | Input stirng string, encode and output UTF-8 byte stream. | -| encodeInto(input : string, dest : Uint8Array) : {read : number, written : number} | Enter the stirng string, dest represents the storage location after encoding, and returns an object, read represents the number of characters that have been encoded,and written represents the size of bytes occupied by the encoded characters. | +| encode(input : string) : Uint8Array | Input string string, encode and output UTF-8 byte stream. | +| encodeInto(input : string, dest : Uint8Array) : {read : number, written : number} | Enter the string string, dest represents the storage location after encoding, and returns an object, read represents the number of characters that have been encoded,and written represents the size of bytes occupied by the encoded characters. | | constructor(encoding? : string, options? : {fatal? : boolean, ignoreBOM? : boolean}) | Constructor, the first parameter encoding indicates the format of decoding.The second parameter represents some attributes.Fatal in the attribute indicates whether an exception is thrown, and ignoreBOM indicates whether to ignore the bom flag. | | readonly encoding : string | In the TextDecoder module, get the set decoding format. | | readonly fatal : boolean | Get the setting that throws the exception. | @@ -277,30 +277,30 @@ var obj = textEncoder.encodeInto('abc', dest); 4.textDecoder() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); ``` 5.readonly encoding() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var getEncoding = textDecoder.encoding(); ``` 6.readonly fatal() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var fatalStr = textDecoder.fatal(); ``` 7.readonly ignoreBOM() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var ignoreBom = textDecoder.ignoreBOM(); ``` 8.decode() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var result = textDecoder.decode(input, {stream : true}); ``` 9.printf() @@ -1023,11 +1023,7 @@ var result = proc.isWeakSet(new WeakSet()); ``` ## Related warehouse - - -[js_util_module subsystem](https://gitee.com/OHOS_STD/js_util_module) - -[base/compileruntime/js_util_module/](base/compileruntime/js_util_module-readme.md) +[js_util_module subsystem](base/compileruntime/js_util_module-readme.md) ## License diff --git a/README_zh.md b/README_zh.md index 91fce74..4b1002c 100644 --- a/README_zh.md +++ b/README_zh.md @@ -276,30 +276,30 @@ var obj = textEncoder.encodeInto('abc', dest); 4.textDecoder() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); ``` 5.readonly encoding() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var getEncoding = textDecoder.encoding(); ``` 6.readonly fatal() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var fatalStr = textDecoder.fatal(); ``` 7.readonly ignoreBOM() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var ignoreBom = textDecoder.ignoreBOM(); ``` 8.decode() ``` import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : ture, ignoreBOM : false}); +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); var result = textDecoder.decode(input, {stream : true}); ``` 9.printf() @@ -1024,11 +1024,7 @@ var result = proc.isWeakSet(new WeakSet()); ``` ## 相关仓 - - -[js_util_module子系统](https://gitee.com/OHOS_STD/js_util_module) - -[base/compileruntime/js_util_module/](base/compileruntime/js_util_module-readme.md) +[js_util_module子系统](base/compileruntime/js_util_module-readme_zh.md) ## 许可证 diff --git a/build_ts_js.py b/build_ts_js.py index 93af118..f1ddd35 100755 --- a/build_ts_js.py +++ b/build_ts_js.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -30,8 +30,6 @@ def run_command(in_cmd): raise Exception(stdout) if __name__ == '__main__': - - PARSER_INST = argparse.ArgumentParser() PARSER_INST.add_argument('--dst-file', help='the converted target file') diff --git a/mozilla_docs.txt b/mozilla_docs.txt index a458057..2fd6176 100644 --- a/mozilla_docs.txt +++ b/mozilla_docs.txt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -15,7 +15,7 @@ The definitions of some interfaces implemented in jsapi/api/js_url.cpp are released under Mozilla license. -The definitions and functions of these interfaces are consistent with the standard interfaces under mozila license, +The definitions and functions of these interfaces are consistent with the standard interfaces under mozilla license, but the implementation of specific functions is independent and self-developed. All interfaces are described in d.ts, the following is the interface written in d.ts under to Mozilla license diff --git a/util/BUILD.gn b/util/BUILD.gn index f1f5a25..9bb1181 100755 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 diff --git a/util/js_base64.cpp b/util/js_base64.cpp index c4181be..03cbe86 100755 --- a/util/js_base64.cpp +++ b/util/js_base64.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -56,7 +56,7 @@ namespace OHOS::Util { napi_value arrayBuffer = nullptr; size_t bufferSize = outputLen; napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer); - if (memcpy_s(data, bufferSize, reinterpret_cast(rets), bufferSize) != 0) { + if (memcpy_s(data, bufferSize, reinterpret_cast(rets), bufferSize) != EOK) { FreeMemory(rets); HILOG_ERROR("copy ret to arraybuffer error"); return nullptr; @@ -101,7 +101,7 @@ namespace OHOS::Util { } if (outputLen > 0) { ret = new unsigned char[outputLen + 1]; - if (memset_s(ret, outputLen + 1, '\0', outputLen + 1) != 0) { + if (memset_s(ret, outputLen + 1, '\0', outputLen + 1) != EOK) { HILOG_ERROR("encode ret memset_s failed"); FreeMemory(ret); return nullptr; @@ -156,7 +156,7 @@ namespace OHOS::Util { napi_get_value_string_utf8(env, src, nullptr, 0, &prolen); if (prolen > 0) { inputString = new char[prolen + 1]; - if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != EOK) { FreeMemory(inputString); napi_throw_error(env, "-1", "decode inputString memset_s failed"); } @@ -175,7 +175,7 @@ namespace OHOS::Util { napi_value arrayBuffer = nullptr; size_t bufferSize = decodeOutLen; napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer); - if (memcpy_s(data, bufferSize, reinterpret_cast(pret), bufferSize) != 0) { + if (memcpy_s(data, bufferSize, reinterpret_cast(pret), bufferSize) != EOK) { FreeMemory(inputString); FreeMemory(pret); HILOG_ERROR("copy retDecode to arraybuffer error"); @@ -209,7 +209,7 @@ namespace OHOS::Util { retLen = DecodeOut(equalCount, retLen); if (retLen > 0) { retDecode = new unsigned char[retLen + 1]; - if (memset_s(retDecode, retLen + 1, '\0', retLen + 1) != 0) { + if (memset_s(retDecode, retLen + 1, '\0', retLen + 1) != EOK) { FreeMemory(retDecode); napi_throw_error(env, "-1", "decode retDecode memset_s failed"); } @@ -364,7 +364,7 @@ namespace OHOS::Util { encodeInfo->soutputLen = outputLen; if (outputLen > 0) { ret = new unsigned char[outputLen + 1]; - if (memset_s(ret, outputLen + 1, '\0', outputLen + 1) != 0) { + if (memset_s(ret, outputLen + 1, '\0', outputLen + 1) != EOK) { FreeMemory(ret); napi_throw_error(encodeInfo->env, "-1", "ret path memset_s failed"); } @@ -410,7 +410,8 @@ namespace OHOS::Util { napi_value arrayBuffer = nullptr; size_t bufferSize = stdEncodeInfo->soutputLen; napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer); - if (memcpy_s(data, bufferSize, reinterpret_cast(stdEncodeInfo->sinputEncoding), bufferSize) != 0) { + if (memcpy_s(data, bufferSize, + reinterpret_cast(stdEncodeInfo->sinputEncoding), bufferSize) != EOK) { HILOG_ERROR("copy ret to arraybuffer error"); napi_delete_async_work(env, stdEncodeInfo->worker); return; @@ -458,7 +459,7 @@ namespace OHOS::Util { napi_get_value_string_utf8(env, src, nullptr, 0, &prolen); if (prolen > 0) { inputString = new char[prolen + 1]; - if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != EOK) { napi_throw_error(env, "-1", "decode inputString memset_s failed"); } } else { @@ -542,7 +543,7 @@ namespace OHOS::Util { retLen = DecodeOut(equalCount, retLen, decodeInfo); if (retLen > 0) { retDecode = new unsigned char[retLen + 1]; - if (memset_s(retDecode, retLen + 1, '\0', retLen + 1) != 0) { + if (memset_s(retDecode, retLen + 1, '\0', retLen + 1) != EOK) { FreeMemory(retDecode); napi_throw_error(decodeInfo->env, "-1", "decode retDecode memset_s failed"); } @@ -584,7 +585,8 @@ namespace OHOS::Util { napi_value arrayBuffer = nullptr; size_t bufferSize = stdDecodeInfo->decodeOutLen; napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer); - if (memcpy_s(data, bufferSize, reinterpret_cast(stdDecodeInfo->sinputDecoding), bufferSize) != 0) { + if (memcpy_s(data, bufferSize, + reinterpret_cast(stdDecodeInfo->sinputDecoding), bufferSize) != EOK) { HILOG_ERROR("copy ret to arraybuffer error"); napi_delete_async_work(env, stdDecodeInfo->worker); return; diff --git a/util/js_base64.h b/util/js_base64.h index f5cac42..b35c7ce 100755 --- a/util/js_base64.h +++ b/util/js_base64.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index a5dc293..db58cc7 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -78,7 +78,7 @@ namespace OHOS::Util { UChar *arr = nullptr; if (limit > 0) { arr = new UChar[limit + 1]; - if (memset_s(arr, len + sizeof(UChar), 0, len + sizeof(UChar)) != 0) { + if (memset_s(arr, len + sizeof(UChar), 0, len + sizeof(UChar)) != EOK) { HILOG_ERROR("decode arr memset_s failed"); FreedMemory(arr); return nullptr; @@ -88,7 +88,7 @@ namespace OHOS::Util { return nullptr; } UChar *target = arr; - size_t tarStartPos = reinterpret_cast(arr); + size_t tarStartPos = reinterpret_cast(arr); ucnv_toUnicode(GetConverterPtr(), &target, target + len, &source, source + length, nullptr, flush, &codeFlag); size_t resultLength = 0; bool omitInitialBom = false; @@ -179,7 +179,7 @@ namespace OHOS::Util { } if (U_SUCCESS(codeFlag)) { if (decArr.limitLen > 0) { - rstLen = reinterpret_cast(decArr.target) - decArr.tarStartPos; + rstLen = reinterpret_cast(decArr.target) - decArr.tarStartPos; if (rstLen > 0 && IsUnicode() && !IsIgnoreBom() && !IsBomFlag()) { bomFlag = (arr[0] == 0xFEFF) ? true : false; label_ |= static_cast(ConverterFlags::BOM_SEEN_FLG); diff --git a/util/js_textdecoder.h b/util/js_textdecoder.h index bc74fda..1753e1d 100755 --- a/util/js_textdecoder.h +++ b/util/js_textdecoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/util/js_textencoder.cpp b/util/js_textencoder.cpp index 00d385a..375b28f 100755 --- a/util/js_textencoder.cpp +++ b/util/js_textencoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -41,7 +41,7 @@ namespace OHOS::Util { NAPI_CALL(env_, napi_get_value_string_utf8(env_, src, buffer, 0, &bufferSize)); NAPI_ASSERT(env_, bufferSize > 0, "bufferSize == 0"); buffer = new char[bufferSize + 1]; - if (memset_s(buffer, bufferSize + 1, 0, bufferSize + 1) != 0) { + if (memset_s(buffer, bufferSize + 1, 0, bufferSize + 1) != EOK) { HILOG_ERROR("buffer memset error"); delete []buffer; return nullptr; @@ -51,14 +51,14 @@ namespace OHOS::Util { void *data = nullptr; napi_value arrayBuffer = nullptr; napi_create_arraybuffer(env_, bufferSize, &data, &arrayBuffer); - if (memcpy_s(data, bufferSize, reinterpret_cast(buffer), bufferSize) != 0) { + if (memcpy_s(data, bufferSize, reinterpret_cast(buffer), bufferSize) != EOK) { HILOG_ERROR("copy buffer to arraybuffer error"); delete []buffer; return nullptr; } delete []buffer; - + buffer = nullptr; napi_value result = nullptr; NAPI_CALL(env_, napi_create_typedarray(env_, napi_uint8_array, bufferSize, arrayBuffer, 0, &result)); diff --git a/util/js_textencoder.h b/util/js_textencoder.h index ab9d419..46deaae 100755 --- a/util/js_textencoder.h +++ b/util/js_textencoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/util/js_types.cpp b/util/js_types.cpp index 57e9f7f..842863e 100644 --- a/util/js_types.cpp +++ b/util/js_types.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/util/js_types.h b/util/js_types.h index 26858e6..6c97253 100644 --- a/util/js_types.h +++ b/util/js_types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include #include #include diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index 2582e97..90603f8 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/util/src/util_js.ts b/util/src/util_js.ts index e3d7716..4fd8b1b 100644 --- a/util/src/util_js.ts +++ b/util/src/util_js.ts @@ -30,13 +30,13 @@ interface Fn{ } declare function requireInternal(s : string) : HelpUtil; const helpUtil = requireInternal('util'); -let TextEncoder = helpUtil.TextEncoder; -let TextDecoder = helpUtil.TextDecoder; -let Base64 = helpUtil.Base64; -let Types = helpUtil.Types; +var TextEncoder = helpUtil.TextEncoder; +var TextDecoder = helpUtil.TextDecoder; +var Base64 = helpUtil.Base64; +var Types = helpUtil.Types; function switchLittleObject(enter : string, obj : Object, count : number) : string | Object { - var str : string = ''; + let str : string = ''; if (obj === null) { str += obj; } else if (obj instanceof Array) { @@ -69,7 +69,7 @@ function switchLittleObject(enter : string, obj : Object, count : number) : stri function switchLittleValue(enter : string, protoName : string, obj : Object, count : number) : string { - var str : string = ''; + let str : string = ''; if (obj[protoName] === null) { str += protoName + ': null,' + enter; } else if (obj[protoName] instanceof Array) { @@ -84,7 +84,7 @@ function switchLittleValue(enter : string, protoName : string, obj : Object, cou str += switchLittleObject(enter + ' ', obj[protoName], count + 1) + ',' + enter; } } else if (typeof obj[protoName] === 'function') { - var space : string= enter; + let space : string= enter; if (obj[protoName].name !== '') { str += obj[protoName].name + ':' + space; } @@ -106,11 +106,11 @@ function switchLittleValue(enter : string, protoName : string, obj : Object, cou function arrayToString(enter : string, arr : Array, count : number) : string { - var str : string = ''; + let str : string = ''; if (!arr.length) { return ''; } - var arrayEnter : string = ', '; + let arrayEnter : string = ', '; for (let k in arr) { if (arr[k] !== null && (typeof arr[k] === 'function' || typeof arr[k] === 'object') && count <= 2) { arrayEnter += enter; @@ -124,9 +124,9 @@ function arrayToString(enter : string, arr : Array, count str += switchLittleObject(enter + ' ', i, count + 1); str += arrayEnter; } else if (typeof i === 'function') { - var space : string = enter; + let space : string = enter; space += ' '; - var end : string = ''; + let end : string = ''; if (i.name !== '') { str += '{ [Function: ' + i.name + ']' + space; end = i.name + ' { [constructor]: [Circular] } }' + arrayEnter; @@ -147,7 +147,7 @@ function arrayToString(enter : string, arr : Array, count function switchBigObject(enter : string, obj : Object, count : number) : string | Object { - var str : string = ''; + let str : string = ''; if (obj === null) { str += obj; } else if (obj instanceof Array) { @@ -177,7 +177,7 @@ function switchBigObject(enter : string, obj : Object, count : number) : string function switchBigValue(enter : string, protoName : string, obj : Object, count : number) : string { - var str : string = ''; + let str : string = ''; if (obj[protoName] === null) { str += protoName + ': null,' + enter; } else if (obj[protoName] instanceof Array) { @@ -206,12 +206,12 @@ function switchBigValue(enter : string, protoName : string, obj : Object, count } function arrayToBigString(enter : string, arr : Array, count : number) : string { - var str : string = ''; + let str : string = ''; if (!arr.length) { return ''; } - var arrayEnter = ', '; + let arrayEnter = ', '; for (let i of arr) { if (i !== null && (typeof i === 'object') && count <= 2) { arrayEnter += enter; @@ -239,7 +239,7 @@ function arrayToBigString(enter : string, arr : Array, cou } function switchIntValue(value : Object | symbol) : string { - var str : string = ''; + let str : string = ''; if (value === '') { str += 'NaN'; } else if (typeof value === 'bigint') { @@ -271,7 +271,7 @@ function switchIntValue(value : Object | symbol) : string } function switchFloatValue(value : Object | symbol) : string { - var str : string = ''; + let str : string = ''; if (value === '') { str += 'NaN'; } else if (typeof value === 'symbol') { @@ -304,7 +304,7 @@ function switchFloatValue(value : Object | symbol) : string function switchNumberValue(value : Object | symbol) : string { - var str : string = ''; + let str : string = ''; if (value === '') { str += '0'; } else if (typeof value === 'symbol') { @@ -329,7 +329,7 @@ function switchNumberValue(value : Object | symbol) : string function switchStringValue(value : Object | symbol) : string { - var str : string = ''; + let str : string = ''; if (typeof value === 'undefined') { str += 'undefined'; } else if (typeof value === 'object') { @@ -349,13 +349,13 @@ function switchStringValue(value : Object | symbol) : string // ...valueString : Array) : string; function printf(formatString : Array, ...valueString : Array) : string { - var formats : string = helpUtil.dealwithformatstring(formatString); - var arr : Array= []; + let formats : string = helpUtil.dealwithformatstring(formatString); + let arr : Array= []; arr = formats.split(' '); - var switchString : Array= []; - var valueLength : number = valueString.length; - var arrLength : number = arr.length; - var i : number= 0; + let switchString : Array= []; + let valueLength : number = valueString.length; + let arrLength : number = arr.length; + let i : number= 0; for (let sub of valueString) { if (i >= arrLength) { break; @@ -383,19 +383,19 @@ function printf(formatString : Array, ...valueString : Arr switchString.push(valueString[i].toString()); i++; } - var helpUtilString : string = helpUtil.printf(formatString, ...switchString); + let helpUtilString : string = helpUtil.printf(formatString, ...switchString); return helpUtilString; } function getErrorString(errnum : number) : string { - var errorString : string = helpUtil.getErrorString(errnum); + let errorString : string = helpUtil.getErrorString(errnum); return errorString; } function createExternalType() : Object { - var externalType : Object = helpUtil.createExternalType(); + let externalType : Object = helpUtil.createExternalType(); return externalType; } @@ -471,7 +471,7 @@ class LruBuffer public constructor(capacity?: number) { - if(capacity !== undefined) { + if (capacity !== undefined) { if (capacity <= 0 || capacity%1 !== 0 || capacity > this.maxNumber) { throw new Error('data error'); } @@ -482,7 +482,7 @@ class LruBuffer public updateCapacity(newCapacity : number) : void { - if (newCapacity <= 0 || newCapacity%1 !== 0 || newCapacity > this.maxNumber) { + if (newCapacity <= 0 || newCapacity % 1 !== 0 || newCapacity > this.maxNumber) { throw new Error('data error'); } else if (this.cache.size >newCapacity) { this.changeCapacity(newCapacity); @@ -695,7 +695,7 @@ class RationalNumber { num = den < 0 ? num * (-1) : num; den = den < 0 ? den * (-1) : den; - if (den == 0) { + if (den === 0) { if (num > 0) { this.mnum = 1; this.mden = 0; @@ -706,13 +706,13 @@ class RationalNumber this.mnum = 0; this.mden = 0; } - } else if (num == 0) { + } else if (num === 0) { this.mnum = 0; this.mden = 1; } else { let gnum : number = 0; gnum = this.getCommonDivisor(num, den); - if (gnum != 0) { + if (gnum !== 0) { this.mnum = num / gnum; this.mden = den / gnum; } @@ -721,10 +721,10 @@ class RationalNumber public createRationalFromString(str : string): RationalNumber { - if (str == null) { + if (str === null) { throw new Error('string invalid!'); } - if (str == 'NaN') { + if (str === 'NaN') { return new RationalNumber(0, 0); } let colon : number = str.indexOf(':'); @@ -742,15 +742,15 @@ class RationalNumber public compareTo(other : RationalNumber) : number { - if (this.mnum == other.mnum && this.mden == other.mden) { + if (this.mnum === other.mnum && this.mden === other.mden) { return 0; - } else if (this.mnum == 0 && this.mden == 0) { + } else if (this.mnum === 0 && this.mden === 0) { return 1; - } else if ((other.mnum == 0) && (other.mden == 0)) { + } else if ((other.mnum === 0) && (other.mden === 0)) { return -1; - } else if ((this.mden == 0 && this.mnum > 0) || (other.mden == 0 && other.mnum < 0)) { + } else if ((this.mden === 0 && this.mnum > 0) || (other.mden === 0 && other.mnum < 0)) { return 1; - } else if ((this.mden == 0 && this.mnum < 0) || (other.mden == 0 && other.mnum > 0)) { + } else if ((this.mden === 0 && this.mnum < 0) || (other.mden === 0 && other.mnum > 0)) { return -1; } let thisnum : number = this.mnum * other.mden; @@ -771,15 +771,15 @@ class RationalNumber } let thisnum : number = this.mnum * obj.mden; let objnum : number = obj.mnum * this.mden; - if (this.mnum == obj.mnum && this.mden == obj.mden) { + if (this.mnum === obj.mnum && this.mden === obj.mden) { return true; - } else if ((thisnum == objnum) && (this.mnum != 0 && this.mden != 0) && (obj.mnum != 0 && obj.mden != 0)) { + } else if ((thisnum === objnum) && (this.mnum !== 0 && this.mden !== 0) && (obj.mnum !== 0 && obj.mden !== 0)) { return true; - } else if ((this.mnum == 0 && this.mden != 0) && (obj.mnum == 0 && obj.mden != 0)) { + } else if ((this.mnum === 0 && this.mden !== 0) && (obj.mnum === 0 && obj.mden !== 0)) { return true; - } else if ((this.mnum > 0 && this.mden == 0) && (obj.mnum > 0 && obj.mden == 0)) { + } else if ((this.mnum > 0 && this.mden === 0) && (obj.mnum > 0 && obj.mden === 0)) { return true; - } else if ((this.mnum < 0 && this.mden == 0) && (obj.mnum < 0 && obj.mden == 0)) { + } else if ((this.mnum < 0 && this.mden === 0) && (obj.mnum < 0 && obj.mden === 0)) { return true; } else { return false; @@ -788,11 +788,11 @@ class RationalNumber public valueOf() : number { - if (this.mnum > 0 && this.mden == 0) { + if (this.mnum > 0 && this.mden === 0) { return Number.POSITIVE_INFINITY; - } else if (this.mnum < 0 && this.mden == 0) { + } else if (this.mnum < 0 && this.mden === 0) { return Number.NEGATIVE_INFINITY; - } else if ((this.mnum == 0) && (this.mden == 0)) { + } else if ((this.mnum === 0) && (this.mden === 0)) { return Number.NaN; } else { return this.mnum / this.mden; @@ -801,8 +801,8 @@ class RationalNumber public getCommonDivisor(number1 : number, number2 : number) : number { - if (number1 == 0 || number2 == 0) { - throw new Error("Parameter cannot be zero!"); + if (number1 === 0 || number2 === 0) { + throw new Error('Parameter cannot be zero!'); } let temp : number = 0; if (number1 < number2) { @@ -810,7 +810,7 @@ class RationalNumber number1 = number2; number2 = temp; } - while (number1 % number2 != 0) { + while (number1 % number2 !== 0) { temp = number1 % number2; number1 = number2; number2 = temp; @@ -830,28 +830,28 @@ class RationalNumber public isFinite() : boolean { - return this.mden != 0; + return this.mden !== 0; } public isNaN() : boolean { - return this.mnum == 0 && this.mden == 0; + return this.mnum === 0 && this.mden === 0; } public isZero() : boolean { - return this.mnum == 0 && this.mden != 0; + return this.mnum === 0 && this.mden !== 0; } public toString() : string { let buf : string; - if (this.mnum == 0 && this.mden == 0) { - buf = "NaN"; - } else if (this.mnum > 0 && this.mden == 0) { - buf = "Infinity"; - } else if (this.mnum < 0 && this.mden == 0) { - buf = "-Infinity"; + if (this.mnum === 0 && this.mden === 0) { + buf = 'NaN'; + } else if (this.mnum > 0 && this.mden === 0) { + buf = 'Infinity'; + } else if (this.mnum < 0 && this.mden === 0) { + buf = '-Infinity'; } else { buf = String(this.mnum) + '/' + String(this.mden); } @@ -898,7 +898,7 @@ class Scope { let resLower: boolean; let resUpper: boolean; this.checkNull(x, 'value must not be null'); - if(x instanceof Scope) { + if (x instanceof Scope) { resLower= x._lowerLimit.compareTo(this._lowerLimit); resUpper= this._upperLimit.compareTo(x._upperLimit); } else { @@ -927,8 +927,7 @@ class Scope { let reUpper: boolean; let mLower: ScopeType; let mUpper: ScopeType; - if(y) - { + if (y) { this.checkNull(x, 'lower limit must not be null'); this.checkNull(y, 'upper limit must not be null'); reLower = this._lowerLimit.compareTo(x); @@ -984,7 +983,7 @@ class Scope { } else { this.checkNull(x, 'lower limit must not be null'); - this.checkNull(y, "upper limit must not be null"); + this.checkNull(y, 'upper limit must not be null'); reLower = x.compareTo(this._lowerLimit); reUpper = this._upperLimit.compareTo(y); if (reLower && reUpper) { @@ -1003,7 +1002,7 @@ class Scope { } public checkNull(o: ScopeType, str: string): void { - if(o == null) { + if (o === null) { throw new Error(str); } } -- Gitee