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 // uniform error code for error throwing 68 constexpr uint32_t JSI_ERR_CODE_PERMISSION_DENIED = 201; 69 constexpr uint32_t JSI_ERR_CODE_PARAM_CHECK_FAILED = 401; 70 constexpr uint32_t JSI_ERR_CODE_NOT_SUPPORTED = 801; 71 72 /** 73 * @enum TypedArrayType 74 * 75 * @brief Values that represent different types of TypedArray object 76 */ 77 enum class TypedArrayType { 78 JSI_INVALID_ARRAY, 79 JSI_INT8_ARRAY, 80 JSI_UINT8_ARRAY, 81 JSI_UINT8CLAMPED_ARRAY, 82 JSI_INT16_ARRAY, 83 JSI_UINT16_ARRAY, 84 JSI_INT32_ARRAY, 85 JSI_UINT32_ARRAY, 86 JSI_FLOAT32_ARRAY, 87 JSI_FLOAT64_ARRAY, 88 JSI_TYPE_MAX_ARRAY 89 }; 90 91 /** 92 * @enum JsiErrorType 93 * 94 * @brief Values that represent different types of error object 95 */ 96 enum class JsiErrorType { 97 JSI_ERROR_INVALID, 98 JSI_ERROR_COMMON, 99 JSI_ERROR_EVAL, 100 JSI_ERROR_RANGE, 101 JSI_ERROR_REFERENCE, 102 JSI_ERROR_SYNTAX, 103 JSI_ERROR_TYPE, 104 JSI_ERROR_URI, 105 JSI_ERROR_MAX 106 }; 107 } // namespace ACELite 108 } // namespace OHOS 109 #endif // OHOS_ACELITE_JSI_TYPES_H 110