diff --git a/README.md b/README.md index a189511c18e9683f0a373a4acfc87a302a765785..fff3c6792eefb7cfd737b655bef68131fd49afc6 100755 --- a/README.md +++ b/README.md @@ -132,13 +132,13 @@ base/compileruntime/js_util_module/ | getMatchCount​(): number | Obtain the number of successful matching of query values, and output the number of successful matching of query values. | | getPutCount(): number | Gets the number of times the value was added to the buffer, and the output returns the number of times the value was added to the buffer. | | isEmpty(): boolean | Checks whether the current buffer is empty and returns true if the current buffer does not contain any values. | -| get(k: key):V \| undefined | Indicates the key to query. If the specified key exists in the buffer, the value associated with the key will be returned; Otherwise, undefined is returned. | -| put(K: key, V: value): V | Adding the key value pair to the buffer and outputting the value associated with the added key; If the key to be added already exists, the original value is returned. If the key or value is empty, this exception is thrown. | +| get(key: K):V \| undefined | Indicates the key to query. If the specified key exists in the buffer, the value associated with the key will be returned; Otherwise, undefined is returned. | +| put(key: K, value: V): V | Adding the key value pair to the buffer and outputting the value associated with the added key; If the key to be added already exists, the original value is returned. If the key or value is empty, this exception is thrown. | | keys(): K[ ] | Get the key list of the value in the current buffer, and the output returns the key list sorted from the most recent access to the least recent access. | -| remove​(k: key):V \| undefined | Deletes the specified key and its associated value from the current buffer. | -| afterRemoval(boolean: isEvict, K: key, V: value, V: newValue):void | Perform subsequent operations after deleting the value. | -| contains(k: key):boolean | Checks whether the current buffer contains the specified key, and returns true if the buffer contains the specified key. | -| createDefault(k: key): V | If the value of a specific key is not calculated, subsequent operations are performed. The parameter represents the missing key, and the output returns the value associated with the key. | +| remove​(key: K):V \| undefined | Deletes the specified key and its associated value from the current buffer. | +| afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void | Perform subsequent operations after deleting the value. | +| contains(key: K): boolean | Checks whether the current buffer contains the specified key, and returns true if the buffer contains the specified key. | +| createDefault(key: K): V | If the value of a specific key is not calculated, subsequent operations are performed. The parameter represents the missing key, and the output returns the value associated with the key. | | entries(): [K,V] | Allows you to iterate over all key value pairs contained in this object. The keys and values of each pair are objects. | | \[Symbol.iterator\](): [K,V]| Returns a two-dimensional array in the form of key value pairs. | | constructor(lowerObj: ScopeType, upperObj: ScopeType) | Creates and returns a Scope object that creates a constructor for a scope instance that specifies a lower and upper bound. | @@ -292,24 +292,27 @@ var result = that.decode(buff); import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -that.encodeAsync(array).then(val=>{ -}) +await that.encodeAsync(array).then(val=>{ +}) +done() ``` -7.encodeToStringAsync() +17.encodeToStringAsync() ``` import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -that.encodeToStringAsync(array).then(val=>{ +await that.encodeToStringAsync(array).then(val=>{ }) +done() ``` 18.decodeAsync() ``` import util from '@ohos.util' var that = new util.Base64() var buff = 'czEz'; -that.decodeAsync(buff).then(val=>{ +await that.decodeAsync(buff).then(val=>{ }) +done() ``` 19.createRationalFromString() ``` diff --git a/README_zh.md b/README_zh.md index a0e4d860f01c4831cb69876c1f4381c24420fc9a..56f00e029af0ed2e32af31891691e71d6078b8a6 100644 --- a/README_zh.md +++ b/README_zh.md @@ -121,29 +121,29 @@ base/compileruntime/js_util_module/ | isZero(): boolean | 检查当前RationalNumber对象是否表示零值。 | | toString(): string | 获取当前RationalNumber对象的字符串表示形式。 | | constructor(capacity?: number) | 创建默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。 | -| updateCapacity(newCapacity:number):void | 将缓冲区容量更新为指定容量,如果 newCapacity 小于或等于 0,则抛出此异常。 | -| toString():string | 返回对象的字符串表示形式,输出对象的字符串表示 | -| values():V[] | 获取当前缓冲区中所有值的列表,输出按升序返回当前缓冲区中所有值的列表,从最近访问到最近最少访问。 | -| size():number | 获取当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 | -| capacity():number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 | -| clear():void | 从当前缓冲区清除键值对,清除键值对后,调用afterRemoval()方法依次对其执行后续操作。 | -| getCreateCount():number | 获取createDefault()返回值的次数,输出返回createDefault()返回值的次数。 | -| getMissCount():number | 获取查询值不匹配的次数,输出返回查询值不匹配的次数。 | -| getRemovalCount():number | 获取从缓冲区中逐出值的次数,输出从缓冲区中驱逐的次数。 | -| getMatchCount​():number | 获取查询值匹配成功的次数,输出返回查询值匹配成功的次数。 | -| getPutCount():number | 获取将值添加到缓冲区的次数,输出返回将值添加到缓冲区的次数。 | -| isEmpty():boolean | 检查当前缓冲区是否为空,输出如果当前缓冲区不包含任何值,则返回 true 。 | -| get(k:key):V \| undefined | 表示要查询的键,输出如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 | -| put(K key, V value):V | 将键值对添加到缓冲区,输出与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 | -| keys():K[ ] | 获取当前缓冲区中值的键列表,输出返回从最近访问到最近最少访问排序的键列表。 | -| remove​(k:key):V \| undefined | 从当前缓冲区中删除指定的键及其关联的值。 | -| afterRemoval(boolean isEvict, K key, V value, V newValue):void | 删除值后执行后续操作。 | -| contains(k:key):boolean | 检查当前缓冲区是否包含指定的键,输出如果缓冲区包含指定的键,则返回 true 。 | -| createDefault(k:key):V | 如果未计算特定键的值,则执行后续操作,参数表示丢失的键,输出返回与键关联的值。 | -| entries():[K,V] | 允许迭代包含在这个对象中的所有键值对。每对的键和值都是对象。 | -| Symbol.iterator():[K,V] | 返回以键值对得形式得一个二维数组。 | -| constructor(lowerObj: ScopeType, upperObj: ScopeType) | 创建并返回一个Scope对象,用于创建指定下限和上限的作用域实例的构造函数。 | -| toString():string | 该字符串化方法返回一个包含当前范围的字符串表示形式。 | +| updateCapacity(newCapacity: number): void | 将缓冲区容量更新为指定容量,如果 newCapacity 小于或等于 0,则抛出此异常。 | +| toString(): string | 返回对象的字符串表示形式,输出对象的字符串表示 | +| values(): V[] | 获取当前缓冲区中所有值的列表,输出按升序返回当前缓冲区中所有值的列表,从最近访问到最近最少访问。 | +| size(): number | 获取当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 | +| capacity(): number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 | +| clear(): void | 从当前缓冲区清除键值对,清除键值对后,调用afterRemoval()方法依次对其执行后续操作。 | +| getCreateCount(): number | 获取createDefault()返回值的次数,输出返回createDefault()返回值的次数。 | +| getMissCount(): number | 获取查询值不匹配的次数,输出返回查询值不匹配的次数。 | +| getRemovalCount(): number | 获取从缓冲区中逐出值的次数,输出从缓冲区中驱逐的次数。 | +| getMatchCount​(): number | 获取查询值匹配成功的次数,输出返回查询值匹配成功的次数。 | +| getPutCount(): number | 获取将值添加到缓冲区的次数,输出返回将值添加到缓冲区的次数。 | +| isEmpty(): boolean | 检查当前缓冲区是否为空,输出如果当前缓冲区不包含任何值,则返回 true 。 | +| get(key: K) : V \| undefined | 表示要查询的键,输出如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 | +| put(key: K , value: V): V | 将键值对添加到缓冲区,输出与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 | +| keys(): K[ ] | 获取当前缓冲区中值的键列表,输出返回从最近访问到最近最少访问排序的键列表。 | +| remove​(key: K): V \| undefined | 从当前缓冲区中删除指定的键及其关联的值。 | +| afterRemoval(isEvict: boolean, key: K, value : V, newValue : V):void | 删除值后执行后续操作。 | +| contains(key: K): boolean | 检查当前缓冲区是否包含指定的键,输出如果缓冲区包含指定的键,则返回 true 。 | +| createDefault(key: K): V | 如果未计算特定键的值,则执行后续操作,参数表示丢失的键,输出返回与键关联的值。 | +| entries(): [K,V] | 允许迭代包含在这个对象中的所有键值对。每对的键和值都是对象。 | +| \[Symbol.iterator\](): [K,V] | 返回以键值对得形式得一个二维数组。 | +| constructor(lowerObj: ScopeType, upperObj : ScopeType) | 创建并返回一个Scope对象,用于创建指定下限和上限的作用域实例的构造函数。 | +| toString(): string | 该字符串化方法返回一个包含当前范围的字符串表示形式。 | | intersect(range: Scope): Scope | 获取给定范围和当前范围的交集。 | | intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | 获取当前范围与给定下限和上限范围的交集。 | | getUpper(): ScopeType | 获取当前范围的上限。 | @@ -157,7 +157,7 @@ base/compileruntime/js_util_module/ | function printf(format: string, ...args: Object[]): string | printf()方法使用第一个参数作为格式字符串(其可以包含零个或多个格式说明符)来返回格式化的字符串。 | | function getErrorString(errno: number): string | getErrorString()方法使用一个系统的错误数字作为参数,用来返回系统的错误信息。 | | function callbackWrapper(original: Function): (err: Object, value: Object) => void | 参数为一个采用 async 函数(或返回 Promise 的函数)并返回遵循错误优先回调风格的函数,即将 (err, value) => ... 回调作为最后一个参数。 在回调中,第一个参数将是拒绝原因(如果 Promise 已解决,则为 null),第二个参数将是已解决的值。 | -| function promiseWrapper(original: (err: Object, value: Object) => void): Object | 参数为采用遵循常见的错误优先的回调风格的函数(也就是将 (err, value) => ... 回调作为最后一个参数),并返回一个返回 promise 的版本。 | +| function promiseWrapper(original: (err: Object, value: Object) => void): Object | 参数为采用遵循常见的错误优先的回调风格的函数(也就是将 (err, value) => ... 回调作为最后一个参数),并返回一个返回 promise 的版本。 | printf中每个说明符都替换为来自相应参数的转换后的值。 支持的说明符有: | 式样化字符 | 式样要求 | @@ -292,24 +292,27 @@ var result = that.decode(buff); import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -that.encodeAsync(array).then(val=>{ -}) +await that.encodeAsync(array).then(val=>{ +}) +done() ``` 17.encodeToStringAsync() ``` import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -that.encodeToStringAsync(array).then(val=>{ +await that.encodeToStringAsync(array).then(val=>{ }) +done() ``` 18.decodeAsync() ``` import util from '@ohos.util' var that = new util.Base64() var buff = 'czEz'; -that.decodeAsync(buff).then(val=>{ +await that.decodeAsync(buff).then(val=>{ }) +done() ``` 19.createRationalFromString() ``` diff --git a/util/build_ts_js.py b/util/build_ts_js.py index d1633c2980b94a3d83a467a0a42cd71dbf3478e9..e9762124152b0e833b30b083caedf2026eb29db7 100755 --- a/util/build_ts_js.py +++ b/util/build_ts_js.py @@ -15,18 +15,35 @@ import os import platform import argparse +import subprocess + +def run_command(cmd): + print(" ".join(cmd)) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, universal_newlines=True) + out, err = proc.communicate() + if out != "": + print(out) + exit(1) if __name__ == '__main__': build_path = os.path.abspath(os.path.join(os.getcwd(), "../..")) os.chdir("%s/base/compileruntime/js_util_module/util" % build_path) - + parser = argparse.ArgumentParser() parser.add_argument('--dst-file', help='the converted target file') input_arguments = parser.parse_args() - os.system('../../../../prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin/node ' - '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc') - os.system('cp -r ./out/util_js.js ' + input_arguments.dst_file) - os.system('rm -rf ./out') \ No newline at end of file + node = '../../../../prebuilts/build-tools/common/nodejs/\ +node-v12.18.4-linux-x64/bin/node' + tsc = '../../../../ark/ts2abc/ts2panda/node_modules/typescript/bin/tsc' + cmd = [node, tsc] + run_command(cmd) + + cmd = ['cp', "-r", './out/util_js.js', input_arguments.dst_file] + run_command(cmd) + + cmd = ['rm', "-rf", './out'] + run_command(cmd) \ No newline at end of file diff --git a/util/js_base64.cpp b/util/js_base64.cpp index 41ee699bfe7acbf834e4e53b37b4a8b4f651d67f..4581bb471cc22ac2f36cf319033ec0cb77451f4f 100755 --- a/util/js_base64.cpp +++ b/util/js_base64.cpp @@ -594,4 +594,4 @@ namespace OHOS::Util { delete[] stdDecodeInfo->sinputDecoding; delete stdDecodeInfo; } -} \ No newline at end of file +} diff --git a/util/js_base64.h b/util/js_base64.h index 44de67b2323e0b532dd22201557965e3bd34de5d..e85e775b019c7416a5964e4649b9d453919be9a7 100755 --- a/util/js_base64.h +++ b/util/js_base64.h @@ -58,7 +58,7 @@ namespace OHOS::Util { class Base64 { public: explicit Base64(napi_env env); - virtual ~Base64(){} + virtual ~Base64() {} napi_value Encode(napi_value src); napi_value EncodeToString(napi_value src); napi_value Decode(napi_value src); diff --git a/util/src/util_js.ts b/util/src/util_js.ts index 981957cda17b8a6bb9ec4afc749cb5d96a75a656..e17473952bb59f07a4e7ea4a9cddcb24534edbb7 100644 --- a/util/src/util_js.ts +++ b/util/src/util_js.ts @@ -376,23 +376,32 @@ function getErrorString(errnum : number) } function callbackified(original : any, ...args : any) - { - const maybeCb = args.pop(); - if (typeof maybeCb !== 'function') { - throw new Error('maybe is not function'); - } - const cb = (...args : any) => { - Reflect.apply(maybeCb, this, args); - }; - Reflect.apply(original, this, args).then((ret : any) => cb(null, ret), (rej : any) => cb(rej)); +{ + const maybeCb = args.pop(); + if (typeof maybeCb !== 'function') { + throw new Error('maybe is not function'); } + const cb = (...args : any) => { + Reflect.apply(maybeCb, this, args); + }; + Reflect.apply(original, this, args).then((ret : any) => cb(null, ret), (rej : any) => cb(rej)); +} + +function getOwnPropertyDescriptors(obj : any) +{ + const result : any = {}; + for (let key of Reflect.ownKeys(obj)) { + result[key] = Object.getOwnPropertyDescriptor(obj, key); + } + return result; +} function callbackWrapper(original : any) { if (typeof original !== 'function') { throw new Error('original is not function'); } - const descriptors = Object.getOwnPropertyDescriptors(original); + const descriptors = getOwnPropertyDescriptors(original); if (typeof descriptors.length.value === 'number') { descriptors.length.value++; } @@ -472,7 +481,7 @@ class LruBuffer } else { value = this.put(key, createValue); this.createCount++; - if (value !== null) { + if (value !== undefined) { this.put(key, value); this.afterRemoval(false, key, createValue, value); return value; @@ -963,4 +972,4 @@ export default { LruBuffer: LruBuffer, RationalNumber : RationalNumber, Scope : Scope, -}; +}; \ No newline at end of file