1 /* 2 * Copyright (c) 2020 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 #ifndef OHOS_ACELITE_JSI_TYPES_H 17 #define OHOS_ACELITE_JSI_TYPES_H 18 19 #include <cstdint> 20 21 namespace OHOS { 22 namespace ACELite { 23 // opaque pointer for JSI abstract value 24 using JSIValue = struct JSIVal *; 25 26 // type used for initialization functions of built-in modules 27 using InitFunc = void(*)(JSIValue exports); 28 29 /** 30 * type used for native callback of built-in modules 31 * Note: this type is deprecated, use JsiCallback alternatively 32 */ 33 using NativeCallback = void(*)(); 34 35 // type used for native callback of built-in modules 36 using JsiCallback = void(*)(int8_t statusCode); 37 38 // struct information for built-in modules 39 struct Module { 40 const char* name; 41 InitFunc initFunc; 42 }; 43 44 // struct information for private modules 45 struct PrivateModule { 46 const char* bundleName; 47 Module module; 48 PrivateModule(const PrivateModule &) = delete; 49 PrivateModule &operator=(const PrivateModule &) = delete; 50 PrivateModule(PrivateModule &&) = delete; 51 PrivateModule &operator=(PrivateModule &&) = delete; 52 }; 53 54 // constants for JSI API development 55 constexpr char CB_CALLBACK[] = "callback"; 56 constexpr char CB_SUCCESS[] = "success"; 57 constexpr char CB_FAIL[] = "fail"; 58 constexpr char CB_COMPLETE[] = "complete"; 59 constexpr uint8_t ARGC_ONE = 1; 60 constexpr uint8_t ARGC_TWO = 2; 61 constexpr uint8_t ARGC_THREE = 3; 62 63 // Error code used for callback processing 64 constexpr int8_t JSI_ERR_OK = 0; 65 constexpr int8_t JSI_ERR_FAIL = -1; 66 67 /** 68 * @enum TypedArrayType 69 * 70 * @brief Values that represent different types of TypedArray object 71 */ 72 enum class TypedArrayType { 73 JSI_INVALID_ARRAY, 74 JSI_INT8_ARRAY, 75 JSI_UINT8_ARRAY, 76 JSI_UINT8CLAMPED_ARRAY, 77 JSI_INT16_ARRAY, 78 JSI_UINT16_ARRAY, 79 JSI_INT32_ARRAY, 80 JSI_UINT32_ARRAY, 81 JSI_FLOAT32_ARRAY, 82 JSI_FLOAT64_ARRAY, 83 JSI_TYPE_MAX_ARRAY 84 }; 85 86 /** 87 * @enum JsiErrorType 88 * 89 * @brief Values that represent different types of error object 90 */ 91 enum class JsiErrorType { 92 JSI_ERROR_INVALID, 93 JSI_ERROR_COMMON, 94 JSI_ERROR_EVAL, 95 JSI_ERROR_RANGE, 96 JSI_ERROR_REFERENCE, 97 JSI_ERROR_SYNTAX, 98 JSI_ERROR_TYPE, 99 JSI_ERROR_URI, 100 JSI_ERROR_MAX 101 }; 102 } // namespace ACELite 103 } // namespace OHOS 104 #endif // OHOS_ACELITE_JSI_TYPES_H 105