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