diff --git a/README.md b/README.md index d39b2d4af631b1663e3ed2816d9e4585022b00a2..2c766ffb6501b275549a84f4f1c5b21eb19fe5c5 100755 --- a/README.md +++ b/README.md @@ -74,19 +74,61 @@ base/compileruntime/js_util_module/ │ ├── createDefault() # createDefault method │ ├── entries() # entries method │ └── [Symbol.iterator]() # Symboliterator method -└── Class:Scope # Scope class - ├── constructor() # create Scope object - ├── toString() # toString method - ├── intersect() # intersect method - ├── intersect() # intersect method - ├── getUpper() # getUpper method - ├── getLower() # getLower method - ├── expand() # expand method - ├── expand() # expand method - ├── expand() # expand method - ├── contains() # contains method - ├── contains() # contains method - └── clamp() # clamp method +├── Class:Scope # Scope class +| ├── constructor() # create Scope object +| ├── toString() # toString method +| ├── intersect() # intersect method +| ├── intersect() # intersect method +| ├── getUpper() # getUpper method +| ├── getLower() # getLower method +| ├── expand() # expand method +| ├── expand() # expand method +| ├── expand() # expand method +| ├── contains() # contains method +| ├── contains() # contains method +| └── clamp() # clamp method +└── Class:Types # Types class + ├── isAnyArrayBuffer() # isAnyArrayBuffer method + ├── isArrayBufferView() # isArrayBufferView method + ├── isArgumentsObject() # isArgumentsObject method + ├── isArrayBuffer() # isArrayBuffer method + ├── isAsyncFunction() # isAsyncFunction method + ├── isBigInt64Array() # isBigInt64Array method + ├── isBigUint64Array() # isBigUint64Array method + ├── isBooleanObject() # isBooleanObject method + ├── isBoxedPrimitive() # isBoxedPrimitive method + ├── isCryptoKey() # isCryptoKey method + ├── isDataView() # isDataView method + ├── isDate() # isDate method + ├── isExternal() # isExternal method + ├── isFloat32Array() # isFloat32Arraymethod + ├── isFloat64Array() # isFloat64Array method + ├── isGeneratorFunction() # isGeneratorFunction method + ├── isGeneratorObject() # isGeneratorObject method + ├── isInt8Array() # isInt8Array method + ├── isInt16Array() # isInt16Array method + ├── isInt32Array() # isInt32Array method + ├── isKeyObject() # isKeyObject method + ├── isMap() # isMap method + ├── isMapIterator() # isMapIterator method + ├── isModuleNamespaceObject() # isModuleNamespaceObject method + ├── isNativeError() # isNativeError method + ├── isNumberObject() # isNumberObject method + ├── isPromise() # isPromise method + ├── isProxy() # isProxy method + ├── isRegExp() # isRegExp method + ├── isSet() # isSet method + ├── isSetIterator() # isSetIterator method + ├── isSharedArrayBuffer() # isSharedArrayBuffer method + ├── isStringObject() # isStringObject method + ├── isSymbolObject() # isSymbolObject method + ├── isTypedArray() # isTypedArray method + ├── isUint8Array() # isUint8Array method + ├── isUint8ClampedArray() # isUint8ClampedArray method + ├── isUint16Array() # isUint16Array method + ├── isUint32Array() # isUint32Array method + ├── isWeakMap() # isWeakMap method + └── isWeakSet() # isWeakSet method ``` ## Description @@ -157,6 +199,47 @@ base/compileruntime/js_util_module/ | function getErrorString(errno: number): string | The geterrorstring () method uses a system error number as a parameter to return system error information. | | function callbackWrapper(original: Function): (err: Object, value: Object) => void | Takes an async function (or a function that returns a Promise) and returns a function following the error-first callback style, i.e. taking an (err, value) => ... callback as the last argument. In the callback, the first argument will be the rejection reason (or null if the Promise resolved), and the second argument will be the resolved value. | | function promiseWrapper(original: (err: Object, value: Object) => void): Object | Takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises. | +| isAnyArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer or sharedarraybuffer type. | +| isArrayBufferView(value: Object): boolean | Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. | +| isArgumentsObject(value: Object): boolean | Check whether the entered value is an arguments object type. | +| isArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer type. | +| isAsyncFunction(value: Object): boolean | Check whether the value entered is an asynchronous function type. | +| isBigInt64Array(value: Object): boolean | Check whether the entered value is of bigint64array array type. | +| isBigUint64Array(value: Object): boolean | Check whether the entered value is of biguint64array array array type. | +| isBooleanObject(value: Object): boolean | Check whether the entered value is a Boolean object type. | +| isBoxedPrimitive(value: Object): boolean | Check whether the entered value is a Boolean or number or string or symbol object type. | +| isCryptoKey(value: Object): boolean | Check whether the entered value is the cryptokey object type. | +| isDataView(value: Object): boolean | Check whether the entered value is of DataView type. | +| isDate(value: Object): boolean | Check whether the entered value is of type date. | +| isExternal(value: Object): boolean | Check whether the entered value is a native external value type. | +| isFloat32Array(value: Object): boolean | Check whether the entered value is of float32array array type. | +| isFloat64Array(value: Object): boolean | Check whether the entered value is of float64array array type. | +| isGeneratorFunction(value: Object): boolean | Check whether the input value is a generator function type. | +| isGeneratorObject(value: Object): boolean | Check whether the entered value is a generator object type. | +| isInt8Array(value: Object): boolean | Check whether the entered value is of int8array array type. | +| isInt16Array(value: Object): boolean | Check whether the entered value is the int16array type. | +| isInt32Array(value: Object): boolean | Check whether the entered value is the int32array array type. | +| isKeyObject(value: Object): boolean | Check whether the entered value is the keyobject object type. | +| isMap(value: Object): boolean | Check whether the entered value is of map type. | +| isMapIterator(value: Object): boolean | Check whether the entered value is the iterator type of map. | +| isModuleNamespaceObject(value: Object): boolean | Check whether the entered value is the module namespace object object type. | +| isNativeError(value: Object): boolean | Check whether the value entered is of type error. | +| isNumberObject(value: Object): boolean | Check whether the entered value is of the number object type. | +| isPromise(value: Object): boolean | Check whether the entered value is of promise type. | +| isProxy(value: Object): boolean | Check whether the value entered is of proxy type. | +| isRegExp(value: Object): boolean | Check whether the entered value is of type regexp. | +| isSet(value: Object): boolean | Check whether the entered value is of type set. | +| isSetIterator(value: Object): boolean | Check whether the entered value is the iterator type of set. | +| isSharedArrayBuffer(value: Object): boolean | Check whether the entered value is of type sharedarraybuffer. | +| isStringObject(value: Object): boolean | Check whether the entered value is a string object type. | +| isSymbolObject(value: Object): boolean | Check whether the entered value is a symbol object type. | +| isTypedArray(value: Object): boolean | Check whether the entered value is a type contained in typedarray. | +| isUint8Array(value: Object): boolean | Check whether the entered value is the uint8array array type. | +| isUint8ClampedArray(value: Object): boolean | Check whether the entered value is the uint8clapedarray array type. | +| isUint16Array(value: Object): boolean | Check whether the entered value is the uint16array array array type. | +| isUint32Array(value: Object): boolean | Check whether the entered value is the uint32array array type. | +| isWeakMap(value: Object): boolean | Check whether the entered value is of type weakmap. | +| isWeakSet(value: Object): boolean | Check whether the entered value is of type weakset. | Each specifier in printf is replaced with a converted value from the corresponding parameter. Supported specifiers are: | Stylized character | Style requirements | @@ -675,6 +758,261 @@ var tempMiDF = new Temperature(35); var range = new Scope(tempLower, tempUpper); var result = range.clamp(tempMiDF) // => 35 ``` +63.isAnyArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAnyArrayBuffer(new ArrayBuffer([])) +``` +64.isArrayBufferView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16))); +``` +65.isArgumentsObject() +``` +import util from '@ohos.util' +function foo() { + var result = proc.isArgumentsObject(arguments); + } +var f = foo(); +``` +66.isArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBuffer(new ArrayBuffer([])); +``` +67.isAsyncFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAsyncFunction(async function foo() {}); +``` +68.isBigInt64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigInt64Array(new Int16Array([])); +``` +69.isBigUint64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigUint64Array(new Int16Array([])); +``` +70.isBooleanObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBooleanObject(new Boolean(false)); +``` +71.isBoxedPrimitive() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBoxedPrimitive(new Boolean(false)); +``` +72.isCryptoKey() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isCryptoKey(false); +``` +73.isDataView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const ab = new ArrayBuffer(20); +var result = proc.isDataView(new DataView(ab)); +``` +74.isDate() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isDate(new Date()); +``` +75.isExternal() +``` +import util from '@ohos.util' +const data = util.createExternalType(); +var reult13 = proc.isExternal(data); +``` +76.isFloat32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat32Array(new Float32Array([])); +``` +77.isFloat64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat64Array(new Float64Array([])); +``` +78.isGeneratorFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isGeneratorFunction(function* foo() {}); +``` +79.isGeneratorObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +function* foo() {} +const generator = foo(); +var result = proc.isGeneratorObject(generator); +``` +80.isInt8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt8Array(new Int8Array([])); +``` +81.isInt16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt16Array(new Int16Array([])); +``` +82.isInt32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt32Array(new Int32Array([])); +``` +83.isKeyObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isKeyObject(0); +``` +84.isMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMap(new Map()); +``` +85.isMapIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMapIterator(map.keys()); +``` +86.isModuleNamespaceObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isModuleNamespaceObject(util); +``` +87.isNativeError() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNativeError(new TypeError()); +``` +88.isNumberObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNumberObject(new Number(0)); +``` +89.isPromise() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isPromise(Promise.resolve(42)); +``` +90.isProxy() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const target = {}; +const proxy = new Proxy(target, {}); +var result = proc.isProxy(proxy); +``` +91.isRegExp() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isRegExp(new RegExp('abc')); +``` +92.isSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSet(new Set()); +``` +93.isSetIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const set = new Set(); +var result = proc.isSetIterator(set.keys()); +``` +94.isSharedArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); +``` +95.isStringObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isStringObject(new String('foo')); +``` +96.isSymbolObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const symbols = Symbol('foo'); +var result = proc.isSymbolObject(Object(symbols)); +``` +97.isTypedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isTypedArray(new Float64Array([])); +``` +98.isUint8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8Array(new Uint8Array([])); +``` +99.isUint8ClampedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); +``` +100.isUint16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint16Array(new Uint16Array([])); +``` +101.isUint32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint32Array(new Uint32Array([])); +``` +102.isWeakMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakMap(new WeakMap()); +``` +103.isWeakSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakSet(new WeakSet()); +``` ## Related warehouse [js_util_module subsystem](https://gitee.com/OHOS_STD/js_util_module) diff --git a/README_zh.md b/README_zh.md index a60319233717897cbec90fdc1ae1a2e7e9bf7961..d010d056200966c426556d8ae68a03dffce3d6fc 100644 --- a/README_zh.md +++ b/README_zh.md @@ -74,19 +74,61 @@ base/compileruntime/js_util_module/ │ ├── createDefault() # createDefault方法 │ ├── entries() # entries方法 │ └── [Symbol.iterator]() # Symboliterator方法 -└── Class:Scope # Scope类 - ├── constructor() # 创建Scope对象 - ├── toString() # toString方法 - ├── intersect() # intersect方法 - ├── intersect() # intersect方法 - ├── getUpper() # getUpper方法 - ├── getLower() # getLower方法 - ├── expand() # expand方法 - ├── expand() # expand方法 - ├── expand() # expand法 - ├── contains() # contains方法 - ├── contains() # contains方法 - └── clamp() # clamp方法 +|—— Class:Scope # Scope类 +| ├── constructor() # 创建Scope对象 +| ├── toString() # toString方法 +| ├── intersect() # intersect方法 +| ├── intersect() # intersect方法 +| ├── getUpper() # getUpper方法 +| ├── getLower() # getLower方法 +| ├── expand() # expand方法 +| ├── expand() # expand方法 +| ├── expand() # expand法 +| ├── contains() # contains方法 +| ├── contains() # contains方法 +| └── clamp() # clamp方法 +└── Class:Types # Types类 + ├── isAnyArrayBuffer() # isAnyArrayBuffer方法 + ├── isArrayBufferView() # isArrayBufferView方法 + ├── isArgumentsObject() # isArgumentsObject方法 + ├── isArrayBuffer() # isArrayBuffer方法 + ├── isAsyncFunction() # isAsyncFunction方法 + ├── isBigInt64Array() # isBigInt64Array方法 + ├── isBigUint64Array() # isBigUint64Array方法 + ├── isBooleanObject() # isBooleanObject方法 + ├── isBoxedPrimitive() # isBoxedPrimitive方法 + ├── isCryptoKey() # isCryptoKey方法 + ├── isDataView() # isDataView方法 + ├── isDate() # isDate方法 + ├── isExternal() # isExternal方法 + ├── isFloat32Array() # isFloat32Array方法 + ├── isFloat64Array() # isFloat64Array方法 + ├── isGeneratorFunction() # isGeneratorFunction方法 + ├── isGeneratorObject() # isGeneratorObject方法 + ├── isInt8Array() # isInt8Array方法 + ├── isInt16Array() # isInt16Array方法 + ├── isInt32Array() # isInt32Array方法 + ├── isKeyObject() # isKeyObject方法 + ├── isMap() # isMap方法 + ├── isMapIterator() # isMapIterator方法 + ├── isModuleNamespaceObject() # isModuleNamespaceObject方法 + ├── isNativeError() # isNativeError方法 + ├── isNumberObject() # isNumberObject方法 + ├── isPromise() # isPromise方法 + ├── isProxy() # isProxy方法 + ├── isRegExp() # isRegExp方法 + ├── isSet() # isSet方法 + ├── isSetIterator() # isSetIterator方法 + ├── isSharedArrayBuffer() # isSharedArrayBuffer方法 + ├── isStringObject() # isStringObject方法 + ├── isSymbolObject() # isSymbolObject方法 + ├── isTypedArray() # isTypedArray方法 + ├── isUint8Array() # isUint8Array方法 + ├── isUint8ClampedArray() # isUint8ClampedArray方法 + ├── isUint16Array() # isUint16Array方法 + ├── isUint32Array() # isUint32Array方法 + ├── isWeakMap() # isWeakMap方法 + └── isWeakSet() # isWeakSet方法 ``` ## 说明 @@ -158,6 +200,47 @@ base/compileruntime/js_util_module/ | 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 的版本。 | +| isAnyArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer或SharedArrayBuffer类型。 | +| isArrayBufferView(value: Object): boolean | 检查输入的value是否是napi_int8_array或napi_uint8_array或napi_uint8_clamped_array或napi_int16_array或napi_uint16_array或napi_int32_array或napi_uint32_array或napi_float32_array或napi_float64_array数组或DataView类型。 | +| isArgumentsObject(value: Object): boolean | 检查输入的value是否是一个arguments对象类型。 | +| isArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer类型。 | +| isAsyncFunction(value: Object): boolean | 检查输入的value是否是异步函数类型。 | +| isBigInt64Array(value: Object): boolean | 检查输入的value是否是BigInt64Array数组类型。 | +| isBigUint64Array(value: Object): boolean | 检查输入的value是否是BigUint64Array数组类型。 | +| isBooleanObject(value: Object): boolean | 检查输入的value是否是一个布尔对象类型。 | +| isBoxedPrimitive(value: Object): boolean | 检查输入的value是否是Boolean或Number或String或Symbol对象类型。 | +| isCryptoKey(value: Object): boolean | 检查输入的value是否是CryptoKey对象类型。 | +| isDataView(value: Object): boolean | 检查输入的value是否是DataView类型。 | +| isDate(value: Object): boolean | 检查输入的value是否是Date类型。 | +| isExternal(value: Object): boolean | 检查输入的value是否是一个native External值类型。 | +| isFloat32Array(value: Object): boolean | 检查输入的value是否是Float32Array数组类型。 | +| isFloat64Array(value: Object): boolean | 检查输入的value是否是Float64Array数组类型。 | +| isGeneratorFunction(value: Object): boolean | 检查输入的value是否是一个generator函数类型。 | +| isGeneratorObject(value: Object): boolean | 检查输入的value是否是一个generator对象类型。 | +| isInt8Array(value: Object): boolean | 检查输入的value是否是Int8Array数组类型。 | +| isInt16Array(value: Object): boolean | 检查输入的value是否是Int16Array数组类型。 | +| isInt32Array(value: Object): boolean | 检查输入的value是否是Int32Array数组类型。 | +| isKeyObject(value: Object): boolean | 检查输入的value是否是KeyObject对象类型。 | +| isMap(value: Object): boolean | 检查输入的value是否是Map类型。 | +| isMapIterator(value: Object): boolean | 检查输入的value是否是Map的iterator类型。 | +| isModuleNamespaceObject(value: Object): boolean | 检查输入的value是否是Module Namespace Object对象类型。 | +| isNativeError(value: Object): boolean | 检查输入的value是否是Error类型。 | +| isNumberObject(value: Object): boolean | 检查输入的value是否是Number对象类型。 | +| isPromise(value: Object): boolean | 检查输入的value是否是Promise类型。 | +| isProxy(value: Object): boolean | 检查输入的value是否是Proxy类型。 | +| isRegExp(value: Object): boolean | 检查输入的value是否是RegExp类型。 | +| isSet(value: Object): boolean | 检查输入的value是否是Set类型。 | +| isSetIterator(value: Object): boolean | 检查输入的value是否是Set的iterator类型。 | +| isSharedArrayBuffer(value: Object): boolean | 检查输入的value是否是SharedArrayBuffer类型。 | +| isStringObject(value: Object): boolean | 检查输入的value是否是一个String对象类型。 | +| isSymbolObject(value: Object): boolean | 检查输入的value是否是一个Symbol对象类型。 | +| isTypedArray(value: Object): boolean | 检查输入的value是否是TypedArray包含的类型。 | +| isUint8Array(value: Object): boolean | 检查输入的value是否是Uint8Array数组类型。 | +| isUint8ClampedArray(value: Object): boolean | 检查输入的value是否是Uint8ClampedArray数组类型。 | +| isUint16Array(value: Object): boolean | 检查输入的value是否是Uint16Array数组类型。 | +| isUint32Array(value: Object): boolean | 检查输入的value是否是Uint32Array数组类型。 | +| isWeakMap(value: Object): boolean | 检查输入的value是否是WeakMap类型。 | +| isWeakSet(value: Object): boolean | 检查输入的value是否是WeakSet类型。 | printf中每个说明符都替换为来自相应参数的转换后的值。 支持的说明符有: | 式样化字符 | 式样要求 | @@ -676,6 +759,261 @@ var tempMiDF = new Temperature(35); var range = new Scope(tempLower, tempUpper); var result = range.clamp(tempMiDF) // => 35 ``` +63.isAnyArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAnyArrayBuffer(new ArrayBuffer([])) +``` +64.isArrayBufferView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16))); +``` +65.isArgumentsObject() +``` +import util from '@ohos.util' +function foo() { + var result = proc.isArgumentsObject(arguments); + } +var f = foo(); +``` +66.isArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBuffer(new ArrayBuffer([])); +``` +67.isAsyncFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAsyncFunction(async function foo() {}); +``` +68.isBigInt64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigInt64Array(new Int16Array([])); +``` +69.isBigUint64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigUint64Array(new Int16Array([])); +``` +70.isBooleanObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBooleanObject(new Boolean(false)); +``` +71.isBoxedPrimitive() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBoxedPrimitive(new Boolean(false)); +``` +72.isCryptoKey() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isCryptoKey(false); +``` +73.isDataView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const ab = new ArrayBuffer(20); +var result = proc.isDataView(new DataView(ab)); +``` +74.isDate() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isDate(new Date()); +``` +75.isExternal() +``` +import util from '@ohos.util' +const data = util.createExternalType(); +var reult13 = proc.isExternal(data); +``` +76.isFloat32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat32Array(new Float32Array([])); +``` +77.isFloat64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat64Array(new Float64Array([])); +``` +78.isGeneratorFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isGeneratorFunction(function* foo() {}); +``` +79.isGeneratorObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +function* foo() {} +const generator = foo(); +var result = proc.isGeneratorObject(generator); +``` +80.isInt8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt8Array(new Int8Array([])); +``` +81.isInt16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt16Array(new Int16Array([])); +``` +82.isInt32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt32Array(new Int32Array([])); +``` +83.isKeyObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isKeyObject(0); +``` +84.isMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMap(new Map()); +``` +85.isMapIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMapIterator(map.keys()); +``` +86.isModuleNamespaceObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isModuleNamespaceObject(util); +``` +87.isNativeError() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNativeError(new TypeError()); +``` +88.isNumberObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNumberObject(new Number(0)); +``` +89.isPromise() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isPromise(Promise.resolve(42)); +``` +90.isProxy() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const target = {}; +const proxy = new Proxy(target, {}); +var result = proc.isProxy(proxy); +``` +91.isRegExp() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isRegExp(new RegExp('abc')); +``` +92.isSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSet(new Set()); +``` +93.isSetIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const set = new Set(); +var result = proc.isSetIterator(set.keys()); +``` +94.isSharedArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); +``` +95.isStringObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isStringObject(new String('foo')); +``` +96.isSymbolObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const symbols = Symbol('foo'); +var result = proc.isSymbolObject(Object(symbols)); +``` +97.isTypedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isTypedArray(new Float64Array([])); +``` +98.isUint8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8Array(new Uint8Array([])); +``` +99.isUint8ClampedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); +``` +100.isUint16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint16Array(new Uint16Array([])); +``` +101.isUint32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint32Array(new Uint32Array([])); +``` +102.isWeakMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakMap(new WeakMap()); +``` +103.isWeakSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakSet(new WeakSet()); +``` ## 相关仓 [js_util_module子系统](https://gitee.com/OHOS_STD/js_util_module) diff --git a/util/BUILD.gn b/util/BUILD.gn index 50a31a079e15148ee2dc037c1d62e6d9faf725ab..1b57306c2496795e74df9abd86395365734f74ff 100755 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -84,6 +84,7 @@ ohos_shared_library("util") { "js_base64.cpp", "js_textdecoder.cpp", "js_textencoder.cpp", + "js_types.cpp", "native_module_util.cpp", ] diff --git a/util/js_types.cpp b/util/js_types.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd1db150d6180941a0eb0b5d8b325963c4537e2f --- /dev/null +++ b/util/js_types.cpp @@ -0,0 +1,610 @@ +/* + * 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. + */ + +#include "js_types.h" +#include +#include +#include "utils/log.h" +#include "securec.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +namespace OHOS::Util { + Types::Types(napi_env env_) : env_(env_) {} + + napi_value Types::IsAnyArrayBuffer(napi_value src) + { + bool flag = false; + bool rstFlag = false; + napi_value rst = nullptr; + napi_status napiRst = napi_is_arraybuffer(env_, src, &rstFlag); + if (napiRst == napi_ok && rstFlag) { + flag = true; + } + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsArrayBufferView(napi_value src) + { + napi_valuetype valuetype; + napi_value rst = nullptr; + bool flag = false; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype != napi_valuetype::napi_object) { + napi_get_boolean(env_, flag, &rst); + return rst; + } + bool rstFlag = false; + napi_status napiRst = napi_is_dataview(env_, src, &rstFlag); + if (napiRst == napi_ok && rstFlag) { + napi_get_boolean(env_, rstFlag, &rst); + return rst; + } + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); + switch (type) { + case napi_typedarray_type::napi_int8_array: + case napi_typedarray_type::napi_uint8_array: + case napi_typedarray_type::napi_uint8_clamped_array: + case napi_typedarray_type::napi_int16_array: + case napi_typedarray_type::napi_uint16_array: + case napi_typedarray_type::napi_int32_array: + case napi_typedarray_type::napi_uint32_array: + case napi_typedarray_type::napi_float32_array: + case napi_typedarray_type::napi_float64_array: + flag = true; + break; + default : + flag = false; + break; + } + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsArgumentsObject(napi_value src) + { + napi_valuetype result; + NAPI_CALL(env_, napi_typeof(env_, src, &result)); + bool flag = false; + if (result == napi_object) { + NAPI_CALL(env_, napi_is_arguments_object(env_, src, &flag)); + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsArrayBuffer(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_arraybuffer(env_, src, &flag)); + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsAsyncFunction(napi_value src) + { + napi_valuetype result; + NAPI_CALL(env_, napi_typeof(env_, src, &result)); + bool flag = false; + if (result == napi_function) { + NAPI_CALL(env_, napi_is_async_function(env_, src, &flag)); + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsBigInt64Array(napi_value src) + { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); + bool flag = false; + if (type == napi_typedarray_type::napi_bigint64_array) { + flag = true; + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + HILOG_INFO("The type is not supported!"); + return rst; + } + + napi_value Types::IsBigUint64Array(napi_value src) + { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); + bool flag = false; + if (type == napi_typedarray_type::napi_biguint64_array) { + flag = true; + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + HILOG_INFO("The type is not supported!"); + return rst; + } + + napi_value Types::IsBooleanObject(napi_value src) + { + napi_valuetype result; + NAPI_CALL(env_, napi_typeof(env_, src, &result)); + bool flag = false; + if (result == napi_object) { + NAPI_CALL(env_, napi_is_boolean_object(env_, src, &flag)); + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsBoxedPrimitive(napi_value src) + { + bool flag = false; + bool rstNum = false; + bool rstStr = false; + bool rstBool = false; + bool rstSym = false; + NAPI_CALL(env_, napi_get_value_bool(env_, IsNumberObject(src), &rstNum)); + NAPI_CALL(env_, napi_get_value_bool(env_, IsStringObject(src), &rstStr)); + NAPI_CALL(env_, napi_get_value_bool(env_, IsBooleanObject(src), &rstBool)); + NAPI_CALL(env_, napi_get_value_bool(env_, IsSymbolObject(src), &rstSym)); + if (rstNum || rstStr || rstBool || rstSym) { + flag = true; + } + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsCryptoKey(napi_value src) + { + bool flag = false; + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + HILOG_INFO("The type is not supported!"); + return rst; + } + + napi_value Types::IsDataView(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_dataview(env_, src, &flag)); + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsDate(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_date(env_, src, &flag)); + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsExternal(napi_value src) + { + napi_valuetype type; + bool flag = false; + NAPI_CALL(env_, napi_typeof(env_, src, &type)); + if (type == napi_valuetype::napi_external) { + flag = true; + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsFloat32Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_float32_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsFloat64Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_float64_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsGeneratorFunction(napi_value src) + { + napi_valuetype result; + NAPI_CALL(env_, napi_typeof(env_, src, &result)); + bool flag = false; + if (result == napi_function) { + NAPI_CALL(env_, napi_is_generator_function(env_, src, &flag)); + } + napi_value rst = nullptr; + napi_get_boolean(env_, flag, &rst); + return rst; + } + + napi_value Types::IsGeneratorObject(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_generator_object(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsInt8Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_int8_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsInt16Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_int16_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsInt32Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_int32_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsKeyObject(napi_value src) + { + bool flag = false; + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + HILOG_INFO("The type is not supported!"); + return result; + } + + napi_value Types::IsMap(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_map(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsMapIterator(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_map_iterator(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsModuleNamespaceObject(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_module_namespace_object(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + HILOG_INFO("The type is not supported!"); + return result; + } + + napi_value Types::IsNativeError(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_error(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsNumberObject(napi_value src) + { + bool flag = false; + napi_valuetype valuetype; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + NAPI_CALL(env_, napi_is_number_object(env_, src, &flag)); + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsPromise(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_promise(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsProxy(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_proxy(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsRegExp(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_reg_exp(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsSet(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_set(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsSetIterator(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_set_iterator(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsSharedArrayBuffer(napi_value src) + { + bool flag = false; + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + HILOG_INFO("The type is not supported!"); + return result; + } + + napi_value Types::IsStringObject(napi_value src) + { + bool flag = false; + napi_valuetype valuetype; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + NAPI_CALL(env_, napi_is_string_object(env_, src, &flag)); + } + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsSymbolObject(napi_value src) + { + bool flag = false; + napi_value result = nullptr; + napi_valuetype valuetype; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + NAPI_CALL(env_, napi_is_symbol_object(env_, src, &flag)); + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsTypedArray(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_typedarray(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsUint8Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_uint8_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsUint8ClampedArray(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_uint8_clamped_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsUint16Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_uint16_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsUint32Array(napi_value src) + { + napi_valuetype valuetype; + bool flag = false; + napi_value result = nullptr; + NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + if (valuetype == napi_valuetype::napi_object) { + napi_typedarray_type type; + size_t byteOffset = 0; + size_t length = 0; + void* resultData = nullptr; + napi_value resultBuffer = nullptr; + NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset)); + if (type == napi_typedarray_type::napi_uint32_array) { + flag = true; + } + } + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsWeakMap(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_weak_map(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } + + napi_value Types::IsWeakSet(napi_value src) + { + bool flag = false; + NAPI_CALL(env_, napi_is_weak_set(env_, src, &flag)); + napi_value result = nullptr; + napi_get_boolean(env_, flag, &result); + return result; + } +} \ No newline at end of file diff --git a/util/js_types.h b/util/js_types.h new file mode 100644 index 0000000000000000000000000000000000000000..fadbcd361409da00ea12cf6a0f2dcf79f42b631a --- /dev/null +++ b/util/js_types.h @@ -0,0 +1,77 @@ +/* + * 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. + */ +#include +#include +#include + +#include "napi/native_node_api.h" +#include "native_engine/native_engine.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +#ifndef BASE_COMPILERUNTIME_JS_UTIL_MODULE_TYPES_CLASS_H +#define BASE_COMPILERUNTIME_JS_UTIL_MODULE_TYPES_CLASS_H + +namespace OHOS::Util { + class Types { + public: + explicit Types(napi_env env); + virtual ~Types() {} + napi_value IsAnyArrayBuffer(napi_value src); + napi_value IsArrayBufferView(napi_value src); + napi_value IsArgumentsObject(napi_value src); + napi_value IsArrayBuffer(napi_value src); + napi_value IsAsyncFunction(napi_value src); + napi_value IsBigInt64Array(napi_value src); + napi_value IsBigUint64Array(napi_value src); + napi_value IsBooleanObject(napi_value src); + napi_value IsBoxedPrimitive(napi_value src); + napi_value IsCryptoKey(napi_value src); + napi_value IsDataView(napi_value src); + napi_value IsDate(napi_value src); + napi_value IsExternal(napi_value src); + napi_value IsFloat32Array(napi_value src); + napi_value IsFloat64Array(napi_value src); + napi_value IsGeneratorFunction(napi_value src); + napi_value IsGeneratorObject(napi_value src); + napi_value IsInt8Array(napi_value src); + napi_value IsInt16Array(napi_value src); + napi_value IsInt32Array(napi_value src); + napi_value IsKeyObject(napi_value src); + napi_value IsMap(napi_value src); + napi_value IsMapIterator(napi_value src); + napi_value IsModuleNamespaceObject(napi_value src); + napi_value IsNativeError(napi_value src); + napi_value IsNumberObject(napi_value src); + napi_value IsPromise(napi_value src); + napi_value IsProxy(napi_value src); + napi_value IsRegExp(napi_value src); + napi_value IsSet(napi_value src); + napi_value IsSetIterator(napi_value src); + napi_value IsSharedArrayBuffer(napi_value src); + napi_value IsStringObject(napi_value src); + napi_value IsSymbolObject(napi_value src); + napi_value IsTypedArray(napi_value src); + napi_value IsUint8Array(napi_value src); + napi_value IsUint8ClampedArray(napi_value src); + napi_value IsUint16Array(napi_value src); + napi_value IsUint32Array(napi_value src); + napi_value IsWeakMap(napi_value src); + napi_value IsWeakSet(napi_value src); + private: + napi_env env_; + }; +} +#endif \ No newline at end of file diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index e16c369ff0d935dff59565027f374f753d4df45a..67faef9d8d7479ba1e546956de59d9cd0d18ea0c 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -19,6 +19,7 @@ #include "js_textdecoder.h" #include "js_textencoder.h" #include "js_base64.h" +#include "js_types.h" #include "napi/native_api.h" #include "napi/native_node_api.h" @@ -645,6 +646,636 @@ namespace OHOS::Util { return result; } + // Types + static napi_value CreateExternalType(napi_env env, napi_callback_info info) + { + napi_value result = nullptr; + const char testStr[] = "test"; + napi_status status = napi_create_external( + env, (void*)testStr, + [](napi_env env, void* data, void* hint) {}, + (void*)testStr, &result); + if (status != napi_ok) { + return NULL; + } + return result; + } + + static napi_value TypesConstructor(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + void* data = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data)); + auto objectInfo = new Types(env); + napi_wrap( + env, thisVar, objectInfo, + [](napi_env env, void* data, void* hint) { + auto objectInfo = (Types*)data; + if (objectInfo != nullptr) { + delete objectInfo; + } + }, + nullptr, nullptr); + return thisVar; + } + + static napi_value IsAnyArrayBuffer(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsAnyArrayBuffer(args); + return rst; + } + + static napi_value IsArrayBufferView(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsArrayBufferView(args); + return rst; + } + + static napi_value IsArgumentsObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsArgumentsObject(args); + return rst; + } + + static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsArrayBuffer(args); + return rst; + } + + static napi_value IsAsyncFunction(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsAsyncFunction(args); + return rst; + } + + static napi_value IsBigInt64Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsBigInt64Array(args); + return rst; + } + + static napi_value IsBigUint64Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsBigUint64Array(args); + return rst; + } + + static napi_value IsBooleanObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsBooleanObject(args); + return rst; + } + + static napi_value IsBoxedPrimitive(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsBoxedPrimitive(args); + return rst; + } + + static napi_value IsCryptoKey(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsCryptoKey(args); + return rst; + } + + static napi_value IsDataView(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsDataView(args); + return rst; + } + + static napi_value IsDate(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsDate(args); + return rst; + } + + static napi_value IsExternal(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsExternal(args); + return rst; + } + + static napi_value IsFloat32Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsFloat32Array(args); + return rst; + } + + static napi_value IsFloat64Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsFloat64Array(args); + return rst; + } + + static napi_value IsGeneratorFunction(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value rst = object->IsGeneratorFunction(args); + return rst; + } + + static napi_value IsGeneratorObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsGeneratorObject(args); + return result; + } + + static napi_value IsInt8Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsInt8Array(args); + return result; + } + + static napi_value IsInt16Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsInt16Array(args); + return result; + } + + static napi_value IsInt32Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsInt32Array(args); + return result; + } + + static napi_value IsKeyObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsKeyObject(args); + return result; + } + + static napi_value IsMap(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsMap(args); + return result; + } + + static napi_value IsMapIterator(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsMapIterator(args); + return result; + } + + static napi_value IsModuleNamespaceObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsModuleNamespaceObject(args); + return result; + } + + static napi_value IsNativeError(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsNativeError(args); + return result; + } + + static napi_value IsNumberObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsNumberObject(args); + return result; + } + + static napi_value IsPromise(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsPromise(args); + return result; + } + + static napi_value IsProxy(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsProxy(args); + return result; + } + + static napi_value IsRegExp(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsRegExp(args); + return result; + } + + static napi_value IsSet(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsSet(args); + return result; + } + + static napi_value IsSetIterator(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsSetIterator(args); + return result; + } + + static napi_value IsSharedArrayBuffer(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsSharedArrayBuffer(args); + return result; + } + + static napi_value IsStringObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsStringObject(args); + return result; + } + + static napi_value IsSymbolObject(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsSymbolObject(args); + return result; + } + + static napi_value IsTypedArray(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsTypedArray(args); + return result; + } + + static napi_value IsUint8Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsUint8Array(args); + return result; + } + + static napi_value IsUint8ClampedArray(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsUint8ClampedArray(args); + return result; + } + + static napi_value IsUint16Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsUint16Array(args); + return result; + } + + static napi_value IsUint32Array(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsUint32Array(args); + return result; + } + + static napi_value IsWeakMap(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsWeakMap(args); + return result; + } + + static napi_value IsWeakSet(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + size_t requireArgc = 1; + size_t argc = 1; + napi_value args = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); + Types* object = nullptr; + NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); + napi_value result = object->IsWeakSet(args); + return result; + } + + static napi_value TypeofInit(napi_env env, napi_value exports) + { + const char* typeofClassName = "Types"; + napi_value typeofClass = nullptr; + static napi_property_descriptor typeofDesc[] = { + DECLARE_NAPI_FUNCTION("isBigInt64Array", IsBigInt64Array), + DECLARE_NAPI_FUNCTION("isBigUint64Array", IsBigUint64Array), + DECLARE_NAPI_FUNCTION("isBooleanObject", IsBooleanObject), + DECLARE_NAPI_FUNCTION("isBoxedPrimitive", IsBoxedPrimitive), + DECLARE_NAPI_FUNCTION("isAnyArrayBuffer", IsAnyArrayBuffer), + DECLARE_NAPI_FUNCTION("isArrayBufferView", IsArrayBufferView), + DECLARE_NAPI_FUNCTION("isArgumentsObject", IsArgumentsObject), + DECLARE_NAPI_FUNCTION("isArrayBuffer", IsArrayBuffer), + DECLARE_NAPI_FUNCTION("isCryptoKey", IsCryptoKey), + DECLARE_NAPI_FUNCTION("isDataView", IsDataView), + DECLARE_NAPI_FUNCTION("isDate", IsDate), + DECLARE_NAPI_FUNCTION("isExternal", IsExternal), + DECLARE_NAPI_FUNCTION("isFloat32Array", IsFloat32Array), + DECLARE_NAPI_FUNCTION("isFloat64Array", IsFloat64Array), + DECLARE_NAPI_FUNCTION("isGeneratorFunction", IsGeneratorFunction), + DECLARE_NAPI_FUNCTION("isGeneratorObject", IsGeneratorObject), + DECLARE_NAPI_FUNCTION("isInt8Array", IsInt8Array), + DECLARE_NAPI_FUNCTION("isInt16Array", IsInt16Array), + DECLARE_NAPI_FUNCTION("isInt32Array", IsInt32Array), + DECLARE_NAPI_FUNCTION("isKeyObject", IsKeyObject), + DECLARE_NAPI_FUNCTION("isMap", IsMap), + DECLARE_NAPI_FUNCTION("isMapIterator", IsMapIterator), + DECLARE_NAPI_FUNCTION("isModuleNamespaceObject", IsModuleNamespaceObject), + DECLARE_NAPI_FUNCTION("isNativeError", IsNativeError), + DECLARE_NAPI_FUNCTION("isNumberObject", IsNumberObject), + DECLARE_NAPI_FUNCTION("isPromise", IsPromise), + DECLARE_NAPI_FUNCTION("isProxy", IsProxy), + DECLARE_NAPI_FUNCTION("isRegExp", IsRegExp), + DECLARE_NAPI_FUNCTION("isSet", IsSet), + DECLARE_NAPI_FUNCTION("isSetIterator", IsSetIterator), + DECLARE_NAPI_FUNCTION("isSharedArrayBuffer", IsSharedArrayBuffer), + DECLARE_NAPI_FUNCTION("isStringObject", IsStringObject), + DECLARE_NAPI_FUNCTION("isSymbolObject", IsSymbolObject), + DECLARE_NAPI_FUNCTION("isTypedArray", IsTypedArray), + DECLARE_NAPI_FUNCTION("isUint8Array", IsUint8Array), + DECLARE_NAPI_FUNCTION("isUint8ClampedArray", IsUint8ClampedArray), + DECLARE_NAPI_FUNCTION("isUint16Array", IsUint16Array), + DECLARE_NAPI_FUNCTION("isUint32Array", IsUint32Array), + DECLARE_NAPI_FUNCTION("isWeakMap", IsWeakMap), + DECLARE_NAPI_FUNCTION("isWeakSet", IsWeakSet), + DECLARE_NAPI_FUNCTION("isAsyncFunction", IsAsyncFunction), + }; + NAPI_CALL(env, napi_define_class(env, typeofClassName, strlen(typeofClassName), TypesConstructor, + nullptr, sizeof(typeofDesc) / sizeof(typeofDesc[0]), typeofDesc, + &typeofClass)); + static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Types", typeofClass) }; + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); + return exports; + } + static napi_value Base64Init(napi_env env, napi_value exports) { const char *base64ClassName = "Base64"; @@ -673,10 +1304,12 @@ namespace OHOS::Util { DECLARE_NAPI_FUNCTION("printf", Printf), DECLARE_NAPI_FUNCTION("geterrorstring", GetErrorString), DECLARE_NAPI_FUNCTION("dealwithformatstring", DealWithFormatString), + DECLARE_NAPI_FUNCTION("createExternalType", CreateExternalType), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); TextcoderInit(env, exports); Base64Init(env, exports); + TypeofInit(env, exports); return exports; } diff --git a/util/src/util_js.ts b/util/src/util_js.ts index 09cf79dcbb6f4e6951c4e582e055fbfa9375a9a3..818c06937e72483d6f570a3e0aeb20feb125368e 100644 --- a/util/src/util_js.ts +++ b/util/src/util_js.ts @@ -17,6 +17,7 @@ const helpUtil = requireInternal('util'); let TextEncoder = helpUtil.TextEncoder; let TextDecoder = helpUtil.TextDecoder; let Base64 = helpUtil.Base64; +let Types = helpUtil.Types; function switchLittleObject(enter : string, obj : any, count : number) { @@ -375,6 +376,12 @@ function getErrorString(errnum : number) return errorString; } +function createExternalType() +{ + var externalType = helpUtil.createExternalType(); + return externalType; +} + function callbackified(original : any, ...args : any) { const maybeCb = args.pop(); @@ -966,9 +973,11 @@ export default { getErrorString: getErrorString, callbackWrapper: callbackWrapper, promiseWrapper: promiseWrapper, + createExternalType: createExternalType, TextEncoder: TextEncoder, TextDecoder: TextDecoder, Base64: Base64, + Types: Types, LruBuffer: LruBuffer, RationalNumber : RationalNumber, Scope : Scope,