1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <cstring> 17 #include <sys/sysinfo.h> 18 #include <unistd.h> 19 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 #include "native_engine/native_engine.h" 23 24 #ifndef UTIL_JS_TYPES_H_ 25 #define UTIL_JS_TYPES_H_ 26 27 namespace OHOS::Util { 28 class Types { 29 public: 30 /** 31 * Constructor of Types. 32 * 33 */ Types()34 explicit Types() {} 35 36 /** 37 * Destructor of Types. 38 */ ~Types()39 virtual ~Types() {} 40 41 /** 42 * Check whether the entered value is of arraybuffer type. 43 * 44 * @param env NAPI environment parameters. 45 * @param src Object to be tested. 46 */ 47 napi_value IsAnyArrayBuffer(napi_env env, napi_value src) const; 48 49 /** 50 * Check whether the entered value is a built-in arraybufferview auxiliary type. 51 * 52 * @param env NAPI environment parameters. 53 * @param src Object to be tested. 54 */ 55 napi_value IsArrayBufferView(napi_env env, napi_value src) const; 56 57 /** 58 * Check whether the entered value is an arguments object type. 59 * 60 * @param env NAPI environment parameters. 61 * @param src Object to be tested. 62 */ 63 napi_value IsArgumentsObject(napi_env env, napi_value src) const; 64 65 /** 66 * Check whether the entered value is of arraybuffer type. 67 * 68 * @param env NAPI environment parameters. 69 * @param src Object to be tested. 70 */ 71 napi_value IsArrayBuffer(napi_env env, napi_value src) const; 72 73 /** 74 * Check whether the input value is an asynchronous function type. 75 * 76 * @param env NAPI environment parameters. 77 * @param src Object to be tested. 78 */ 79 napi_value IsAsyncFunction(napi_env env, napi_value src) const; 80 81 /** 82 * Check whether the entered value is a bigint64array type. 83 * 84 * @param env NAPI environment parameters. 85 * @param src Object to be tested. 86 */ 87 napi_value IsBigInt64Array(napi_env env, napi_value src) const; 88 89 /** 90 * Check whether the entered value is a biguint64array type. 91 * 92 * @param env NAPI environment parameters. 93 * @param src Object to be tested. 94 */ 95 napi_value IsBigUint64Array(napi_env env, napi_value src) const; 96 97 /** 98 * Check whether the entered value is a Boolean object type. 99 * 100 * @param env NAPI environment parameters. 101 * @param src Object to be tested. 102 */ 103 napi_value IsBooleanObject(napi_env env, napi_value src) const; 104 105 /** 106 * Check whether the entered value is Boolean or number or string or symbol object type. 107 * 108 * @param env NAPI environment parameters. 109 * @param src Object to be tested. 110 */ 111 napi_value IsBoxedPrimitive(napi_env env, napi_value src) const; 112 113 /** 114 * Check whether the entered value is of DataView type. 115 * 116 * @param env NAPI environment parameters. 117 * @param src Object to be tested. 118 */ 119 napi_value IsDataView(napi_env env, napi_value src) const; 120 121 /** 122 * Check whether the entered value is of type date. 123 * 124 * @param env NAPI environment parameters. 125 * @param src Object to be tested. 126 */ 127 napi_value IsDate(napi_env env, napi_value src) const; 128 129 /** 130 * Check whether the entered value is of type native external. 131 * 132 * @param env NAPI environment parameters. 133 * @param src Object to be tested. 134 */ 135 napi_value IsExternal(napi_env env, napi_value src) const; 136 137 /** 138 * Check whether the entered value is the type of float32array array. 139 * 140 * @param env NAPI environment parameters. 141 * @param src Object to be tested. 142 */ 143 napi_value IsFloat32Array(napi_env env, napi_value src) const; 144 145 /** 146 * Check whether the entered value is the type of float64array array. 147 * 148 * @param env NAPI environment parameters. 149 * @param src Object to be tested. 150 */ 151 napi_value IsFloat64Array(napi_env env, napi_value src) const; 152 153 /** 154 * Check whether the value entered is the type of generator function. 155 * 156 * @param env NAPI environment parameters. 157 * @param src Object to be tested. 158 */ 159 napi_value IsGeneratorFunction(napi_env env, napi_value src) const; 160 161 /** 162 * Check whether the value entered is the type of generator object. 163 * 164 * @param env NAPI environment parameters. 165 * @param src Object to be tested. 166 */ 167 napi_value IsGeneratorObject(napi_env env, napi_value src) const; 168 169 /** 170 * Check whether the value entered is the type of int8 array. 171 * 172 * @param env NAPI environment parameters. 173 * @param src Object to be tested. 174 */ 175 napi_value IsInt8Array(napi_env env, napi_value src) const; 176 177 /** 178 * Check whether the value entered is the type of int16 array. 179 * 180 * @param env NAPI environment parameters. 181 * @param src Object to be tested. 182 */ 183 napi_value IsInt16Array(napi_env env, napi_value src) const; 184 185 /** 186 * Check whether the value entered is the type of int32 array. 187 * 188 * @param env NAPI environment parameters. 189 * @param src Object to be tested. 190 */ 191 napi_value IsInt32Array(napi_env env, napi_value src) const; 192 193 /** 194 * Check whether the value entered is the type of map. 195 * 196 * @param env NAPI environment parameters. 197 * @param src Object to be tested. 198 */ 199 napi_value IsMap(napi_env env, napi_value src) const; 200 201 /** 202 * Check whether the entered value is the iterator type of map. 203 * 204 * @param env NAPI environment parameters. 205 * @param src Object to be tested. 206 */ 207 napi_value IsMapIterator(napi_env env, napi_value src) const; 208 209 /** 210 * Check whether the entered value is the module name space type of object. 211 * 212 * @param env NAPI environment parameters. 213 * @param src Object to be tested. 214 */ 215 napi_value IsModuleNamespaceObject(napi_env env, napi_value src) const; 216 217 /** 218 * Check whether the entered value is of type error. 219 * 220 * @param env NAPI environment parameters. 221 * @param src Object to be tested. 222 */ 223 napi_value IsNativeError(napi_env env, napi_value src) const; 224 225 /** 226 * Check whether the entered value is the number type of object. 227 * 228 * @param env NAPI environment parameters. 229 * @param src Object to be tested. 230 */ 231 napi_value IsNumberObject(napi_env env, napi_value src) const; 232 233 /** 234 * Check whether the entered value is the type of promise. 235 * 236 * @param env NAPI environment parameters. 237 * @param src Object to be tested. 238 */ 239 napi_value IsPromise(napi_env env, napi_value src) const; 240 241 /** 242 * Check whether the entered value is the type of proxy. 243 * 244 * @param env NAPI environment parameters. 245 * @param src Object to be tested. 246 */ 247 napi_value IsProxy(napi_env env, napi_value src) const; 248 249 /** 250 * Check whether the entered value is the type of regexp. 251 * 252 * @param env NAPI environment parameters. 253 * @param src Object to be tested. 254 */ 255 napi_value IsRegExp(napi_env env, napi_value src) const; 256 257 /** 258 * Check whether the entered value is the type of set. 259 * 260 * @param env NAPI environment parameters. 261 * @param src Object to be tested. 262 */ 263 napi_value IsSet(napi_env env, napi_value src) const; 264 265 /** 266 * Check whether the entered value is the iterator type of set. 267 * 268 * @param env NAPI environment parameters. 269 * @param src Object to be tested. 270 */ 271 napi_value IsSetIterator(napi_env env, napi_value src) const; 272 273 /** 274 * Check whether the entered value is the type of sharedarraybuffer. 275 * 276 * @param env NAPI environment parameters. 277 * @param src Object to be tested. 278 */ 279 napi_value IsSharedArrayBuffer(napi_env env, napi_value src) const; 280 281 /** 282 * Check whether the entered value is the string type of object. 283 * 284 * @param env NAPI environment parameters. 285 * @param src Object to be tested. 286 */ 287 napi_value IsStringObject(napi_env env, napi_value src) const; 288 289 /** 290 * Check whether the entered value is the symbol type of object. 291 * 292 * @param env NAPI environment parameters. 293 * @param src Object to be tested. 294 */ 295 napi_value IsSymbolObject(napi_env env, napi_value src) const; 296 297 /** 298 * Check whether the entered value is the type of typedarray. 299 * 300 * @param env NAPI environment parameters. 301 * @param src Object to be tested. 302 */ 303 napi_value IsTypedArray(napi_env env, napi_value src) const; 304 305 /** 306 * Check whether the entered value is the type of uint8array. 307 * 308 * @param env NAPI environment parameters. 309 * @param src Object to be tested. 310 */ 311 napi_value IsUint8Array(napi_env env, napi_value src) const; 312 313 /** 314 * Check whether the entered value is the type of uint8clampedarray. 315 * 316 * @param env NAPI environment parameters. 317 * @param src Object to be tested. 318 */ 319 napi_value IsUint8ClampedArray(napi_env env, napi_value src) const; 320 321 /** 322 * Check whether the entered value is the type of uint16array. 323 * 324 * @param env NAPI environment parameters. 325 * @param src Object to be tested. 326 */ 327 napi_value IsUint16Array(napi_env env, napi_value src) const; 328 329 /** 330 * Check whether the entered value is the type of uint32array. 331 * 332 * @param env NAPI environment parameters. 333 * @param src Object to be tested. 334 */ 335 napi_value IsUint32Array(napi_env env, napi_value src) const; 336 337 /** 338 * Check whether the entered value is the type of weakmap. 339 * 340 * @param env NAPI environment parameters. 341 * @param src Object to be tested. 342 */ 343 napi_value IsWeakMap(napi_env env, napi_value src) const; 344 345 /** 346 * Check whether the entered value is the type of weakset. 347 * 348 * @param env NAPI environment parameters. 349 * @param src Object to be tested. 350 */ 351 napi_value IsWeakSet(napi_env env, napi_value src) const; 352 }; 353 } 354 #endif // UTIL_JS_TYPES_H_ 355